根据tabControl C#的高度移动控件

时间:2015-04-20 13:44:30

标签: c# position controls tabcontrol

所以,我试图在我的表单中的tabControl下面找到一些按钮。但即使它们设置为相同的东西,它也会使所有按钮的高度不同。   有没有更好的方法让我的按钮保持在标签控件下方? tabControl会更改高度,因为其中的项目正在更改。固定按钮只会让他们处于疯狂的位置......

 private void ReForm()
    {
        //Reset the position of the buttons
        CloseButton.Top = 0;
        insertOne.Top = 0;
        insertMany.Top = 0;
        HelperButton.Top = 0;
        insertInstance.Top = 0;

        //Make an int for the height and width position of the tab windows controls
        int dtop = 0;
        int theight = 0;
        int twidth = 0;
        int xsize = 0;
        int ysize = 0;

        //Try to find the tab controls that are closest to the bottom, or closest to the right
        //When found, get the height and width of these as well
        try
        {
            foreach (Control ctr in blockDefTab.Controls)
            {
                Control control = (Control)ctr;
                //Get the height position
                if (control.Location.Y >= theight)
                {
                    theight = control.Location.Y;
                    ysize = control.Height;
                }
                //Get the width position
                if (control.Location.X >= twidth)
                {
                    twidth = control.Location.X;
                    xsize = control.Width;
                }
            }

            //Set the selected tab height and width
            //tabControl.SelectedTab.Size = new System.Drawing.Size((twidth + xsize+10), (theight+ysize));
            tabControl.Size = new System.Drawing.Size(twidth+xsize+20,theight+ysize+40);

            //Find the height of the tabControl in the form
            int formCT = 0;
            int formCH = 0;
            foreach (Control formControl in this.Controls)
            {
                if (formControl.Top >= formCT)
                {
                    if (formControl is Button)
                    {
                        //DoNothing
                    }
                    else
                    {
                        formCT = formControl.Top;
                        formCH = formControl.Height;
                    }
                }
            }

            //Set button location
            CloseButton.Top = formCH+formCT;
            insertOne.Top = formCH + formCT;
            insertMany.Top = formCH + formCT;
            HelperButton.Top = formCH + formCT;
            insertInstance.Top = formCH + formCT;
        }
        catch
        {

        }
    }

0 个答案:

没有答案