0
我試圖繪製一個邊框,看起來完全像一個在Windows 10一個ListView了。我這樣做是因爲Fixed3D看起來凹陷,而FixedSingle看起來與上述邊界不同。自定義面板只有一個孩子罷了本身就帶有填充
隨着放大鏡,我發現在Windows 10的邊界有兩個像素寬。所以,我的想法是創建一個自定義面板,該面板沒有邊框,但在其客戶區域繪製了兩個像素寬的矩形,並且在矩形內部適合一個邊框設置爲無的子區域。我嘗試了以下方法,但它不適用於Designer,也不工作。
出了什麼問題?
class CustomBorder:Panel
{
protected override void OnControlAdded(ControlEventArgs e)
{
if (Controls.Count == 2)
{
Controls.Remove(e.Control);
return;
}
base.OnControlAdded(e);
}
protected override void OnLayout(LayoutEventArgs levent)
{
var child = levent.AffectedControl;
if (levent.AffectedProperty == "Bounds")
{
FillChild(child);
}
base.OnLayout(levent);
}
void FillChild(Control child)
{
const int padding = 2;
var childSize = new Size(Bounds.Width - padding * 2, Bounds.Height - padding * 2);
child.SetBounds(padding, padding, childSize.Width, childSize.Height);
}
}
我不會按照你的邏輯,但如果你希望你的自定義面板有類似的ListView邊框,我建議你的副本[CreateParams屬性(https://referencesource.microsoft.com/# System.Windows.Forms的/的WinForms /管理/系統/的WinForms/ListView.cs,9cdcd5b83231f700,從ListView的引用),並修改它來創建你想要的效果。 – TnTinMn