473,320 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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 1430
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 different font setting? Sometimes the string has two or...
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 draw it vertically, but I need to turn the...
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 utility class the helps it to mesure strings. To...
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 applicantID.backcolor = "#F6F6F6"
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 I'd appreciate it. Dim g As Graphics Dim...
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 = Me.CreateGraphics() Dim labelFont As New...
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 when it updated it just drew over the same area w/o...
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 I measure it and if it is longer than the column...
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 me with this peice of work, I just need pointing...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.