Child Form Location

4 posts, 1 answers
  1. Victoria F
    Victoria F avatar
    46 posts
    Member since:
    May 2010

    Posted 13 Dec 2010 Link to this post

    I have MDI frame. .NET C# WinForms.
    In the MDI frame I have a main window that contains ListBox. Depend on selected item from the ListBox a Child Form suppose to be opened with parameters. Everything working file except :  I want Child Form to be opened next to the ListBox on the main form.
    So  I'm trying to set  x, y location position properties of the Child Form. Does not work.
    Every form opens ... looks like in cascading positions. ( I noticed it because I tried to open and close 5 - 7 forms and I saw that every other form was opened a little aside from the previous).
    I need every form to be opened at the same location. What should I do for it?
    Please , help...

    Thank you ,
    Victoria.
  2. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 14 Dec 2010 Link to this post

    Hi Victoria,


    hope you're well.
    you need to get the screen position of the cursor and pass that to the form.

    For exmaple:

    In the form that you want to place next to the ListBox
    private Point m_Location;
    public DialogForm(Point location)
    {
        InitializeComponent();
        m_Location = location;
    }
    private void DialogForm_Load(object sender, EventArgs e)
    {
        this.Location = m_Location;
    }

    In the ListBox Selection Changed
    private void radListControl1_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
    {
        if (radListControl1.SelectedIndex == 2)
        {
            Point scrPos = this.PointToScreen(radListControl1.Location);
            DialogForm form = new DialogForm(scrPos);
            form.Show();
        }
    }

    Hope this helps, but let me know if you have any questions
    Richard
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Victoria F
    Victoria F avatar
    46 posts
    Member since:
    May 2010

    Posted 14 Dec 2010 Link to this post

    Richard,
    This works absolutely amazing!!
    Thanks a lot!
    Victoria.
  5. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 14 Dec 2010 Link to this post

    Hi Victoria,

    Glad I could help. Please remember to mark as answer.
    All the best
    Richard
Back to Top