Show Dialog box at center of its parent

后端 未结 5 536
Happy的楠姐
Happy的楠姐 2020-12-28 13:14

It\'s been a mess to show a DialogBox at the center of its parent form. Here is a method to show a dialog.

I am positioning its parent to center but not able to cen

相关标签:
5条回答
  • 2020-12-28 13:20

    In addition, if you want to set up arbitrary location you can use this

    FormLoading frm = new FormLoading();
    Point location = new Point(300, 400);
    frm.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
    frm.Location = location;
    frm.ShowDialog();
    
    0 讨论(0)
  • 2020-12-28 13:21
    NewForm.Show();
    
    NewForm.Top = (this.Top + (this.Height / 2)) - NewForm.Height / 2;
    NewForm.Left = (this.Left + (this.Width / 2)) - NewForm.Width / 2;
    
    0 讨论(0)
  • 2020-12-28 13:27

    You might want to check the Form.StartPosition property.

    http://msdn.microsoft.com/en-us/library/system.windows.forms.form.startposition.aspx

    something along the lines of:

    private void OpenForm(Form parent)
    {
        FormLoading frm = new FormLoading();
        frm.Parent = parent;
        frm.StartPosition = FormStartPosition.CenterParent;
        frm.ShowDialog();
    }
    

    This of course requires setting the form's parent.

    0 讨论(0)
  • 2020-12-28 13:35
    form1.StartPosition = FormStartPosition.CenterScreen;
    

    See http://msdn.microsoft.com/en-us/library/system.windows.forms.form.startposition(v=vs.110).aspx

    0 讨论(0)
  • 2020-12-28 13:38

    if you are making a custom MessageBox,you can simply put this:

    CenterToParent();
    

    in your custom MessageBox formload() method.

    0 讨论(0)
提交回复
热议问题