Board index » delphi » TPopupMenu Kills Mickey & Miny in a Freak Accident... film at 11!

TPopupMenu Kills Mickey & Miny in a Freak Accident... film at 11!

Ok, the TPopupMenu is going to drive me crazy (its a short drive).

What I am trying to do is this:

I have two speedbuttons (side by side) like so (not to scale!):

    ########$$$$
   #              #$     $
   #     1       #$ 2 $
   #              #$     $
   ########$$$$
(Damn it Jim, I'm a programmer not an Artist!)

I want to allow the user to click on button 2, and have a PopupMenu
appear under the bottom left corner of the button1  like so..

    ########$$$$
   #              #$     $
   #     1       #$ 2 $
   #              #$     $
   ########$$$$
  MMMMMMMMMMMMMMMMMMM
  M Choose me!                                 M
  M No! Choose ME!                         M
  M------------------------------------------- M
  M Don't choose them!                   M
  MMMMMMMMMMMMMMMMMMM

The problem is, is that the popup menu appears in the wrong spot.  Now
according to the documentation (yes, I know I shouldn't believe
everything I read) the menu should Popup at X,Y.... Yeah, give or take
10 or 20 pixels.

Here is the code I am using.  Now you would think that it would be off
by the same amount for each button I did this for, but its not.  One
button it might be off by 6 pixels, where another button its off by
more than 27.   Go figure.

procedure TWinMplusForm.ActiveMonthDDClick(Sender: TObject);
var SPoint: TPoint;
begin
     SPoint.X := ActiveMonthButton.Left;
     SPoint.Y := ActiveMonthButton.Top;
     SPoint   := ActiveMonthButton.ClientToScreen(SPoint);

     WinMplusForm.ActiveMonthPopup.Alignment := paLeft;
     WinMplusForm.ActiveMonthPopup.AutoPopup := False;
     WinMplusForm.ActiveMonthPopup.Popup(SPoint.X, SPoint.Y);

end;

Any help would be highly appreciated!!

Brien King
bk...@primenet.com

 

Re:TPopupMenu Kills Mickey & Miny in a Freak Accident... film at 11!


Quote
>     SPoint.X := ActiveMonthButton.Left;
>     SPoint.Y := ActiveMonthButton.Top;
>     SPoint   := ActiveMonthButton.ClientToScreen(SPoint);

        Not sure about this but the following might be right:
AMButton.Parent=theForm, right? So surely AMButton.Left is relative to the
form, so if you want to convert that to screen coordinates you're converting
form-coordinates to screen coordinates, so you want to use

     SPoint.X := ActiveMonthButton.Left;
     SPoint.Y := ActiveMonthButton.Top;
     SPoint   := theForm.ClientToScreen(SPoint);

Try it, I bet that's it.

--
David Ullrich
Don't you guys find it tedious typing the same thing
after your signature each time you post something?
I know I do, but when in Rome...

Re:TPopupMenu Kills Mickey & Miny in a Freak Accident... film at 11!


Quote
bk...@primenet.com (Brien King) wrote:
>Ok, the TPopupMenu is going to drive me crazy (its a short drive).
[...]
>The problem is, is that the popup menu appears in the wrong spot.  Now
[...]
>Here is the code I am using.  Now you would think that it would be off
>by the same amount for each button I did this for, but its not.  One
>button it might be off by 6 pixels, where another button its off by
>more than 27.   Go figure.
>procedure TWinMplusForm.ActiveMonthDDClick(Sender: TObject);
>var SPoint: TPoint;
>begin
>     SPoint.X := ActiveMonthButton.Left;
>     SPoint.Y := ActiveMonthButton.Top;

                  ^^^^^-coordinates in parents client area.
Try instead using a point relative to the client area you are
mapping to screen, e.g., 4 under bottom left corner of client
area would be
      SPoint.X := 0; {left side}
      SPoint.Y := ActiveMonthButton.ClientHeight+4;
Quote
>     SPoint   := ActiveMonthButton.ClientToScreen(SPoint);

                                    ^^^^^^ button's client area

Quote
>     WinMplusForm.ActiveMonthPopup.Alignment := paLeft;
>     WinMplusForm.ActiveMonthPopup.AutoPopup := False;
>     WinMplusForm.ActiveMonthPopup.Popup(SPoint.X, SPoint.Y);
>end;
>Any help would be highly appreciated!!
>Brien King
>bk...@primenet.com

HTH (and works :-)
Regards, Bengt Richter

Other Threads