簡體   English   中英

C#Winforms |形狀邊框厚度

[英]C# Winforms | Form-border thickness

是否有任何關於常規形式邊框厚度的文檔?

目標:
我創建了一個寬度為800px的userControl。 我想用一個全分辨率的新實例(800px - 一切可見)來提出一個彈出窗口(一般的普通形式)。

我的問題:將表單設置為Form.Size.Width = 800不會這樣做。 看起來窗體的邊框包含在窗體的width屬性中。 我需要減去那個邊界。

我應該是這樣的: 2px + 800px + 2px

如果你想看到一些代碼告訴我,但我覺得這里沒必要。

編輯

在此輸入圖像描述

彈出控件后:

在此輸入圖像描述

彈出代碼:

private void buttonPopup_Click(object sender, EventArgs e)
{
    Form MyPopup = new Form();
    customControl MyUserControl = new customControl();

    MyUserControl.Dock = DockStyle.Fill;

    Rectangle rc = MyUserControl.RectangleToScreen(MyUserControl.ClientRectangle);

    //int thickness = SystemInformation.Border3DSize.Width;
    //MyPopup.MaximumSize = new Size(MyUserControl.Size.Width + (thickness*2), 1500);

    MyPopup.Controls.Add(MyUserControl);
    MyPopup.MaximumSize = new Size(rc.Width, rc.Height);
    MyPopup.Show();
}

我的意思是你的代碼看起來合乎邏輯。 但結果仍然是一樣的。 userControl顯示的小一點。 我知道我已經使用了dock = fill ,我的按鈕沒有專業地放置在布局中。 但遠離這一點,必須有一個解決方案,只需設置正確的大小

看來你正在尋找

int thickness = SystemInformation.Border3DSize;

另一個(和INHO,一個更好的 )可能性是使用控件的ClientRectangle 例如:

// Client rectangle in screen coordinates
Rectangle rc = MyControl.RectangleToScreen(MyControl.ClientRectangle);

// Let's align context menu (its width) to bottom of the control
MyContextMenuStrip.AutoSize = false;
// Depending on actual dropdown control you may want align either via
//   Width = rc.Width;
// Or 
//   ClientSize = new Size(rc.Width, someHeight);
MyContextMenuStrip.Width = rc.Width;

// Let's show context menu at the bottom of the control
MyContextMenuStrip.Show(new Point(rc.Left, rc.Bottom));

暫無
暫無

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

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