locked
Toolstrip width not working yet height works fine. RRS feed

  • Question

  • I am trying to change Toolstrip width to match text in the toolstrips width.

    Using autosize doesnt work, the width is the full screen.

    Changing autosize to false and then changing width and height only changes the height.

    Any clues would be appreciated.

                Image nigel = Image.FromFile(drivestring + @"\\pcbcad720\play.png");
    
    
                ts1.BackColor = Color.Cyan;
                ts1.Items.Add("Toolbar>>");
                ts1.Items.Add("Edit line", nigel, new EventHandler(this.f1editlineclick));
                ts1.Items.Add("New line", nigel, new EventHandler(f2newlineclick));
                ts1.Items.Add("Edit text", nigel, new EventHandler(f3edittextclick));
                ts1.Items.Add("New text", nigel, new EventHandler(f4newtextclick));
                ts1.Items.Add("Edit symbol", nigel, new EventHandler(f5editsymbolclick));
                ts1.Items.Add("New symbol", nigel, new EventHandler(f6newsymbolclick));
                ts1.Items.Add("Add already used symbol", nigel, new EventHandler(newsymbolfromclick));
    
    
                ts1.AutoSize = false;
                ts1.Width = 500;
                ts1.Height = 30;
                
    
                Controls.Add(ts1);
    


    n.Wright

    Friday, January 31, 2020 10:25 PM

Answers

  • Hi nigelwright7557,

    Sorry for delay in reply.

    As far as I know, the width of toolscript auto follow the follow the form. To custom the width of toolscript, maybe we could use panel to save toolscript control. Please refer it:

        public partial class Form1 : Form
        {
            private ToolStrip ts1 = new ToolStrip();
            private Panel panel = new Panel();
    
            public Form1()
            {
                InitializeComponent();
    
                panel.Location = new Point(0 + this.AutoScrollPosition.X, 0+this.AutoScrollPosition.Y);
                panel.Size = new Size(200, 50);
    
                Image nigel = Image.FromFile(drivestring + @"\\pcbcad720\play.png");
    
    
                ts1.BackColor = Color.Cyan;
                ts1.Items.Add("Toolbar>>");
                ts1.Items.Add("Edit line", nigel, new EventHandler(this.f1editlineclick));
                ts1.Items.Add("New line", nigel, new EventHandler(f2newlineclick));
                ts1.Items.Add("Edit text", nigel, new EventHandler(f3edittextclick));
                ts1.Items.Add("New text", nigel, new EventHandler(f4newtextclick));
                ts1.Items.Add("Edit symbol", nigel, new EventHandler(f5editsymbolclick));
                ts1.Items.Add("New symbol", nigel, new EventHandler(f6newsymbolclick));
                ts1.Items.Add("Add already used symbol", nigel, new EventHandler(newsymbolfromclick));
    
                ts1.AutoSize = false;
                ts1.Height = 50;
    
    
                panel.Controls.Add(ts1);
                this.Controls.Add(panel);
            }
        }

    Hope it could help you.

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Monday, February 3, 2020 5:40 AM