Re: Graphics.MeasureString? or Graphics.DrawString?
- From: "Ron" <rallen@xxxxxxxxxxxxxxxxx>
- Date: Mon, 31 Dec 2007 12:16:11 -0500
Norman,
I don't know why this would happen but I use the StringFormat.GenericTypographic all through my utilities library for printing and it works just fine for centering, left aligning, etc. I only mentioned the Transform because that is why you need a position to measure from. I do note that you are measuring with this.Font and then drawing with legendFont though which may produce differnent results if the two Font objects are different.
Ron Allen
"Norman Diamond" <ndiamond@xxxxxxxxxxxxxxxx> wrote in message news:esQqIY3QIHA.748@xxxxxxxxxxxxxxxxxxxxxxx
Bad news.
With your suggested changes to the MeasureString call, in Vista it now loses the last 2 characters of each legend. The simplest version of Measure String only lost the last 1 character of each legend, in Vista.
Rebooting to XP on the same machine, with your suggested changes to the MeasureString call, it again loses the last 2 characters of each legend. The simplest version of MeasureString didn't lose any characters at all from the legends in XP.
"Ron" <rallen@xxxxxxxxxxxxxxxxx> wrote in message news:A3CC59CC-B04F-4D43-8299-F668AB568052@xxxxxxxxxxxxxxxxNorman,
The measurements of the string depend on the StringFormat being used.
The default one includes a fair amount of space around the whole string when measuring. For what you want to do one of the MeasureString calls including a StringFormat would probably work best and include a clone of StringFormat.GenericTypographic to get the closest meaurements around the object being measured.
i.e. the following after you compute the starting point
legendSize = m_grChartResults.MeasureString(legend, this.Font,
new PointF(0, 0), StringFormat.GenericTypographic);
for a string at the top/left of the page. The starting location is used because if there is some kind of non-linear transform done on the graphics being used the size of the string depends on the location.
Ron Allen
"Norman Diamond" <ndiamond@xxxxxxxxxxxxxxxx> wrote in message news:%23KwI8mFQIHA.1164@xxxxxxxxxxxxxxxxxxxxxxxIn Windows XP, the following code figures out where to position a string and draws the string. In Vista, the following code figures out where to position all except the last character of the string and draws all except the last character of the string.
Notice that this legend is located near the lower left of the chart and there's lots of blank space on the right. (In fact after all that blank space there's another legend at the lower right which suffers from exactly the same defect, but I'm omitting that code because the positioning might lead to a red herring. Anyway there's lots and lots of blank space where there should be the last character and lots and lots of blank space.)
legendSize = m_grChartResults.MeasureString(legend, this.Font);
legendRectangle.X = ChartLeftMargin - (legendSize.Width / 2.0f);
if (legendRectangle.X < 0)
{
legendRectangle.X = 0;
}
legendRectangle.Width = legendSize.Width;
legendRectangle.Y = pbChartResults.Height - legendSize.Height - 2;
legendRectangle.Height = legendSize.Height;
m_grChartResults.DrawString(legend, legendFont, legendBrush,
legendRectangle);
DotNet Framework 2 with SP1, Visual Studio 2005 with SP1 C#.
.
- References:
- Graphics.MeasureString? or Graphics.DrawString?
- From: Norman Diamond
- Re: Graphics.MeasureString? or Graphics.DrawString?
- From: Ron
- Re: Graphics.MeasureString? or Graphics.DrawString?
- From: Norman Diamond
- Graphics.MeasureString? or Graphics.DrawString?
- Prev by Date: Graphics.MeasureString() is messing up my image
- Next by Date: Scale Transform - Why do I need to account for verticalResolution?
- Previous by thread: Re: Graphics.MeasureString? or Graphics.DrawString?
- Next by thread: Re: Convert Color Bitmap To B/W
- Index(es):
Relevant Pages
|