简体   繁体   English

TextFormatFlags.TextBoxControl标志的作用是什么

[英]What TextFormatFlags.TextBoxControl flag exactly does

I would like to understand what effect has enablig the flag TextFormatFlags.TextBoxControl when using the TextRenderer.DrawText method is called. 我想了解调用TextRenderer.DrawText方法时,使TextFormatFlags.TextBoxControl标志起作用的效果。

I have written an small program and I can't see difference between using it and don't using it. 我写了一个小程序,我看不出使用它和不使用它之间的区别。

Also, I inpected the code with the .NET reflector and the flag is passed directly to the native method so I could see what is the effect. 另外,我使用.NET反射器来检查代码,并且标志直接传递给本机方法,因此我可以看到效果是什么。

Not sure everything it does, but I use it for one specific effect... 不知道它做的一切,但我用它来做一个特定的效果......

If you use just WordBreak, then if you have a word that is too wide to fit on a line, it just clips that word... it will not break in the middle of a word. 如果您只使用WordBreak,那么如果您的单词太宽而无法放在一行上,它只会剪切该单词...它不会在单词中间中断。 But if instead you want it to break within words that are longer than the width, such that nothing is clipped, the you can add TextBoxControl to it and it will do so. 但是,如果相反,您希望它在长于宽度的单词中打断,以至于没有任何内容被剪切,则可以向其中添加TextBoxControl,它将这样做。

The TextBox Control needs that, because when you are editing text, you really want to be able to see all the characters. TextBox控件需要这样做,因为在编辑文本时,您确实希望能够看到所有字符。

The DataGridView's text columns by default render without it, unless you are editing, and then they edit with it. 默认情况下,除非您正在编辑,否则DataGridView的文本列将不显示它,然后使用它们进行编辑。 Right now I'm trying to figure out if there is a setting somewhere in DataGridView or its Columns etc., that will let me specify TextFormatFlags to use when rendering it, so that I can fix that. 现在我正在试图弄清楚DataGridView或其Columns等中是否存在某个设置,这将让我指定TextFormatFlags在渲染时使用,以便我可以解决这个问题。 Any clues on that greatly appreciated. 对此的任何线索均表示赞赏。

It looks like it has something to do with Padding, maybe when MultiLines is in play. 看起来它与Padding有关,也许当MultiLines在玩时。

From Accurate Font Metrics 来自准确的字体指标

Note that we calculate the size of the string using MeasureText and then we add an additional 7 pixels to the height. 请注意,我们使用MeasureText计算字符串的大小,然后在高度上增加7个像素。 This is because the TextBox itself has some internal padding that it applies and from our testing it appears to be roughly 7 pixels. 这是因为TextBox本身具有一些内部填充,并且根据我们的测试,它似乎约为7像素。

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

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