How to Solve Event Hander Nullable Warning Problem

841 views Asked by At
button1.Click += new System.EventHandler(button1_Click);

For this code above the VS gives warning of CS8622 for "button1_Click" in the EventHandler: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/nullable-warnings?f1url=%3FappId%3Droslyn%26k%3Dk(CS8622)

In the VS it says: "Nullability of reference types in type of parameter 'sender' of 'void Form1.Button2_Click(object sender, EventArgs e) doesn't match the target delegate 'EventHandler' (possibly because nullability attributes)".

namespace BirUygulama
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            Button button1 = new Button();
            Font fon = new Font("Corbel", 18, FontStyle.Italic);
            button1.Font = fon;
            Point buttonLoc = new Point();
            buttonLoc.X = 520;
            buttonLoc.Y = 444;
            button1.Location = buttonLoc;
            button1.Size = new Size(100, 85);
            button1.ForeColor = SystemColors.MenuHighlight;
            button1.BackColor = Color.Azure;
            this.Controls.Add(button1);
            button1.Text = "Giriş";
            button1.Click += new System.EventHandler(button1_Click);
        }
    }
}

What does this warning mean and how do I solve this warning? enter image description here

0

There are 0 answers