This is a migrated thread and some comments may be shown as answers.

Child Form Location

3 Answers 158 Views
Form
This is a migrated thread and some comments may be shown as answers.
Victoria F
Top achievements
Rank 1
Victoria F asked on 13 Dec 2010, 11:38 PM
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.

3 Answers, 1 is accepted

Sort by
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 14 Dec 2010, 01:15 PM
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
0
Victoria F
Top achievements
Rank 1
answered on 14 Dec 2010, 04:54 PM
Richard,
This works absolutely amazing!!
Thanks a lot!
Victoria.
0
Richard Slade
Top achievements
Rank 2
answered on 14 Dec 2010, 04:57 PM
Hi Victoria,

Glad I could help. Please remember to mark as answer.
All the best
Richard
Tags
Form
Asked by
Victoria F
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Victoria F
Top achievements
Rank 1
Share this question
or