473,804 Members | 2,190 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Drawing strings

Hi all

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

----------------------------
Dim tabGraphics As System.Drawing. Graphics = Me.CreateGraphi cs()
Dim labelFont As New Font("Verdana", 12, FontStyle.Regul ar, GraphicsUnit.Pi xel)
Dim solidBrush As New SolidBrush(Colo r.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 1463
Hi,

Use one of the drawstring methods with a string format.

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

Ken
---------------
"Steve" <stevea@centuri on-ms_RemoveThis_. co.uk> wrote in message news:e2******** ******@tk2msftn gp13.phx.gbl...
Hi all

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

----------------------------
Dim tabGraphics As System.Drawing. Graphics = Me.CreateGraphi cs()
Dim labelFont As New Font("Verdana", 12, FontStyle.Regul ar, GraphicsUnit.Pi xel)
Dim solidBrush As New SolidBrush(Colo r.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***@bellsout h.net> wrote in message news:e2******** ******@tk2msftn gp13.phx.gbl...
Hi,

Use one of the drawstring methods with a string format.

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

Ken
---------------
"Steve" <stevea@centuri on-ms_RemoveThis_. co.uk> wrote in message news:e2******** ******@tk2msftn gp13.phx.gbl...
Hi all

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

----------------------------
Dim tabGraphics As System.Drawing. Graphics = Me.CreateGraphi cs()
Dim labelFont As New Font("Verdana", 12, FontStyle.Regul ar, GraphicsUnit.Pi xel)
Dim solidBrush As New SolidBrush(Colo r.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.Control s.Add(myControl )

Ken
----------------
"Steve" <stevea@centuri on-ms_RemoveThis_. co.uk> wrote in message news:e2******** ******@TK2MSFTN GP10.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***@bellsout h.net> wrote in message news:e2******** ******@tk2msftn gp13.phx.gbl...
Hi,

Use one of the drawstring methods with a string format.

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

Ken
---------------
"Steve" <stevea@centuri on-ms_RemoveThis_. co.uk> wrote in message news:e2******** ******@tk2msftn gp13.phx.gbl...
Hi all

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

----------------------------
Dim tabGraphics As System.Drawing. Graphics = Me.CreateGraphi cs()
Dim labelFont As New Font("Verdana", 12, FontStyle.Regul ar, GraphicsUnit.Pi xel)
Dim solidBrush As New SolidBrush(Colo r.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
1769
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 three row. Can i get a rectangle scope of it? Thanks! Steven.Xu
2
1283
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 strings 180°. I use the Invalidate() function and call the Paint event: private: System::Void groupBox2_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e){ e->Graphics->DrawString(Voltage,new
1
3241
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 get the best performance for the utility class, its members, as well as the System.Drawing.Graphics object, are static:
10
12231
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
1230
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 LabelText As String LabelText = "--" x = x + 20
3
276
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 Font("Verdana", 12, FontStyle.Regular, GraphicsUnit.Pixel) Dim solidBrush As New SolidBrush(Color.DarkSlateBlue) ---------------------------
1
1344
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 clearing the first instance of text and lines. How can i clear it? Below is my code, basically it is a thermometer and my program is drawing a red line the height of the temp and drawing the temp on the red bubble. Dim g As Graphics
5
1271
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 width I remove a character at the end and measure it again. I repeat this until the string is not longer than the desired width. I'm drawing the strings on panel and wonder if there is a faster way.
1
2388
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 in the right direction. Ok the problem. I am creating a program that ask the user to input a height value, the program will then do a calculation and create a golden ratio width. The type of both the height and the width are double. This is...
0
9714
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9594
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10600
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10350
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10351
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10096
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9174
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
2
3834
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.