|
-
Apr 12th, 2004, 06:23 AM
#1
Thread Starter
G&G Moderator
Text Width
Howdy all,
I was wondering if there is a way to determine the width of text in a RichTextBox (in pixels or otherwise). The RichTextBox will have different sized fonts aswell.
RichTextBox1
Do I use GetTextMetrics? If so how? If not, what should I use?
Thanks in advance
Phreak
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Apr 12th, 2004, 02:21 PM
#2
Well, you could parse the TextRTF property for different fonts and use TextWidth of a hidden picturebox (I'd use that instead of the form because you'd have to change the remaining width so you don't go over the edge of your box), add them together, and get your answer. Hmmmm, there must be a simpler way.... maybe some weird SendMessage on the RTB?
The time you enjoy wasting is not wasted time.
Bertrand Russell
<- Remember to rate posts you find helpful.
-
Apr 12th, 2004, 02:24 PM
#3
Thread Starter
G&G Moderator
I tried doing something like you suggested, like this:
VB Code:
For i = 0 To Len(rtb.SelText)
rtb.SelStart = i
rtb.SelLength = 1
With rtb
Form1.pic.FontName = .SelFontName
Form1.pic.FontSize = .SelFontSize
Form1.pic.FontBold = .SelBold
Form1.pic.FontItalic = .SelItalic
Form1.pic.FontStrikethru = .SelStrikeThru
Form1.pic.FontUnderline = .SelUnderline
Form1.pic.Print .SelText
End With
Next i
widthIWant = Form1.pic.TextWidth(rtb.SelText)
It seems to work, but there is some math involved (since it isn't right every time). A Simpler way would be nice.. 
Phreak
Visual Studio 6, Visual Studio.NET 2005, MASM
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
|