Gop*_*ath 8 .net c# compact-framework
我想集中在.NET Compact Framework中使用Form.ShowDialog()启动的弹出窗体.我没有在.NET CF Form对象中看到任何像StartPosition这样的属性.
有人可以建议我如何在.NET CF 3.5中居中弹出窗口?
Fre*_*örk 12
您可以创建一个为您工作的扩展方法:
public static class FormExtensions
{
public static void CenterForm(this Form theForm)
{
theForm.Location = new Point(
Screen.PrimaryScreen.WorkingArea.Width / 2 - theForm.Width / 2,
Screen.PrimaryScreen.WorkingArea.Height / 2 - theForm.Height / 2);
}
}
Run Code Online (Sandbox Code Playgroud)
你这样称呼它:
TheDialogForm f = new TheDialogForm();
f.CenterForm();
f.ShowDialog();
Run Code Online (Sandbox Code Playgroud)
如果您希望弹出窗体默认显示在屏幕的中心,您可以在窗体属性中设置它的起始位置,它应该听起来像'中心父窗口'.
像这样的东西:
form1.StartPosition = FormStartPosition.CenterScreen;
Run Code Online (Sandbox Code Playgroud)
小智 6
如果没有为Dialog定义Parent,则使用
login.StartPosition = FormStartPosition.CenterScreen;
login.ShowDialog();
Run Code Online (Sandbox Code Playgroud)
其中login是FormObject
或者如果您在现有的父母之上呼叫,也可以使用 Form
login.StartPosition = FormStartPosition.CenterParent;
login.ShowDialog();
Run Code Online (Sandbox Code Playgroud)
Form如果您认为该属性始终与您相同,也可以在属性对话框中设置此属性.默认情况下,它应设置为CenterParent,如果您在某些情况下Form在Parent之前调用您的内容,这将无法工作Form,例如首次登录屏幕等.