日期:2014-05-17  浏览次数:20686 次

子窗口显示位置的问题
是winform的程序

有两个form:form1和form2
程序启动调用form1   中间一个button调用form2

form1的大小比form2大
form1相当于form2的父窗口
怎么才能在点击button后  form2始终出现在form1的正中间


C# 好像对话框的位置不受position的控制。它们的位置都不是固定的。

------解决方案--------------------

        private void button1_Click(object sender, EventArgs e)
        {
            Form1 f2 = new Form2();
            f2.StartPosition = FormStartPosition.Manual;
            f2.Location=this.PointToScreen(new Point((this.Width - f2.Width) / 2, (this.Height - f2.Height) / 2));
            f2.Show();
        }


设置一下Location就可以了。