469,635 Members | 2,395 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,635 developers. It's quick & easy.

Drawing strings

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.
Jul 21 '05 #1
3 1316
Hi,

Use one of the drawstring methods with a string format.

http://msdn.microsoft.com/library/de...ringtopic4.asp

Ken
---------------
"Steve" <stevea@centurion-ms_RemoveThis_.co.uk> wrote in message news:e2**************@tk2msftngp13.phx.gbl...
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.
Jul 21 '05 #2
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.
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message news:e2**************@tk2msftngp13.phx.gbl...
Hi,

Use one of the drawstring methods with a string format.

http://msdn.microsoft.com/library/de...ringtopic4.asp

Ken
---------------
"Steve" <stevea@centurion-ms_RemoveThis_.co.uk> wrote in message news:e2**************@tk2msftngp13.phx.gbl...
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.
Jul 21 '05 #3
Hi,

tabMain.Controls.Add(myControl)

Ken
----------------
"Steve" <stevea@centurion-ms_RemoveThis_.co.uk> wrote in message news:e2**************@TK2MSFTNGP10.phx.gbl...
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.
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message news:e2**************@tk2msftngp13.phx.gbl...
Hi,

Use one of the drawstring methods with a string format.

http://msdn.microsoft.com/library/de...ringtopic4.asp

Ken
---------------
"Steve" <stevea@centurion-ms_RemoveThis_.co.uk> wrote in message news:e2**************@tk2msftngp13.phx.gbl...
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.
Jul 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Marcelo | last post: by
10 posts views Thread by tshad | last post: by
5 posts views Thread by brix_zx2 | last post: by
3 posts views Thread by Steve | last post: by
1 post views Thread by asdf | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.