2012-09-17 34 views
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个像素,如果我做的按钮文本较长(文字环绕)

+1

差距有多大?间隙的大小是否随着按钮的内容而变化? – ChrisF

+1

尝试将其放置在面板中并停靠。 – Luftwaffe

回答

3

是否对接工作对你来说不会改变?

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

只要设置码头填充应使按钮填满其父母的整个区域。

+0

这个工程(按钮填满表格)。任何解释为什么它通过简单地设置大小不起作用? –

相关问题