472,342 Members | 1,320 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,342 software developers and data experts.

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 1375
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Steven.Xu | last post by:
Hi, I want to draw some strings on a picturebox. The strings has some different font setting. How can i get the string width and height with...
2
by: Marcelo | last post by:
Greetings! I develop a Multiple Windows Forms application in Microsoft Visual Studio C++ .NET 2003 and I have a problem with string drawing. I can...
1
by: Hadar | last post by:
Hi, I'm getting "object is currently in use elsewhere" when I use System.Drawing.Graphics.MesureString. This is what I do: My controls use a...
10
by: tshad | last post by:
I have a problem setting the background color of textbox on the fly. I tried using: applicantID.backcolor = "F6F6F6" and ...
5
by: brix_zx2 | last post by:
vb.net 2k3: I have this code that doesn't work unless I take out the g.DrawString statements. If anyone can look over the code and tell me why...
3
by: Steve | last post by:
Hi all I am using the following code to draw strings onto a Form: ---------------------------- Dim tabGraphics As System.Drawing.Graphics =...
1
by: asdf | last post by:
I just started my first project where i draw lines and strings on the screen. I sucessfully drew what i needed on the screen, then realized that...
5
by: Academia | last post by:
As a simple example suppose I want to draw two columns of strings. I know where each column starts and the widths. So before I print a string...
1
by: sheephead86 | last post by:
Hi, I'm pretty new to java, and I have a small problem involving drawing a rectangle on a java applet.Firstly this is not a plea for someone to help...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.