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

  

猜你喜欢

转载自www.cnblogs.com/susiesnai-sun/p/12825328.html