none
How-To Set Height of textbox ?

    Question

  • Hi, For my Textbox, I set is Border = NONe. On doing this, the height turns very small. I can't programamtically set the height of the textbox. If I set any border, then again its fine, but I don't want any border.

    I tried creating a custom textbox, and set the Height of it, but it has no effect. How to handle this situation ? Any help is highly appreciative.


    Thanks
    If you find any answer helpful, then click "Vote As Helpful" and if it also solves your question then also click "Mark As Answer".
    Friday, July 15, 2011 5:32 PM

Answers

  • MAking border = none, defintely makes the textbox smaller, but text fits in it. With the custom textbox, the text is added at 4th y, due to which full text is not visible length wise.

    So yes, I agree wiith you all, then by making border as none or any other should make the text not visible. But it was the location of the DrawString which was causing problem with text visibility.

    And MultiLine, I would never go for it, to just increase the height, as along with height we are allowing the user to enter more than a line which our app isn't expected to do so.

    Once again, thanks a lot to all.


    Thanks
    If you find any answer helpful, then click "Vote As Helpful" and if it also solves your question then also click "Mark As Answer".
    • Marked as answer by truptivd Monday, July 18, 2011 9:00 AM
    Monday, July 18, 2011 9:00 AM

All replies

  • The TextBox control in C# (and VB.NET) ignores the height property and adjusts it to fit the font height. By calculating the exact font size needed, we can set the TextBox to a desired height.

    Single-line textbox height is set by the size of the font, not the TextBox.Height property. This makes it difficult if you are looking for an exact height. Luckily, the font property uses a float for the font size (emSize). You can use fractions of fonts to fine-tune the textbox height.

    if you want to use multi-line textbox, you will have to use listBox.


    Mitja
    Friday, July 15, 2011 5:36 PM
  • Try enabling multiline, or else you may update the region by overriding layout.

     

     

    Hope this helps.


    Regards Vallarasu S. BreakingDotNet.blogspot.com
    Friday, July 15, 2011 5:37 PM
  • Set Multiline to True.
    Friday, July 15, 2011 5:37 PM
  • Multi-line textBox and adding a property ScrollBar.Veritcal will still look like a textBox (single line textBox) on the outiside, but there will be rows available.
    Mitja
    • Proposed as answer by vinothmdu2001 Monday, July 18, 2011 11:56 AM
    Friday, July 15, 2011 5:38 PM
  • THEN why when border is set, it is fine. If border is none, then it becomes almost half size and full text is also not visibel in height.

    How & What to set to textbox when border is none.


    Thanks
    If you find any answer helpful, then click "Vote As Helpful" and if it also solves your question then also click "Mark As Answer".
    Friday, July 15, 2011 5:44 PM
  • Try this code to put into constructor (or load time):

    textBox1.BorderStyle = BorderStyle.None;
    textBox1.Font = new Font("Arial", 25, FontStyle.Regular);
    


    just this, no othe code. Even if you have changed some properties in the form designer, set it back to default settings.

    You will see how textBox height changes. And the text is still insde of textBox.

    Aobut invisible text, of couse it is invisible, if you set MultiLine property to TRUE. Use key UP and DOWN arrows to scroll through the text, or add ScrollBar.Verical property, to use a mouse click.


    Mitja
    Friday, July 15, 2011 5:49 PM
  • Set AutoSize to False.  There's a reason you shouldn't do this and the TextBox works the way it does, but you don't like that.
    Friday, July 15, 2011 5:56 PM
  • MAking border = none, defintely makes the textbox smaller, but text fits in it. With the custom textbox, the text is added at 4th y, due to which full text is not visible length wise.

    So yes, I agree wiith you all, then by making border as none or any other should make the text not visible. But it was the location of the DrawString which was causing problem with text visibility.

    And MultiLine, I would never go for it, to just increase the height, as along with height we are allowing the user to enter more than a line which our app isn't expected to do so.

    Once again, thanks a lot to all.


    Thanks
    If you find any answer helpful, then click "Vote As Helpful" and if it also solves your question then also click "Mark As Answer".
    • Marked as answer by truptivd Monday, July 18, 2011 9:00 AM
    Monday, July 18, 2011 9:00 AM