0

我做了一个浮动按钮。我希望它占据它包含的整个表单,但下面的代码在按钮右侧和表单右侧之间有一个边距。

   public FloatButton()
   {
        InitializeComponents();
        int width = (int)((double)Screen.PrimaryScreen.Bounds.Width / 20);
        int height = (int)((double)Screen.PrimaryScreen.Bounds.Height / 20);
        this.WindowState = FormWindowState.Normal;
        FormBorderStyle = FormBorderStyle.None;
        int x_pos = Screen.PrimaryScreen.Bounds.Width - width; 
        int y_pos = Screen.PrimaryScreen.Bounds.Height / 2 - height / 2;
        this.Location = new Point(x_pos,y_pos);
        this.Height = height;
        this.Width = width;
        this.button.Width = width;
        this.button.Height = height;
    }

编辑:大约 40 像素,如果我让按钮文本更长(文本换行),它不会改变

4

1 回答 1

3

对接对您有用吗?

 this.button.Dock = System.Windows.Forms.DockStyle.Fill;

只需将 Dock 设置为 Fill 即可使按钮填满其父级的整个区域。

于 2012-09-17T13:11:51.267 回答