使用鼠标右键选择? [英] selecting, using the RIGHT mouse button ?

查看:58
本文介绍了使用鼠标右键选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带删除"按钮的listBox1和一个contextMenuStrip1.
直到现在我都可以使用它,但是我必须在listBox1中左键单击一个项目(以选择它),然后(在任何地方)我单击右键并选择删除"-它可以工作,但不是我真正想要的.

如何使用鼠标右键选择一个项目(从listBox1)(仅删除该选择)?


I have a listBox1 and a contextMenuStrip1 with a "delete" button.
I made it functional until now, but I must Left click an Item from listBox1 (to select it), then (anywhere) i click right and choose "delete"- it works but not as I really want.

How do I select an Item (from listBox1), using the RIGHT mouse button(to delete that selection only)?


//I use this event to get the mouse buttons:
private void listBox1_MouseDown(object sender, MouseEventArgs e)
        {
            if (listBox1.Items.Count > 0)//if List is NOT empty
            {
                if (e.Button == MouseButtons.Right){
//..?..



谢谢.



Thanks.

推荐答案

您可以找到所选的项目,然后将其选中.将这些代码写入
You can find selected item then if it''s selected delete it.Write these codes to
if (e.Button == MouseButtons.Right){

类似:

for (int i = 0; i < listBox1.Items.Count; i++)
{
    listBox1.SelectedIndex = i;
    Delete(listBox1.Items[i]); // Your delete Code.
}


Iam为您重新配置它在ListBox的鼠标单击事件上使用此事件
:
Iam reformulating it for you Use This On Mouse Click Event of ListBox
:
if (listBox1.Items.Count >; 0)//if List is NOT empty
            {if (e.Button == MouseButtons.Right){

for (int i = 0; i < listBox1.Items.Count; i++)
            {
                listBox1.SelectedIndex = i;
                //Your Delete CODE!
}
} // Your delete Code.            }


这篇关于使用鼠标右键选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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