Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
Hai all,


I am using this code

int x=int w =Convert.ToInt32(Math.Ceiling(g.MeasureString("My string", s).Width));
//f is the object of Font
//g is the object of Graphics


but the value I am getting in x is not accurate all time, Its value is changing alternately...

How can I solve this problem...

Please help...
Posted

1 solution

There is an article here that may help you: Bypass Graphics.MeasureString limitations[^]
 
Share this answer
 
Comments
version_2.0 22-Jun-11 8:03am    
k...

Is there any, another way to solve this....?
Sergey Alexandrovich Kryukov 22-Jun-11 14:45pm    
Why?!
--SA
Sergey Alexandrovich Kryukov 22-Jun-11 14:45pm    
Looks like a good article. The problem is pretty difficult. My 5.
--SA
OriginalGriff 22-Jun-11 14:54pm    
Hi SA! Yeah, it's a pity MeasureString is so unreliable - but there you go, it is quick...
Sergey Alexandrovich Kryukov 22-Jun-11 18:27pm    
Yes. Do you know the backgrounds of this difficulty? Rendering (small) characters is a very complex and hard-to-understand technique, taking into account sub-pixels, an internal structure of each pixel and other delicate aspects. I recently came across to an article on the topic -- a head-breaking reading, in fact.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900