Another simple question

  • Thread starter Christian O'Connell
  • Start date
C

Christian O'Connell

Hi, please excuse this, my third posting today. It is my last I
promise.

When I past this into form1, I am expecting to see
"Start0Start01Start012Start0123". But what I see is "Start0 Start01
Start012 Start0123". Where is the extra 'space' coming from?
Thank you again.
Chris


Protected Overrides Sub OnPaint(ByVal vpe As PaintEventArgs)
MyBase.OnPaint(vpe)
Dim g As Graphics = vpe.Graphics
Dim b As SolidBrush = New SolidBrush(Color.Black)
Dim YCoord As Single = 100
Dim XCoord As Single = 100
Dim f As New Font("Times New Roman", 12, _
FontStyle.Regular, GraphicsUnit.Pixel)

Dim s As String = "Start"
For i As Integer = 0 To 3
s += Integer.Parse(i).ToString
g.DrawString(s, f, b, XCoord, YCoord)
XCoord += g.MeasureString(s, f).Width
Next i

End Sub
 
T

test

Christian, the on-line docs do say.

Quote: "The MeasureString method is designed for use with individual strings
and includes a small amount of extra space before and after the string to
allow for overhanging glyphs. Also, the DrawString method adjusts glyph
points to optimize display quality and might display a string narrower than
reported by MeasureString. To obtain metrics suitable for adjacent strings
in layout (for example, when implementing formatted text), use the
MeasureCharacterRanges method."


Perhaps the "extra space" you refer to is merely just the additional extra
space before and after the string to allow for the overhanging glyphs. I've
spent the past 45 mins attempting to get a demo together for you using
MeasureCharacterRanges but without success. My gut feeling is that you
should focus your efforts here and not use "MeasureString". If/when you get
it working please post a code excerpt.

Regards
Hexathioorthooxalate.
 
C

Christian O'Connell

Hex, thank you. I can't get it to work either.

Please please can someone help me out with a basic skeleton few lines
that prints displays strings using a graphics object without spaces. I
can't see how to do it. My code is below. Google doesn't give any
hints/hits using the 'MeasureCharacterRanges' subroutine to get a
working example.
Thank you
Christian
 
B

Brian

If you really want control over your text output then go with GDI and use
TextOut. The GDI+ DrawString will only give you a headache if you try to use
it for precise text printing. I really hate it. I hope Microsoft will change
the way DrawString works with video display and not worry about device
independence, but I doubt it.
 
R

Ron Allen

Christian,
You will get better results by using one of the MeasureString overloads
that takes a StringFormat parameter. Use an instance of
StringFormat.GenericTypographic for this and you should get better results.
The overloads that don't specify a StringFormat object use the default which
includes some space around the string.
I normally use the MeasureString(string, font, maxWidth, myStringFormat)
overload when I want more exact results. Just make sure to make maxWidth
big enough so that you don't run into the maximum.
You may want to use Google to search
microsoft.putlic.dotnet.framework.drawing for more detailed discussions on
GDI+ drawing and measuring strings.

Ron Allen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top