Click here to Skip to main content
15,905,323 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have built a custom user control in which i have button. on the click event a form appears. i want the form to appear always just below the button. its like something that happens in datetime picker.
Posted

1 solution

Bad UI design idea, really. Anyway, what's the problem? Finding the current location just below the button? Or setting the form location? Whatever your problem is, the question is even worse.

You can find location of the button by using, not to much of surprise, the properties Top and Left. Don't forget to add Button.Height to its Top, to get the vertical coordinate just below the button.

Then you need to transform it to screen coordinates: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.pointtoscreen(v=vs.110).aspx[^].

And, to set the location of the form, use the same two properties, Top and Left.

—SA
 
Share this answer
 
v2
Comments
thedinesh01 9-Apr-14 1:26am    
if i use the control in any form i want the response of my control as DateTimePicker. how to make that happen?
Sergey Alexandrovich Kryukov 9-Apr-14 2:24am    
I don't know what do you mean. I answered your question exactly, per your description. Isn't it enough? Doesn't it give you the idea how to do such things? It should be more than enough.
—SA
thedinesh01 9-Apr-14 2:29am    
not really. suppose i have main from and button in it. and i have another Form form2, when i click in the button of the mail form i want Form 2 appear just below the button. No matter where i kept the button and when i kept the main form i.e. in any corner..
Sergey Alexandrovich Kryukov 9-Apr-14 3:16am    
I already answered. Actually, your "problem" did not required asking in first place, you just need to read MSDN articles on Control, Form, etc. and act accordingly. There is nothing else to know.
—SA

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