TextBox 使用 GDI 还是 GDI+ [英] Does TextBox use GDI or GDI+

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

问题描述

基本上,我想测量 TextBox 中的文本大小,我发现 TextRenderer 给了我正确的值,而 Graphics 给了我错误的值.这样看来,TextBox 应该使用 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:

  • 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 而不是使用 Graphics 得到一致的结果,而它应该是其他方式呢?

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".

当这些消息来源谈论Default"时,他们谈论的是Default(1)",如如果没有执行额外的代码",而不是Default(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".

由于Default(2)",Application.SetCompatibleTextRenderingDefault(false)"被添加到新项目的Program.cs文件中,使得TextBox类使用GDI进行渲染,从而不是它的Default(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.

这基本上就是吸引我的原因.

This is basically what got me.

PS:我假设默认(1)"是正确的,这个假设是基于这个问题的接受答案 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

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

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