Results 1 to 3 of 3

Thread: C# WinForms position a child dialog with specific coordinates

  1. #1

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a new Maserati down a dead end street
    Posts
    4,245

    C# WinForms position a child dialog with specific coordinates

    I can't position a child dialog where I want it. My hardware configuration is a docked laptop with two large monitors, A on the left and B on the right. I don't care where my main application is appearing, but if it's on A then I want my dialog on A also, and same thing if B. I don't want the child dialog centered. There is a grid on the parent form and I want the dialog to initialize underneath the grid, that way the user can see the rows he has selected which are the rows the dialog is operating on.

    This child dialog is very annoying becuase if I am running on A it shows up on B. Then if I am running on B it shows up on A. Which is exactly the opposite of what I want!

    If I center the child to the parent it's on the correct monitor, but centered it covers up the grid so I want to push it down.

    What am I not understanding? Because honestly the logic of this dialog should've been the hard part but that took no time at all compared to how much time this little "icing on the cake" is taking me!!!

    Here is the code. Some of it is commented out but you can maybe see what I've tried and hopefully tell me what I am doing wrong currently. Thanks.

    Code:
                
    using (System_Data_III.frmSystemReleaseQuickSelect frmSystemReleaseQuickSelect = new System_Data_III.frmSystemReleaseQuickSelect(listOfSDC, this.Location.X, this.Location.Y))
    {
                    frmSystemReleaseQuickSelect.StartPosition = FormStartPosition.Manual;
                    frmSystemReleaseQuickSelect.Location = new Point(2543 - this.Location.X, 718 - this.Location.Y);
                    frmSystemReleaseQuickSelect.ShowDialog();
    }
    
    
            List<int> listOfSDC;
            Point newLocation;
            public frmSystemReleaseQuickSelect(List <int> listOfSDC, int parentX, int parentY)
            {
                InitializeComponent();
                this.listOfSDC = listOfSDC;
                // Because I want this form positioned below the list of systems on frmCS so the user can see what he selected and I don't have to repeat it back to him.
                newLocation = new Point(2543 - parentX, 718 - parentY);
            }
    
            private void frmSystemReleaseQuickSelect_Load(object sender, EventArgs e)
            {
                LoadSystemRelease();
    
                //StartPosition = FormStartPosition.CenterParent;
                //Location = newLocation;
            }
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  2. #2

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a new Maserati down a dead end street
    Posts
    4,245

    Re: C# WinForms position a child dialog with specific coordinates

    You know what? Nevermind. I will just open up the form centered. It's small enough that the user can see the grid behind it. If the user wants to see the whole grid he can position the form lower himself. This is a stupid problem, don't waste your time on it, I'm not!
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    106,893

    Re: C# WinForms position a child dialog with specific coordinates

    If you want your dialogue positioned relative to an existing form then you should use coordinates relative to that form, e.g.
    csharp Code:
    1. var position = PointToScreen(new Point(button1.Left, button1.Bottom));
    2.  
    3. using (var dialogue = new Form2
    4.                       {
    5.                           StartPosition = FormStartPosition.Manual,
    6.                           Location = position
    7.                       })
    8. {
    9.     dialogue.ShowDialog();
    10. }
    That will display the dialogue immediately below the Button.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width