简体   繁体   中英

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 eg font size which is in points), including the result of MeasureText.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM