开发者

How to determine which units are being used?

so I was just wondering how you go about knowing which units are used by what? does everything default to pixels, or inches or what?

For example, I have a string that I would like to put on the right side of an object. so what I thought was doing something like this:

string str = "this is a string";
System.Drawing.Font f = new System.Drawing.Font("Verdana",14);
System.Drawing.Size size = System.Windows.Forms.TextRenderer.MeasureText(str, f);
context.DrawText(str, new Point(790-size.Width, 1070));

I assume that this will 开发者_如何学运维take the width of the object (790) and subtract from that the length of the string, and then the string would be nice and snug up against the right side of the object....but when I do this, the string starts more so in the middle of the object, and there is a lot of white space between the string and the right size of the object...

For example, this is what I want:

                                                                           String

this is what I get:

                                                 string

notice in the first one, the word 'String' is right up against the right side, and in the second...it isnt

So how do I know which units are being used?

thanks!


System.Windows.Forms.TextRenderer.MeasureText returns size in pixels.

http://msdn.microsoft.com/en-us/library/system.windows.forms.textrenderer.measuretext.aspx


In WinForms, the default unit is pixels (except for e.g. font size which is in points), including the result of MeasureText.

What is context.DrawText? Why not call Graphics.DrawString?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜