|
-
Mar 20th, 2006, 03:38 PM
#1
Thread Starter
Lively Member
Help with drawing a string
I have a problem hopefully someone can help me out with. I am trying to draw a string in a rectange (not inheriting from any control). The rectangle can only be so big. I need to figure out if the string will not fit in the rectangle, then add a "..." to the end of the string right before it gets cut off.
I know how to the draw the string, and I can figure out how measure it with the font and string formating. But finding that cut-off point is where I am having much difficulty.
Thanks!
-
Mar 20th, 2006, 03:54 PM
#2
Re: Help with drawing a string
There is a Graphics.MeasureString method you can use to measure the length of the string...
-
Mar 20th, 2006, 04:18 PM
#3
Re: Help with drawing a string
Like this?
VB Code:
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim txt As String
Dim the_Font As New Font("Times New Roman", 30, FontStyle.Bold, GraphicsUnit.Pixel)
Dim layout_rect As RectangleF
Dim string_format As New StringFormat
e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit
layout_rect = New RectangleF(100, 0, 180, 70)
txt = "Hello this is the text that is going to be trimmed"
string_format.Trimming = StringTrimming.EllipsisCharacter
e.Graphics.DrawString(txt, the_Font, Brushes.Black, layout_rect, string_format)
e.Graphics.DrawRectangle(Pens.Red, Rectangle.Round(layout_rect))
End Sub
-
Mar 20th, 2006, 04:28 PM
#4
Thread Starter
Lively Member
Re: Help with drawing a string
I can already get the length of the string. What I need to find is the length of the "fitting" string and cut it off at the proper length. For example, a string that measures an area of 200,400. However the actually area displayed is 200, 200. I need to find that point in the string and add a "..." to indicate there is more text.
-
Mar 20th, 2006, 04:30 PM
#5
Thread Starter
Lively Member
Re: Help with drawing a string
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|