文本框是否使用GDI和GDI + [英] Does TextBox use GDI or GDI+

查看:221
本文介绍了文本框是否使用GDI和GDI +的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我想衡量一个文本框中的文本大小,我发现TextRenderer给了我正确的价值观,而图形会给我错误的价值观。因此,这似乎是文本框,应使用GDI绘制文本,对吧?

Basically, I want to measure the text size in a TextBox, and I found out that TextRenderer gives me the correct values, while Graphics would give me wrong values. So that seems like TextBox should be using GDI to draw text, right?

不过,无论我看,我看到它应该使用GDI +。例如:

However, wherever I read, I see that it's supposed to use GDI+. For example:

  • 在这里<一个href="http://microsoft.public.dotnet.framework.windowsforms.controls.narkive.com/yoHKjPut/text-rendering-accuracy-problem-in-textbox-richtextbox" rel="nofollow">http://microsoft.public.dotnet.framework.windowsforms.controls.narkive.com/yoHKjPut/text-rendering-accuracy-problem-in-textbox-richtextbox它说,文本框和按钮使用GDI +。
  • 在这里<一个href="http://stackoverflow.com/questions/1203087/why-is-graphics-measurestring-returning-a-higher-than-expected-numberit">Why是Graphics.MeasureString()返回一个高于预期的数字?的它说,默认为兼容模式,吸引在GDI +
  • Here http://microsoft.public.dotnet.framework.windowsforms.controls.narkive.com/yoHKjPut/text-rendering-accuracy-problem-in-textbox-richtextbox it says that TextBox and Buttons use GDI+.
  • Here Why is Graphics.MeasureString() returning a higher than expected number? it says that default is "compatibility mode" that draws in GDI+

那么为什么说我越来越有TextRenderer而不是图形时,它应该是各地的其他方法一致的结果?

So why is it that I'm getting consistent results with TextRenderer and not with Graphics when it's supposed to be other way around?

推荐答案

好了,一些研究已经表明,有什么是一片混乱的默认的。

All right, some more research have shown that there is a confusion of what is "Default".

当这些资源谈的默认的,只讲的默认(1)的,如如果没有执行额外的code 的,而不是默认(2)的,如如果不采取额外的行动的。

When these sources talk about "Default", they talk about "Default(1)" as in "If no extra code is executed", not "Default(2)" as in "If no extra action is taken".

由于通过的默认(2)的,Application.SetCompatibleTextRenderingDefault(假)被添加到新的proiject,这使得TextBox类使用GDI用于渲染的Program.cs文件,这是不是的<​​em>默认(1)的的,但实际上这是会发生什么,如果你,作为一个程序员,不采取任何其他行动。

Because by "Default(2)", "Application.SetCompatibleTextRenderingDefault(false)" is added to the Program.cs file of a new proiject, which makes TextBox class use GDI for rendering, which is not the "Default(1)" for it, but in fact this is what happens if you, as a programmer, take no additional action.

这基本上是什么让我。

PS:我是从这个问题上公认的答案基础的assumtion这是真的被默认(1)<一href="http://stackoverflow.com/questions/1296951/usecompatibletextrendering-property-not-created-by-designer-when-it-is-set-to-fa">UseCompatibleTextRendering由设计师当它被设置为false 财产未创建

PS: I'm basing the assumtion that it's true by "Default(1)" on the accepted answer from this question UseCompatibleTextRendering property not created by designer when it is set to false

这篇关于文本框是否使用GDI和GDI +的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆