Left click works right does not
-
I do not understand why the right button does not work??
namespace mouseclick
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
listBox1.MouseClick += new MouseEventHandler(listBox1_MouseClick);
listBox1.Items.Add("aaaaaaaaaaaa");
listBox1.Items.Add("aaaaaaaaaaaa");
listBox1.Items.Add("aaaaaaaaaaaa");
}void listBox1\_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { MessageBox.Show("Left Button"); // Works } if (e.Button == MouseButtons.Right) { MessageBox.Show("Right Button"); // Does not work } } }
}
-
I do not understand why the right button does not work??
namespace mouseclick
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
listBox1.MouseClick += new MouseEventHandler(listBox1_MouseClick);
listBox1.Items.Add("aaaaaaaaaaaa");
listBox1.Items.Add("aaaaaaaaaaaa");
listBox1.Items.Add("aaaaaaaaaaaa");
}void listBox1\_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { MessageBox.Show("Left Button"); // Works } if (e.Button == MouseButtons.Right) { MessageBox.Show("Right Button"); // Does not work } } }
}
-
-
-
I do not understand why the right button does not work??
namespace mouseclick
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
listBox1.MouseClick += new MouseEventHandler(listBox1_MouseClick);
listBox1.Items.Add("aaaaaaaaaaaa");
listBox1.Items.Add("aaaaaaaaaaaa");
listBox1.Items.Add("aaaaaaaaaaaa");
}void listBox1\_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { MessageBox.Show("Left Button"); // Works } if (e.Button == MouseButtons.Right) { MessageBox.Show("Right Button"); // Does not work } } }
}
-
The
ListBox
does not return a right click event; see the table on this MSDN page[^].Use the best guess
-
The
ListBox
does not return a right click event; see the table on this MSDN page[^].Use the best guess
-
I see from your posted link that a listView does have a right.mouse.button.click. I guess that's my best solution.
-
I do not understand why the right button does not work??
namespace mouseclick
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
listBox1.MouseClick += new MouseEventHandler(listBox1_MouseClick);
listBox1.Items.Add("aaaaaaaaaaaa");
listBox1.Items.Add("aaaaaaaaaaaa");
listBox1.Items.Add("aaaaaaaaaaaa");
}void listBox1\_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { MessageBox.Show("Left Button"); // Works } if (e.Button == MouseButtons.Right) { MessageBox.Show("Right Button"); // Does not work } } }
}
Perhaps the MouseDown and MouseUp events could help.
-
I do not understand why the right button does not work??
namespace mouseclick
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
listBox1.MouseClick += new MouseEventHandler(listBox1_MouseClick);
listBox1.Items.Add("aaaaaaaaaaaa");
listBox1.Items.Add("aaaaaaaaaaaa");
listBox1.Items.Add("aaaaaaaaaaaa");
}void listBox1\_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { MessageBox.Show("Left Button"); // Works } if (e.Button == MouseButtons.Right) { MessageBox.Show("Right Button"); // Does not work } } }
}
better use else if in second condition if (e.Button == MouseButtons.Left) { MessageBox.Show("Left Button"); } else if (e.Button == MouseButtons.Right) { MessageBox.Show("Right Button"); }