c# winform设置控件居中

 

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

  

 

posted @ 2020-05-04 09:17  SusieSnail_SUN  阅读(1423)  评论(0编辑  收藏  举报