Changing the height of a single line textbox at design time

Posted on 2007-07-27
Last Modified: 2008-02-01
How can I change the height of a textbox at design time without making it multiline ?

Question by:rajesh_khater
    LVL 8

    Assisted Solution

    try this

    Hashtable hash = new Hashtable();

                //## save default location of buttons into a
                //## hash table
                public void InitDefLoc()
                      foreach(Control cl in Controls)
                            if ((cl is Button) ^ (cl is TextBox))
                DefLocation dl = new DefLocation();

    public Form1()

                      // Required for Windows Form Designer support
                      // TODO: Add any constructor code after InitializeComponent call

    private void Form1_Resize(object sender, System.EventArgs e)
                      foreach (Control ctl in Controls)
                            if ((ctl is Button)^(ctl is TextBox))
                                  int widthRatio = ClientRectangle.Width * 100 / startW;
                                  int heightRatio = ClientRectangle.Height * 100 / startH;                        
                                  DefLocation dl2 = (DefLocation)hash[ctl];
                                  Point pnt = new Point((dl2.getDefCX() * widthRatio / 100),(dl2.getDefCY() * heightRatio / 100));
                                  ctl.Width = dl2.getDefW() * widthRatio / 100;
                                  ctl.Height = dl2.getDefH() * heightRatio / 100;
                                  ctl.Location = pnt;

    public class DefLocation
                int defW,defH,defCX,defCY;
                public void setDefW(int dw){
                      defW = dw;
                public void setDefH(int dh){
                      defH = dh;
                public void setDefCX(int dcx){
                      defCX = dcx;
                public void setDefCY(int dcy){
                      defCY = dcy;

                public int getDefW(){return defW;}
                public int getDefH(){return defH;}
                public int getDefCX(){return defCX;}
                public int getDefCY(){return defCY;}
    LVL 96

    Accepted Solution

    You don't have control over the height of the control for the single-line TextBox, it is controlled by the font height.


    Assisted Solution


    Change the font!

    TextBox.Font = new Font(TextBox.Font.FontFamily, 6, TextBox.Font.Style);

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now