当我点击button控件时,MainMenu菜单如何在点击处弹出?多谢!!

解决方案 »

  1.   

    代码如下
    procedure xPopupMenuPopup(Sender: TObject; pMenu: TPopupMenu); 
    begin
      with Sender as TControl do
      begin
        with ClientOrigin do
        begin
          Inc(Y, ClientHeight);
          pMenu.Popup(X, Y);
        end;
      end;
    end;
      

  2.   

    这个好象不行的吧,只听说有popmenu的,谁知道也告诉我下
      

  3.   

    谁说不行的?
    只要获得MainMenu的子菜单项,后面的不就和处理PopupMenu一样了
    ------------------------------------------
    写程序要学会变通!!!!!!!!!!
      

  4.   

    procedure TFrmPreview.SpeedButtonZoomClick(Sender: TObject);
    Var P:TPoint;
    begin
    //弹出菜单
      p := SpeedButtonZoom.ClientToScreen(
                       Point(0,SpeedButtonZoom.Height));
      PopupMenu1.Popup(p.x,p.y);
    end;
    揭帖
      

  5.   

    // 在MouseDown 事件中
    procedure TForm1.SpeedButton1Mousedown(Sender:TObject...);
    var p:TPoint;
    begin
       getcursorpos(p);
       if button=mbleft then //判断鼠标左右键
          PopupMenu1.Popup(p.x,p.y);
    end;
      不行找我。
      

  6.   

    CMenu menu,menuTemp;
    menuTemp.LoadMenu(IDR_PERSONTYPE);
    CString strMenu;
    menu.CreatePopupMenu();
    for(UINT i=0;i<menuTemp.GetMenuItemCount();i++)
    {
    menuTemp.GetMenuString(i,strMenu,MF_BYPOSITION);
    menu.InsertMenu(i,MF_BYPOSITION|MF_POPUP,int(menuTemp.GetSubMenu(i)->m_hMenu),strMenu);
    }
    menu.TrackPopupMenu(TPM_RIGHTBUTTON|TPM_LEFTALIGN,rect.left,rect.bottom,this);
    ----------------------
    上面是vc中的代码
    本人对delphi不太熟,你转换过去就行了
      

  7.   

    >>我有一个PopMenu和主菜单一抹一样,我不想使用ActionList,
    >>那么怎么能够做到最简单呢?Kingron:请参看如下代码:procedure PopMainMenuItem(hWnd:HWND;Menu:TMenuItem);
    var
      R:TRect;
    begin
      R:=Screen.DesktopRect;
      TrackPopupMenu(Menu.Handle,TPM_LEFTALIGN ,Mouse.CursorPos.X,Mouse.CursorPos.Y,0,hWnd,@R);
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      PopMainMenuItem(Handle,MainMenu1.Items[0]);
    end;
      

  8.   

    如果只button的话,是不可以的,但换成toolButton就可以了,只要设置它的Menuitem属性为MainMenu1的一个菜单项就行了.
    对于其它的控件你可以看看它有没有Menuitem属性!
      

  9.   

    Use TMainMenu to provide the main menu for a form. To begin designing a menu, add a main menu to a form, and double-click the component. ,想让主菜单在一个地方弹出,这这这。。我不会,哈哈,看看help吧
      

  10.   

    procedure TfrmMain.Button3Click(Sender: TObject);
    begin
      PopupMenu1.Popup(Button3.ClientOrigin.X, Button3.ClientOrigin.Y);
    end;
      

  11.   

    呵呵,是用trackpopupmenu的,或许是track……自己查查看。
      

  12.   

    我靠!不会没一个人懂delphi吧?  我都给出代码了,还有人说 不行!
      

  13.   

    procedure TForm1.Button2Click(Sender: TObject);
    var P:TPoint;
    begin
      GetCursorPos(P);
      TrackPopupMenu(ManuItem1.Handle, 0, p.X, p.Y,0, handle, nil);
    //不得直接使用MainMenu,只可以的MainMenu的子项目
    end;