"Academia" <ac************@a-znet.comschrieb
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.
You can use an overloaded DrawString version specifiying the
"LayoutRectangle" and formatting options:
Dim rect As RectangleF
Dim sf As StringFormat
'--- 50 is the column width ---
rect = New RectangleF(30, 40, 50, 0)
sf = New StringFormat(StringFormatFlags.NoWrap)
'optional:
'sf.Trimming = StringTrimming.None
e.Graphics.DrawRectangle(Pens.Blue, Rectangle.Round(rect))
e.Graphics.DrawString( _
"very long text that does not fit into the column", _
Panel1.Font, Brushes.Black, rect, sf _
)
Armin