I am trying to access the MouseWheel events on my application main form, with much difficulty. There is no event handler in the properties and after much internet searching, it seems as if I have to manually create the event handler.
My code is :-
C#:
C#
using System.ComponentModel;
using System.IO;
using System.Net.NetworkInformation;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using static System.Net.WebRequestMethods;
namespace Image_Viewer
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
this.MouseWheel += new MouseEventHandler(MainForm_MouseWheel);
}But the compiler says

Am I missing a directive or something?
I have seen almost identical code posted on the internet, except using Form1 instead of MainForm


Cr BhargaviRank #420 · 5.9K reputationPosted Aug 17, 2023, 11:34 AM EDT
Event handler method
MainForm_MouseWheelis missing. Please try adding that and run the code again, you would be able to have that issue fixedAmit MohantyRank #112 · 20K reputationPosted Aug 17, 2023, 8:31 AM EDT
To fix this issue, you need to create the event handler method
MainForm_MouseWheelin yourMainFormclass.using System; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; namespace Image_Viewer { public partial class MainForm : Form { public MainForm() { InitializeComponent(); this.MouseWheel += new MouseEventHandler(MainForm_MouseWheel); } private void MainForm_MouseWheel(object sender, MouseEventArgs e) { // Your mouse wheel event handling code here } } }