473,396 Members | 2,021 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,396 software developers and data experts.

DrawString

Using Graphics.DrawString, is it possible to specify that the text is draw
centerd horizontally and/or vertically in the specified layout rectangle?
Thanks.

Jerry
Nov 21 '05 #1
2 1095
Nevermind... Figured it out.

Dim s As New StringFormat

s.Alignment = StringAlignment.Center

s.LineAlignment = StringAlignment.Center

"Rlrcstr" <rl*****@msn.com> wrote in message
news:uX**************@TK2MSFTNGP12.phx.gbl...
Using Graphics.DrawString, is it possible to specify that the text is draw
centerd horizontally and/or vertically in the specified layout rectangle?
Thanks.

Jerry

Nov 21 '05 #2
Hi,

Use the drawstring that accepts a string format.

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint

Dim sf As New StringFormat

Dim strOut As String = "Hello World"

With sf

..LineAlignment = StringAlignment.Center ' center vertically

..Alignment = StringAlignment.Center 'center horizontally

End With

e.Graphics.DrawString(strOut, Me.Font, Brushes.Black, _

RectangleF.op_Implicit(Me.ClientRectangle), sf)

End Sub

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

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

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

Ken
--------------------
"Rlrcstr" <rl*****@msn.com> wrote in message
news:uX**************@TK2MSFTNGP12.phx.gbl...
Using Graphics.DrawString, is it possible to specify that the text is draw
centerd horizontally and/or vertically in the specified layout rectangle?
Thanks.

Jerry

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: timtos | last post by:
I am working on a custom treeView and have some problems with a) node.Bounds.Width b) concatenate strings drawn with DrawString(...) a) I want to highlight a selected node and used the...
1
by: David Lindgren | last post by:
Hello! I am using the DrawString method with different StringAlignments passed to it and the result varies alot! Take a look at this screenshot:...
1
by: Drew | last post by:
I posted this to framework.drawing, but did not get any responses... Maybe here?? I am drawing some text using DrawString() and using a bounding rectangle so that when the string is too long it...
4
by: Geert Gerrits | last post by:
Hi, I'm trying to print a string under an angle. Is there a way to do this ? Thanks.
1
by: Joao | last post by:
Hi, I'm trully excited to use VB.NET's PrintDocument to make my printouts. On them I draw strings, images and lines. All perfect, if I invoke the Print or the PrintPreview one time per run. At...
5
by: johnb41 | last post by:
I need to print out a string of text and obviously i'm using the DrawString command. But the string must be placed AFTER some "programmatically generated text" (also printed using DrawString). ...
2
by: ChrisNightingale | last post by:
Hi everybody, I have an odd issue which I'm not sure how to resolve. I'm basically implementing a print mechanism which takes a series of controls and reproduces them on a print document. So...
2
by: Tony Johansson | last post by:
Hello! If I use the DrawString below with object of StringFormat as the last object it works good. If I instead remove object StringFormat below as the last object of DrawString I get some rows...
9
by: kynos | last post by:
I would like to paint a box using DrawString, standard Unicode characters (box drawings characters) and monospaced font. Unfortunately for some fonts painted lines contain a break. Example...
6
by: Dilip | last post by:
Howdy Folks I have a display where the Graphics.DrawString function is called to display something. Since the text seems to be larger than its bounding rectangle, the call basically splits the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
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,...
0
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...
0
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...
0
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,...

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.