Graphics.MeasureString accuracy
-
Hello. I'm using
Graphics gr = Graphics.FromHwnd(IntPtr.Zero);
(int)gr.MeasureString(xrt.Rows[x].Cells[y].Text, xrt.Rows[x].Cells[y].Font).Width;But as you can see http://img156.yfrog.com/img156/3585/measurestring.jpg it doesn't work as i would like. Can you please advice me so i can increase its accuracy? Thank you in advance!
-
Hello. I'm using
Graphics gr = Graphics.FromHwnd(IntPtr.Zero);
(int)gr.MeasureString(xrt.Rows[x].Cells[y].Text, xrt.Rows[x].Cells[y].Font).Width;But as you can see http://img156.yfrog.com/img156/3585/measurestring.jpg it doesn't work as i would like. Can you please advice me so i can increase its accuracy? Thank you in advance!
What's wrong with it ? Also, you can't make it more accurate than it is. I am sure it is accurate, it always has been for me.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
Hello. I'm using
Graphics gr = Graphics.FromHwnd(IntPtr.Zero);
(int)gr.MeasureString(xrt.Rows[x].Cells[y].Text, xrt.Rows[x].Cells[y].Font).Width;But as you can see http://img156.yfrog.com/img156/3585/measurestring.jpg it doesn't work as i would like. Can you please advice me so i can increase its accuracy? Thank you in advance!
Hi, I've read before there are some slight inaccuracies, so I tend to add some 10 pixels to make strings fit. This article will tell you more: Bypass Graphics.MeasureString limitations[^] :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
-
What's wrong with it ? Also, you can't make it more accurate than it is. I am sure it is accurate, it always has been for me.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
Hello and thanks for replying. Well "personal information" is not in the same line.Moreover "Orders table" "for each order" etc. I would like them to be in the same line and not wordwraped.
Every time it wraps, it's because there's not enough room to fit them. If the column has been sized to the biggest string ( you don't actually tell us what you do with it ), then perhaps you just need to add a few pixels ?
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
Every time it wraps, it's because there's not enough room to fit them. If the column has been sized to the biggest string ( you don't actually tell us what you do with it ), then perhaps you just need to add a few pixels ?
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
Thanks for the replies.Well i just want to fit the text exactly inside the cells(table cells).I create a table(control provided) and set text inside its cells.Then i process all the cells and try to set the correct width(using measurestring). How will i know that more pixels are needed to be added? I will try the links provided but i don't know if they fit in my occasion. Thanks again people.