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

I don't believe this code gives the correct RichTextBox string size

I don't believe the code below gives the correct string size in inches.

Can any one tell me what is wrong?

I need to know the size of the string before I add it to the RichTextBox

Thanks

Public ReadOnly Property TxtMeasureString(ByVal str As String) As SizeF

Get

Dim Gr As Graphics = Me.CreateGraphics

Dim MeasureString As SizeF = Gr.MeasureString(str,
ControlRichTextBox1.SelectionFont())

TxtMeasureString = New SizeF(MeasureString.Width / Gr.DpiX,
MeasureString.Height / Gr.DpiY)

Gr.Dispose()

End Get

End Property
Nov 21 '05 #1
2 1039
" **Developer**" <RE*************@a-znet.com> schrieb:
I don't believe the code below gives the correct string size in inches.

Can any one tell me what is wrong?

I need to know the size of the string before I add it to the RichTextBox


I think it's not as easy. The richtextbox control is drawn using GDI, while
'Graphics.MeasureString' measuers the string using GDI+. Consequently
'MeasureString' won't return the exact size of the string. I fear you will
have to dig into the GDI32-API to get exact results.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #2
Thanks, I'll go searching

\
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:uW*************@TK2MSFTNGP15.phx.gbl...
" **Developer**" <RE*************@a-znet.com> schrieb:
I don't believe the code below gives the correct string size in inches.

Can any one tell me what is wrong?

I need to know the size of the string before I add it to the RichTextBox


I think it's not as easy. The richtextbox control is drawn using GDI,
while 'Graphics.MeasureString' measuers the string using GDI+.
Consequently 'MeasureString' won't return the exact size of the string. I
fear you will have to dig into the GDI32-API to get exact results.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #3

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

Similar topics

2
by: PC User | last post by:
I found some VB code to printout a richtext field and I'm trying to adapt it to MS Access 2000. I think there might be some small changes to make the adaption between VB versions. Also my OS is...
1
by: Angus Lepper | last post by:
I'm writing a stock ticker for a stock market simulation, and can load the data into the xmlreader in the first place, but can't figure out how to refresh/update the data in it. Any ideas? Code:...
6
by: cj | last post by:
Lets just take this example I'm looking at now. I'm looking at the help screen titled .NET Framework Class Library FolderBrowserDialog Class . It gives an example at the bottom that begins with:...
1
by: Rasko | last post by:
when i try to insert kind of text to my richtextbox from web (copy/paste) i can do it but after i wanted to update i can't do it . there is an errormessage appears (Input string was not in a correct...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.