2012-09-17 30 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

這個工程(按鈕填滿表格)。任何解釋爲什麼它通過簡單地設置大小不起作用? –

相關問題