private void zedGraphControl1_MouseEnter(object sender, EventArgs e)
        {
            zedGraphControl1.Location = new Point(this.Width / 2, this.Height / 2);
        }


但这将使控件的左侧位于form1的中间,然后所有右侧都将退出form1区域。

我怎样才能使整个控件位于中间?

最佳答案

您已经正确找到主Winform的中心并将图形控件放置在此处。要将其居中定位,只需删除其宽度和高度的一半即可。

private void zedGraphControl1_MouseEnter(object sender, EventArgs e)
{
    zedGraphControl1.Location = new Point(Width / 2 - zedGraphControl1.Width/2, Height / 2 - zedGraphControl1.Height/2);
}


很抱歉,但是我爱MS Paint:

关于c# - 我该如何在鼠标进入事件时将新表单/用户控件移至Form1的中心?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23840246/

10-10 18:38