问题描述
我有与具有不同的字体大小多线功能的一些文本框。现在我想知道这个文本框的文本作为其插入符光标高度一个简单的文本框,以便插入符号光标将能够调整根据字体的变化等,并在换句话说,我想知道TextBox的行高或字体大小作者的textBox
I have some textBox having multiple line feature on with having different font size. Now I want to know the caret cursor height of this textbox text as its a simple text box so caret cursor will be able to resize as per font change etc and in other words I want to know the line height of the textBox or the font size of textBox.
int fontHeight ;
using (Graphics g = textBox1.CreateGraphics()) {
float points = textBox1.Font.SizeInPoints;
fontHeight = Convert.ToInt16(points * g.DpiX / 72);
}
MessageBox.Show("myFont size in pixels: " + fontHeight );
和...
int fontHeight = Convert.ToInt32(textBox1.Font.Size);
有关这个我用上面的代码,但没有给出全部结果,因此如何使它更加完美?
For this I am using the above codes but not giving the full results so How to make it more perfect?
推荐答案
尝试一些代码和片段,并对其进行编辑后,我得到了文本的每一个大小如下共享下面的解决方案, 。其工作完美
After trying some codes and snippets and edit them I got the below solution for every size of text that is shared below and its working perfectly.
int lineHeight;
using (Graphics g = textBox1.CreateGraphics())
{
lineHeight = Convert.ToInt32(g.MeasureString("A", textBox1.Font).Height);
}
这篇关于如何获取插入符光标高度在文本框中使用C#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!