somu
somu

Reputation: 447

Word wrap in Windows Forms (vb.net)

How can I use DrawString to create a word wrap effect in Visual Basic .NET 2005?

Upvotes: 3

Views: 2632

Answers (2)

Indolent Coder
Indolent Coder

Reputation: 728

If you provide a rectangle to an overload of the Graphics.DrawString method, it will wrap the text within the rectangle.

Overloads Public Sub DrawString(String, Font, Brush, RectangleF)

Upvotes: 3

Sören Kuklau
Sören Kuklau

Reputation: 19970

http://www.informit.com/guides/content.aspx?g=dotnet&seqNum=286

You can draw text in a rectangle by passing a RectangleF object to the DrawString method. GDI+ will wrap the text to make it fit in the specified rectangle. For example:

Dim s As String = "This string will be wrapped in the output rectangle"
Dim rectf As New RectangleF(10, 100, 200, 200)
grf.DrawString(s, myFont, Brushes.Red, rectf)

Upvotes: 5

Related Questions