DevExpress 给GridControl(或TreeList,等控件都可以)添加右键菜单

1、添加BarManager和popupMenu组建

2、设置popupMenu组件的Manager属性

3、右键点击popupMenu主键,点击Customize选项添加菜单

4、然后便可添加到鼠标事件中,此处以GridControl为例

/// <summary>
/// popupMenu菜单的点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
    //点击菜单之后所要做的事
}
//原创来自 http://www.luofenming.com/show.aspx?id=ART2019071600001 不懂可以问我
/// <summary>
/// 设置控件点击位置弹出右键菜单gridControl的鼠标弹起事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void gridControl1_MouseUp(object sender, MouseEventArgs e)
{
    try
    {
        if (e.Button == MouseButtons.Right)//设置右键启作用
        {
            popupMenu1.ShowPopup(gridControl1.PointToScreen(e.Location));
        }
    }
    catch (Exception ex)
    {

        MessageBox.Show(ex.Message);
    }
}


评论