简体   繁体   English

如何确定正在使用哪些单位?

[英]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.例如,我想将一个字符串放在 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...我假设这将采用 object (790) 的宽度并从中减去字符串的长度,然后字符串会很好并紧贴 object 的右侧......但是当我这样做时,字符串在object中间开始较多,而且字符串和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. System.Windows.Forms.TextRenderer.MeasureText 返回大小(以像素为单位)。

http://msdn.microsoft.com/en-us/library/system.windows.forms.textrenderer.measuretext.aspx 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.在 WinForms 中,默认单位是像素(例如以点为单位的字体大小除外),包括 MeasureText 的结果。

What is context.DrawText?什么是 context.DrawText? Why not call Graphics.DrawString ?为什么不调用Graphics.DrawString

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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