same code in menus and button
-
i have a some lines of code in the button which is providing a functionality of saving data into database.I like to do the same funtionality(saving data into database),what i have to do.,write the same code in menu item ???? or any shortcut way to complete this task.
-
i have a some lines of code in the button which is providing a functionality of saving data into database.I like to do the same funtionality(saving data into database),what i have to do.,write the same code in menu item ???? or any shortcut way to complete this task.
hi, of course you should have this code only once! you can call same handler for button (e.g
btnSave_Click
) from menu handler (miSave_Click
) asvoid miSave_Click(object sender, EventArgs args )
{
btnSave_Click(this, null);
}or you can have method, say
OnSave()
with code for saving and both in menu and button hanlder call this function. David Never forget: "Stay kul and happy" (I.A.)
David's thoughts / dnhsoftware.org / MyHTMLTidy -
i have a some lines of code in the button which is providing a functionality of saving data into database.I like to do the same funtionality(saving data into database),what i have to do.,write the same code in menu item ???? or any shortcut way to complete this task.
You can write a separate method and call it from button and menu events. It's called code centralization (I think). At least I do that.
-
You can write a separate method and call it from button and menu events. It's called code centralization (I think). At least I do that.
WujekSamoZlo wrote: It's called code centralization (I think). I stand corrected. David Never forget: "Stay kul and happy" (I.A.)
David's thoughts / dnhsoftware.org / MyHTMLTidy