简体   繁体   中英

Default visual studio always create event handlers in the same file - Form1.cs, how to change location?

I'm just wondering if anyone had annoying default automatic event handler function creating. For example, I'm creating button event automatically, by double click on event tab (lightning tab) for double click event - visual studio automatically generates event handler in Form1.cs file. But if I want to move this event handler to another file (but in the same object and same namespace), let's say called ButtonEvents.cs (partial Form1 class), visual studio automatically generates another empty event handler in Form1.cs file. Visual studio doesn't understand, that event handler already exists, but when compiling, it send error, so every time I have to delete these default event handlers - this is very annoying....

Thank You Guys.

You can set every method you want to handling events of your control. for example:

Button1.Click += new EventHandler(AnotherClass.GreetingBtn_Click);

If you want when you double click on your button editor shows AnotherClass.GreetingBtn_Click method, try to change event handler of your button in YourForm.Designer file (I'm not sure about it).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM