Drawing strings

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

Hi all

I am using the following code to draw strings onto a Form:

----------------------------
Dim tabGraphics As System.Drawing.Graphics = Me.CreateGraphics()
Dim labelFont As New Font("Verdana", 12, FontStyle.Regular, GraphicsUnit.Pixel)
Dim solidBrush As New SolidBrush(Color.DarkSlateBlue)
---------------------------

My question is, Is there a way that I can align the string that I am drawing to the right? When I draw the string it obviously writes it onto the form, but the strings are variable lengths and I want to align them to the right as if they were in a Label control with the TextAlign set to MiddleRight.

Also, is there a way that I can get a control on the form by using it's name? I know that I have a control named "tabMain" which is a tab control, can I get the object so I can add to the controls collection? I would like something like:

Dim c as Control = "tabMain"
c.Controls.Add(myControl)

Thanks for any help,

Kind regards,
Steve.
 
Hi,

Use one of the drawstring methods with a string format.

http://msdn.microsoft.com/library/d...ystemdrawinggraphicsclassdrawstringtopic4.asp

Ken
---------------
Hi all

I am using the following code to draw strings onto a Form:

----------------------------
Dim tabGraphics As System.Drawing.Graphics = Me.CreateGraphics()
Dim labelFont As New Font("Verdana", 12, FontStyle.Regular, GraphicsUnit.Pixel)
Dim solidBrush As New SolidBrush(Color.DarkSlateBlue)
---------------------------

My question is, Is there a way that I can align the string that I am drawing to the right? When I draw the string it obviously writes it onto the form, but the strings are variable lengths and I want to align them to the right as if they were in a Label control with the TextAlign set to MiddleRight.

Also, is there a way that I can get a control on the form by using it's name? I know that I have a control named "tabMain" which is a tab control, can I get the object so I can add to the controls collection? I would like something like:

Dim c as Control = "tabMain"
c.Controls.Add(myControl)

Thanks for any help,

Kind regards,
Steve.
 
Hi Ken

Thanks very much for that!! Very useful :o)

Do you know how I can accomplish the 2nd task at all please?? I need to add controls to a control. I have the name of the control, but I'd prefer not to have to loop through all of the controls on the form and in each sub-control if possible.

Thanks.

Regards,
Steve.
Hi,

Use one of the drawstring methods with a string format.

http://msdn.microsoft.com/library/d...ystemdrawinggraphicsclassdrawstringtopic4.asp

Ken
---------------
Hi all

I am using the following code to draw strings onto a Form:

----------------------------
Dim tabGraphics As System.Drawing.Graphics = Me.CreateGraphics()
Dim labelFont As New Font("Verdana", 12, FontStyle.Regular, GraphicsUnit.Pixel)
Dim solidBrush As New SolidBrush(Color.DarkSlateBlue)
---------------------------

My question is, Is there a way that I can align the string that I am drawing to the right? When I draw the string it obviously writes it onto the form, but the strings are variable lengths and I want to align them to the right as if they were in a Label control with the TextAlign set to MiddleRight.

Also, is there a way that I can get a control on the form by using it's name? I know that I have a control named "tabMain" which is a tab control, can I get the object so I can add to the controls collection? I would like something like:

Dim c as Control = "tabMain"
c.Controls.Add(myControl)

Thanks for any help,

Kind regards,
Steve.
 
Hi,

tabMain.Controls.Add(myControl)

Ken
----------------
Hi Ken

Thanks very much for that!! Very useful :o)

Do you know how I can accomplish the 2nd task at all please?? I need to add controls to a control. I have the name of the control, but I'd prefer not to have to loop through all of the controls on the form and in each sub-control if possible.

Thanks.

Regards,
Steve.
Hi,

Use one of the drawstring methods with a string format.

http://msdn.microsoft.com/library/d...ystemdrawinggraphicsclassdrawstringtopic4.asp

Ken
---------------
Hi all

I am using the following code to draw strings onto a Form:

----------------------------
Dim tabGraphics As System.Drawing.Graphics = Me.CreateGraphics()
Dim labelFont As New Font("Verdana", 12, FontStyle.Regular, GraphicsUnit.Pixel)
Dim solidBrush As New SolidBrush(Color.DarkSlateBlue)
---------------------------

My question is, Is there a way that I can align the string that I am drawing to the right? When I draw the string it obviously writes it onto the form, but the strings are variable lengths and I want to align them to the right as if they were in a Label control with the TextAlign set to MiddleRight.

Also, is there a way that I can get a control on the form by using it's name? I know that I have a control named "tabMain" which is a tab control, can I get the object so I can add to the controls collection? I would like something like:

Dim c as Control = "tabMain"
c.Controls.Add(myControl)

Thanks for any help,

Kind regards,
Steve.
 
Back
Top