Board index » cppbuilder » PopUp Menu is show distant of the control...

PopUp Menu is show distant of the control...


2004-06-08 11:59:28 AM
cppbuilder28
Hello again...
I have a Popup menu that must be showed only under some circunstances.
Because of this i set the propert AutoPopUp to false.
Bu now, when i show it with the X an Y of the MouseDown Event of my
TreeView, The PopUp appears far from the control, outside my form's
application...
How can i put this popup under the mouse pointer?
Thank's for the help
Eduardo Jauch.
 
 

Re:PopUp Menu is show distant of the control...

Eduardo Jauch < XXXX@XXXXX.COM >wrote:
Quote
[...] How can i put this popup under the mouse pointer?
Look at the Popup method in the help. You'll see that it takes
X,Y coordinates that are screen relative. If you're passing the
X,Y from a control's MouseDown event, those coordinates are
client relative.
ClientToScreen will convert the control-relative coordinates
to screen-relative coordinates:
TPoint P = ClientToScreen( TPoint(X,Y) );
Now, instead of passing X,Y to the popup, pass P.x,P.y.
~ JD
 

Re:PopUp Menu is show distant of the control...

"Eduardo Jauch" < XXXX@XXXXX.COM >wrote in message
Quote
Bu now, when i show it with the X an Y of the MouseDown
Event of my TreeView, The PopUp appears far from the
control, outside my form's application...
The OnMouse... events provide client coordinates that are relative to the
top-left corner of the component being clicked on. The Popup() method, on
the other hand, expects screen coordinates that are relative to the top-left
corner of the entire screen instead.
Quote
How can i put this popup under the mouse pointer?
You have to translate the OnMouse... client coordinates into absolute screen
coordinates. Every visual component has a ClientToScreen() method inherited
from TControl that you can use for that. For example
void __fastcall TForm1::SomeControlMouseDown(TObject* Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
TPoint p = SomeControl->ClientToScreen(Point(X, Y));
PopupMenu1->Popup(p.x, p.y);
}
Gambit
 

{smallsort}

Re:PopUp Menu is show distant of the control...

Thank's to both of you Gambit and JD. Now Work fine.
Eduardo Jauch.