![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
In 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#. |
#3
| |||
| |||
|
|
The text rendering hint of the Graphics device you use to measure with and the font settings themselves may have a bearing on the measurement. Some fonts incorrectly report their sizes and errors can reult when measuring. -- -- Bob Powell [MVP] Visual C#, System.Drawing Ramuseco Limited .NET consulting http://www.ramuseco.com Find great Windows Forms articles in Windows Forms Tips and Tricks http://www.bobpowell.net/tipstricks.htm Answer those GDI+ questions with the GDI+ FAQ http://www.bobpowell.net/faqmain.htm All new articles provide code in C# and VB.NET. Subscribe to the RSS feeds provided and never miss a new article. "Norman Diamond" <ndiamond (AT) community (DOT) nospam> wrote in message news:%23KwI8mFQIHA.1164 (AT) TK2MSFTNGP02 (DOT) phx.gbl... In 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#. |
#4
| |||
| |||
|
|
In 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#. |
#5
| |||
| |||
|
|
StringFormat.GenericTypographic to get the closest meaurements Whereas MSDN says for the simplest version of MeasureString: |
|
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. |
|
Norman, 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 (AT) community (DOT) nospam> wrote in message news:%23KwI8mFQIHA.1164 (AT) TK2MSFTNGP02 (DOT) phx.gbl... In 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#. |
#6
| |||
| |||
|
|
Norman, 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 (AT) community (DOT) nospam> wrote in message news:%23KwI8mFQIHA.1164 (AT) TK2MSFTNGP02 (DOT) phx.gbl... In 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#. |
#7
| |||
| |||
|
|
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 (AT) nospam (DOT) src-us.com> wrote in message news:A3CC59CC-B04F-4D43-8299-F668AB568052 (AT) microsoft (DOT) com... Norman, 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 (AT) community (DOT) nospam> wrote in message news:%23KwI8mFQIHA.1164 (AT) TK2MSFTNGP02 (DOT) phx.gbl... In 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#. |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |