Click here to Skip to main content
15,902,189 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
I've created a form with a textbox1 at the location (10,14).
Now calling another modal form named FORM2 by pressing F4 from that textbox1.
I want to display the FORM2, just below the textbox1 in run time.
But I cannot calculate the location of FORM2. Pls, help me. Thanks in advance.
Posted
Comments
Sergey Alexandrovich Kryukov 8-Jun-11 17:27pm    
I would say this UI trick is a bad style. However, implementation is quite easy. For example, you can avoid modal form (highly recommended in most cases), use different layout states withing the same form.
--SA

Each control has a PointToScreen method which you can use to convert the local coords that you have into screen coordinates that you can place your new form at. So from your original form you should be able to do something like this:

void textBox1_KeyDown(...) //Assuming your using an event on the form for catching F4
{
  Point newFormPos = this.PointToScreen(new Point(10,40));
  newForm.Location = newFormPos;
  newForm.Show();
}
 
Share this answer
 
Comments
OriginalGriff 8-Jun-11 14:31pm    
I'd forgotten that! A better solution that mine - gets my 5!
Sergey Alexandrovich Kryukov 8-Jun-11 17:23pm    
This is correct, my 5. I would also add that knowing this location might be a sign of bad style.
--SA
Monjurul Habib 8-Jun-11 18:50pm    
nice answer , my 5.
Why not? It's pretty simple.

Form2 location is relative to the TLHC of the screen.
TextBox1 location is relative to the TLHC of the client area of Form1.

So, to place Form2 below TextBox1 add Form1.Location to TextBox1.Location, and offset it by the title bar thickness and the left hand border thickness, plus an offset to get it "just below".
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 8-Jun-11 17:25pm    
Not as good as the one by SK Genius, only 4 :-)
Also, I would also add that knowing this location might be a sign of bad style.
I wonder why this is needed.
--SA
OriginalGriff 9-Jun-11 2:50am    
I agree - That's why I gave him 5.
I can see what he is doing: He is trying to bring up a form that looks like it "belongs" to the parent, but that is not necessarily contained fully within it. Sort of the way a context menu works, but from the keyboard.

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