I have a WPF application that is using a WindowsFormsHost control to host a control of Windows.Forms.
I tried to implement the MouseWheel event - but it seems that the the MouseWheel event never fired.
Is there a workaround for this issue?
A workaround is to use event MouseEnter.
Suppose you have a winform label in a WindowsFormHost
In XAML
<WindowsFormsHost Height="100" Name="windowsFormsHost1" Width="200" />
In C#
System.Windows.Forms.Label label = new System.Windows.Forms.Label();
label.Text = "Hallo";`
label.MouseEnter += new EventHandler(label_MouseEnter);
label.MouseWheel += new System.Windows.Forms.MouseEventHandler(label_MouseWheel);
windowsFormsHost1.Child = label;
.....
void label_MouseEnter(object sender, EventArgs e)
{
(sender as System.Windows.Forms.Label).Focus();
}
void label_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e)
{
(sender as System.Windows.Forms.Label).BackColor = System.Drawing.Color.Red;
}
Now MouseWheel should work (label shoud change color)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With