c# winform设置控件居中

时间:2020-05-04 09:32:26   收藏:0   阅读:311

 

  重写OnResize(EventArgs e)方法,通过计算,重新定位控件的位置。下面以picbox为例:

 

  protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);
            int x = (int)(0.5 * (this.Width - picbox.Width));
            int y = (int)(0.5 * (this.Height - picbox.Height));
            picbox.Location = new System.Drawing.Point(x, y);
        }

  

 

原文:https://www.cnblogs.com/susiesnai-sun/p/12825328.html

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