Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

c# center modal forms

Posted on 2012-03-11
4
Medium Priority
?
282 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1500 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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

721 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