簡體   English   中英

如何使按鈕占據整個包含形式?

[英]How can I make a button take up its entire containing form?

我做了一個浮動按鈕。 我希望它占據所有包含它的表單,但是下面的代碼在按鈕的右邊和表單的右邊之間有一個空白。

   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像素,並且如果我將按鈕文本加長(文本換行),它不會改變

對接對您有用嗎?

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

只需將Dock設置為Fill即可使按鈕填充其父對象的整個區域。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM