C# WinForm设置控件居中


简单阐述

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);
}

//网络素材仅限收藏 方便学习


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM