none
How to Resize a ToolStrip-control? RRS feed

  • Question

  • I try to resize my ToolStrip-control to give the buttons some space, but it somehow doesn't work. Can you show me how to do it? Thanks in advance


    //namespace MyNamespae

    namespace MyNamespace
    {
     
     //using...
     using System.Windows.Forms;


     //class MyForm
     class MyForm:Form
     {

      //constructor
      public MyForm()
      {
       Text="How to Resize a TooStrip?";
       ToolStripButton toolstripbutton1=new ToolStripButton("Height=21");
       ToolStripButton toolstripbutton2=new ToolStripButton("Height=34");
       ToolStripButton toolstripbutton3=new ToolStripButton("Height=55");
       toolstripbutton1.Height=21;
       toolstripbutton1.Height=34;
       toolstripbutton1.Height=55;
       ToolStrip toolstrip=new ToolStrip
       (
        new ToolStripItem[]
        {
         toolstripbutton1,
         toolstripbutton2,
         toolstripbutton3,
        }
       );
       toolstrip.Height=89;
       Controls.Add(toolstrip);
      }
     }


     //class Application
     static class Application
     {
      [System.STAThread]
      static void Main()
      {
       System.Windows.Forms.Application.EnableVisualStyles();
       System.Windows.Forms.Application.Run(new MyForm());
      }
     }
    }



    Tuesday, August 28, 2007 3:04 PM

Answers

  •  

    Hi Tile,

    Try to set both ToolStrip and ToolStripButton’s AutoSize to false, and make sure your ToolStrip’s height is greater than all your ToolStripButtons. Something like the following:

    Code Snippet

                this.toolStrip1.AutoSize = false;

                this.toolStripButton1.AutoSize = false;

                this.toolStripButton2.AutoSize = false;

                this.toolStripButton3.AutoSize = false;

                this.toolStripButton1.Height = 20;

                this.toolStripButton2.Height = 40;

                this.toolStripButton3.Height = 60;

                this.toolStrip1.Height = 65;

     

    Hope this helps.
    Best regards.

    Friday, August 31, 2007 9:02 AM