簡單闡述
1在C#的WinForm里面,原生控件是沒有居中屬性的,故通過重寫OnResize(EventArgs e)方法,通過計算,重新定位控件位置。
以 Tab 控件為例
(1)重寫居中的代碼如下:
protected override void OnResize(System.EventArgs e)
{
base.OnResize(e);
int x = (int)(0.5 * (this.Width - tabLogin.Width));
int y = (int)(0.5 * (this.Height - tabLogin.Height));
tabLogin.Location = new System.Drawing.Point(x, y);
}
//網絡素材僅限收藏 方便學習