CodeMonkey
CodeMonkey

Reputation: 12424

Visual Studio keeps deleting code in form.designers

I'm making a winform application. I'm trying to add a keydown event to a combo box so I prepared the event implementation and then I added inside the form.designers document the line:

this.cmboxSearchPath.KeyDown += cmboxSearchPath_KeyDown;

for some reason this line always get deleted from the document.. do you know why and how can I stop it from being deleted?

Upvotes: 4

Views: 2545

Answers (2)

Reed Copsey
Reed Copsey

Reputation: 564451

for some reason this line always get deleted from the document.. do you know why and how can I stop it from being deleted?

Don't put it in the designer generated code. You can include this in your constructor after the InitializeComponent() call, or allow the designer to generate this for you by wiring up the event via the designer itself.

Upvotes: 4

Habib
Habib

Reputation: 223277

Its not a good idea to modify the desginer.cs file. Attach the event in the form designer or you can attach the event in the code behind (form.cs). It is probably disappearing if you are loading the form in the designer and you are getting the message to ignore changes and reload design.

Upvotes: 0

Related Questions