How to add MouseWheel event to Eto control

@dale,

I have a simple Eto form that we have been using to learn about Eto Forms. I want to add a MouseWheel event to a ComboBox control which enabling scrolling of the SelectedIndex for this control. To do this I added MouseWheel = self.OnMouseWheel to the control and included an event handler:

	def OnMouseWheel(self, sender, e):
		i = 1 if e.Delta > 0 else -1
		next = min(2, max(0, self.n_combobox.SelectedIndex + i))
		self.n_combobox.SelectedIndex = next

This works with .NET forms. The problem with the Eto Form is that the Python compiler complains:

Message: ComboBox() takes no arguments (5 given)

since it does not recognize MouseWheel as a legitimate argument for the control.

What is the proper way to add a MouseWheel event to the control on this Eto Form?

The complete form is here:

ETO Example Revised.py (7.9 KB)

Regards,
Terry.

@dale,

Any thoughts?

Regards,
Terry.

You might try this (or something similar):

cb = forms.ComboBox()
cb.DataStore = ['first pick A', 'pick A', 'third pick A']
cb.Font = Font('Segoe UI', my_font_size, FontStyle.Bold)
cb.TextColor = Colors.Blue
cb.SelectedIndex = self.Args.pickABC
cb.MouseWheel += self.OnMouseWheel
self.n_combobox = cb

– Dale

Is that sb.MouseWheel? Or did you mean cb.MouseWheel?

Sure…

@dale,

So when I try:

		cb = forms.ComboBox()
		cb.DataStore = ['first pick A', 'pick A', 'third pick A']
		cb.Font = Font('Segoe UI', my_font_size, FontStyle.Bold)
		cb.TextColor = Colors.Blue
		cb.SelectedIndex = self.Args.pickABC
		cb.MouseWheel = self.OnMouseWheel
		self.n_combobox = cb

The Python compiler complains:

Message: attribute 'MouseWheel' of 'Control' object is read-only

Why does Eto.Forms have like a hundred IHandler entries? Is on of them for this case? How would it be used?

Regards,
Terry.

Try +=

@dale,

More interesting with cb.MouseWheel += self.OnMouseWheel.

Now form comes up but as soon as mouse wheel is rotated anywhere inside the control, I see:

Message: OnMouseWheel() takes exactly 3 arguments (2 given)

We may be getting closer.

Regards,
Terry.

You should call your event handler something different. OnMouseWheel() is already a virtual method on the Control class, and that is what is being called here. Hence the error message. Change it to OnMouseWheelHandler and it will start to work. You may want to ensure none of your event handlers have the name of an existing (virtual) function (see for instance OnMouseUp).

Additional note: MouseEventArgs.Delta is of type SizeF, you are looking for the Height property of it.

Nathan,

Thanks for the final fix. I was tearing my hair out trying to get my Microsoft Forms code converted to Eto Forms. Much of it is the same but the few small differences that popup can be killers. I do not like NumericUpDown controls so I have replaced them with Labels over which I use the mouse to change a value. I really like this much better but it is totally dependent upon being able to capture all mouse events. With yours and Dale’s help, it now looks very promising that I can port this functionality over to Eto Forms.

Regards,
Terry.

Have fun! :slight_smile: