Muhammad Hassan Muhammad Hassan - 1 year ago 211
C# Question

How To Get LineHeight/FontHeight In MultiLine TextBox Using C#?

I have some text boxes having multiple line feature on with having different font size. Now I want to know the line height of this textbox text as its a simple text box so each line height will be same for a whole textbox as its not a RichTextBox.

enter image description here

So can we get it in a variable via C# programming? You can see the screenshot for more info.

Answer Source

Thanks for your helpful reply @CodyGray and finally I got my desired answer by just little editing of your code as below and its working perfectly.

int lineHeight;
using (Graphics g = textBox1.CreateGraphics())
    lineHeight = Convert.ToInt32(g.MeasureString("A", textBox1.Font).Height);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download