Click here to Skip to main content
15,905,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends !!
I have a Form "CheckerList" and its parent form "Mainform".If the user click on the textbox "TbEditedBy" in Mainform then the checkerList should appear exactly at the location of the textbox specified.I used the below code but its not working.. Please help me to find a solution..
Thanks in Advance!!
private void TbEditedBy_Click(object sender, EventArgs e)
{
    TextBox TB = (TextBox)sender;
    CheckerList ch = new CheckerList();
    ch.StartPosition = FormStartPosition.Manual;
    ch.Location = TB.Location;
    ch.tb = TB;
    ch.ShowDialog();
}
Posted
Comments
BillWoodruff 13-Oct-14 7:59am    
I don't see any code that sets 'ch to be a child of the current Mainform instance: why do you say 'CheckerList is a "child" Form ?

This: ch.tb = TB; doesn't make sense: show the code for the definition of 'tb in the 'CheckerList Form code.

Describe in detail how your code is not working: errors ? what doesn't look right ?
Sinisa Hajnal 13-Oct-14 8:13am    
The positioning looks fine, if you remove ch.tb = TB (maybe you meant ch.tb.Text = TB.Text?) everything looks like it should work - except of course ch is NOT child form and it's location might be relative to the screen / main window :)

Also, you should create property to set tb instead of having public control.
Manu Prasad 13-Oct-14 8:15am    
I have a listbox in Checkerlist form so that, If the user select any item in that listbox should reflect on the "TbEditedBy" textbox for that I declared a public textbox in Checkerlist as || public TextBox tb { get; set; } || and then set that textbox equal to the mainform textbox.
BillWoodruff 13-Oct-14 8:20am    
So the only problem is getting the position of the instance of 'CheckerList shown where you want it ? If so, my answer here should be useful.

If the instance of 'CheckerList really was a "child" of the MainForm instance, then the co-ordinates of the TextBox could be used directly.

1 solution

To give a short answer to the specific question of how to get a Form shown at the location of a Control on another Form when the second form is be shown with 'ShowDialog ... in the code for the first Form:
C#
SecondForm f2 = new SecondForm();
f2.StartPosition = FormStartPosition.Manual;
f2.Location = PointToScreen(ControlOnFirstForm.Location);
f2.ShowDialog();
 
Share this answer
 
Comments
Manu Prasad 13-Oct-14 8:21am    
Thank You!!!
Maciej Los 13-Oct-14 16:45pm    
+5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900