Solved

c# center modal forms

Posted on 2012-03-11
4
266 Views
Last Modified: 2012-03-30
my form launches 3 modal forms.  i'm trying to center the forms based on the parent form.  The first modal form centers based n the screen - no matter which form i launch first it's always the first one that centers based on screen and not on parent.  I have a workaround which is to first launch a blank form and then hide it, but does anyone know why this would occur?
0
Comment
Question by:pdering
  • 2
4 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 375 total points
ID: 37707602
How are you opening up the dialog?

Something like this should work:
    public partial class Form1 : Form
    {

        private void button1_Click(object sender, EventArgs e)
        {
            frmDialog dialog = new frmDialog();
            dialog.StartPosition = FormStartPosition.CenterParent;
            dialog.ShowDialog(this);
        }
    }

Open in new window

0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 37707787
You can have a look at the form properties - there should be one for the location of the form.  Select the option Center Parent and that should do what you want.
0
 

Author Comment

by:pdering
ID: 37709329
Thanks!  I was leaving off the "this".
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 37710763
>>Thanks!  I was leaving off the "this".

Odd.  My suggestion works with just
            frmDialog dialog = new frmDialog();
            dialog.ShowDialog();

and I have checked that from idle_mind (with a minor change)
            frmDialog dialog = new frmDialog();
            dialog.StartPosition = FormStartPosition.CenterParent;
            dialog.ShowDialog();   //the 'this' is removed

and that also centers to parent
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now