任何点击一个按钮后在按钮下方弹出右键菜单

解决方案 »

  1.   

    PopupMenu1.Popup(ToolButton3.Left,ToolButton3.Top+ToolButton3.Height);
    这么写后弹出的不在按钮的下方
    可能是取的绝对位置
      

  2.   

    BOOL GetCursorPos(    LPPOINT lpPoint  // address of structure for cursor position  
       );
      

  3.   

    BOOL GetWindowRect(    HWND hWnd, // handle of window
        LPRECT lpRect  // address of structure for window coordinates
       );
     
      

  4.   


    procedure TForm1.Button1Click(Sender: TObject);
    var
      rct:Trect;
    begin
      getwindowrect(button1.Handle,rct);
      popupmenu1.Popup(rct.Right,rct.Bottom);
    end;
      

  5.   


    procedure TForm1.ToolButton2Click(Sender: TObject);
    var
      APoint: TPoint;
    begin
      APoint := ToolButton2.ClientToScreen(Point(0, ToolButton2.ClientHeight));  TrackPopupMenu(PopupMenu1.Handle, TPM_BOTTOMALIGN , APoint.X, APoint.Y,
        0, self.Handle, nil);
    end;
      

  6.   

    [Error] UPrint.pas(87): Undeclared identifier: 'Handle'
      

  7.   

    [Error] UPrint.pas(87): Undeclared identifier: 'Handle'
      

  8.   

    我试好用的,你有button1吗?button1与事件关联了吗?TForm1.Button1Click
      

  9.   

    procedure TFrmPrint.ToolButton3Click(Sender: TObject);
    var   Rect:TRect;
    begin
      GetWindowRect(ToolButton3.Handle,Rect);
      PopupMenu1.Popup(Rect.Left,Rect.Bottom);
    end;
    [Error] UPrint.pas(88): Undeclared identifier: 'Handle'
      

  10.   

    这个可以弹出到指定位置,但是不知道怎么回事点击弹出菜单后不执行菜单的N1Click过程,就是点了没反应
      

  11.   


    procedure TForm1.ToolButton1Click(Sender: TObject);
    var
      APoint: TPoint;
    begin
      apoint:=toolbutton1.ClientToScreen(Point(toolbutton1.Left+toolbutton1.Width, toolbutton1.Top+toolbutton1.Height));
      popupmenu1.Popup(apoint.X,apoint.y);
    end;
      

  12.   

    PopupMenu1.Popup(mouse.CursorPos.X,mouse.CursorPos.Y);