C# WinForm设置控件居中

时间:2021-06-10 11:57:45   收藏:0   阅读:31

简单阐述

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

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

原文:https://www.cnblogs.com/New-HackerHK/p/14869871.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!