Disable action on the mouse moves C #

0

I have a problem in my code, I have some actions on mouse moves in C # and would like to disable them. Whenever I drag the mouse to the listbox of my form, it already does the action, I would like to leave it in the mouse click, but I am in difficulties, follow the code if someone can help I thank.

private void lstColunasLayout2_MouseMove(object sender, MouseEventArgs e) {
  int index = lstColunasLayoutSecundario.IndexFromPoint(new Point(e.X, e.Y));
  ListBox lb = sender as ListBox;
  if (index >= 0 && lb_item != null) {
    lb.SelectedIndex = index;
    AtualizaRelacaoColunas(lb);
    lb_item = null;
  }
}
    
asked by anonymous 25.09.2017 / 16:27

1 answer

2

Remove the association between the MouseMove event of the listbox and the lstColunasLayout2_MouseMove method.

To do this, delete the following line from your code:

    this.lstColunasLayout2.MouseMove += new System.Windows.Forms.MouseEventHandler(this.lstColunasLayout2_MouseMove);

If you used Visual Studio to create the form, this line of code will likely be inside the "[TemplateName] .Designer.cs" file

Another way to do this, if you're using Visual Studio, would be:

  • Open Form
  • Select Listview
  • In the Properties window, click the events button (button with a lightning bolt icon)
  • Delete the contents of the MouseMove event
25.09.2017 / 19:00