可以通过子窗体的StartPosition属性设置。

建立两个窗体KeleyiParentForm主窗体,KeleyiSonForm子窗体

在KeleyiParentForm类中的一个方法声明显示子窗体,并设置子窗体的StartPosition为FormStartPosition.CenterScreen:


KeleyiSonForm m_SonForm = new KeleyiSonForm();
m_SonForm.MdiParent = this;
m_SonForm.StartPosition = FormStartPosition.CenterScreen;
m_SonForm.Show();


附:

StartPosition属性有如下选项,分别含义如下:
CenterParent 窗体在其父窗体中居中。
CenterScreen 窗体在当前显示窗口中居中,其尺寸在窗体大小中指定。
Manual 窗体的位置由 Location 属性确定。
WindowsDefaultBounds 窗体定位在 Windows 默认位置,其边界也由 Windows 默认决定。
WindowsDefaultLocation 窗体定位在 Windows 默认位置,其尺寸在窗体大小中指定。

CenterScreen的意思并不是屏幕居中(是相对的),它是在"当前显示窗口"中居中。

本文转载自柯乐义http://www.keleyi.com/dev/beb40909418eb322.htm

相关文章:

  • 2021-10-03
  • 2021-10-28
  • 2022-01-06
  • 2021-09-23
  • 2021-09-05
  • 2021-10-10
猜你喜欢
  • 2022-12-23
  • 2021-11-28
  • 2022-12-23
  • 2022-03-04
  • 2021-09-25
  • 2022-12-23
相关资源
相似解决方案