开发者

How to use contentmenustrip for listview and listviewitem? C#

开发者 https://www.devze.com 2023-02-28 15:32 出处:网络
I use Window Form C# My code private void ViewList_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right)

I use Window Form C# My code

    private void ViewList_MouseClick(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Right)
        {

            Point pt = ViewList.PointToScreen(e.Location);
            ListViewItem item = ViewList.GetItemAt(pt.X, pt.Y);              
            if (item != null)
            {
                contextMenuStrip1.Enabled = true;
                contextMenuStrip1.Show(pt);
            }

            //else { }
        }
    }

But it not working sometimes.开发者_开发问答 How to have a contentmenu for listview and listviewitem?


   if(e.Buttons == MouseButton.Right)
          contextMenuStrip1.Show(e.X+val1, e.Y+val2);

val1 and val2 are integers values, if menu doesn't come to the right position you can add some values in it to make it on the right position :)


listView1.ContextMenu = yourcontextmenu;

or you can set it from properties window also

0

精彩评论

暂无评论...
验证码 换一张
取 消