c# - differentiate F2 keypress on active TAB -


i have complex winform. using many tabs decrease complexity there small problem dont know how solve.

lets have winform screen called "example.cs". have many tabs on screen. in each tab, have button called "f2 - save". when user presses f2 button, capture , below

protected override bool processcmdkey(ref message msg, keys keydata) {     if (keydata == (keys.f2))     {         btn_save.performclick();         return true;     }     return base.processcmdkey(ref msg, keydata); } 

how supposed find click event of button user intend trigger, since there many "save buttons" on same winform?

thanks.

if have set of tabbed documents in tabcontrol not mean have have save button every tab. here should have 1 save button , picup active tab upon save button click. able pick object need save tab. can pick active control active tab using property

public somecontroltosave activecontrol {         {         if (tabcontrol.tabpages.count == 0)             return null;         return tabcontrol.selectedtab.controls.oftype<somecontroltosave>().firstordefault();     } } 

also, don't simulate click event work. create method requires job , call code behind. should use method inside event handlers.

i hope helps.


Comments