I have a keyup
event that I want to remove from my C# Winform:
private void txtInputBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Return)
{
cmdSend.PerformClick();
}
}
If I comment out or delete this function I get an error in the design view of the form:
"The designer cannot process unknown name 'txtInputBox_KeyDown' at line 66. The code within the method 'InitializeComponent' is generated by the designer and should not be manually modified. Please remove any changes and try opening the designer again."
The program also will not compile.
It happens if I try to delete any event handler code on my form. I am teaching myself C# from my background in VB.NET and in VB.NET I could remove event handler code without issue.
thats because in C#, the functions are added to the events programatically by the designer, when you add it in the designer.
In the solution explorer window, Expand Form1.cs
and open the Form1.Designer.cs
file there:
then locate the function :
private void InitializeComponent()
and delete the line that registers your event handler to the event. it will have a +=
operator in the middle like this:
your event will be located at line 66 and will look like this:
this.txtInputBox.KeyDown += new System.EventHandler(this.txtInputBox_KeyDown);