在ListView中显示项目的上下文菜单 [英] Showing a Context Menu for an item in a ListView

查看:62
本文介绍了在ListView中显示项目的上下文菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何制作一个右键单击listView时弹出的contextMenu,我想要的是右键单击时弹出的contextMenu.我正在尝试制作聊天服务器和客户端,现在...现在,我想在右键单击连接的客户端项目时查看客户端信息.

I know how to make a contextMenu that pops up when I right click on a listView, what I want is for it to pop up when I right click on an item. I am trying to make a chat server and client, and now... Now I want to view client info when I right click on a connected client's item.

我该怎么做?

推荐答案

private void listView1_MouseClick(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Right)
    {
        var focusedItem = listView1.FocusedItem;
        if (focusedItem != null && focusedItem.Bounds.Contains(e.Location))
        {
            contextMenuStrip1.Show(Cursor.Position);
        }
    } 
}

您可以将连接的客户端信息放入contextMenuStrip1.当您右键单击某个项目时,可以显示该contextMenuStrip1中的信息.

You can put connected client information in the contextMenuStrip1. and when you right click on a item, you can show the information from that contextMenuStrip1.

这篇关于在ListView中显示项目的上下文菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆