我做了一个浮动按钮。我希望它占用整个包含表单但下面的代码在按钮右侧和表单右侧之间有一个边距。
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个像素,如果我让按钮文本更长(文本换行),它就不会改变
答案 0 :(得分:3)
对接是否适用于您?
this.button.Dock = System.Windows.Forms.DockStyle.Fill;
只需将Dock设置为Fill就可以使按钮填满其父级的整个区域。