c# - SendKeys.Send function not working -
i want press shift + tab on event , using system.windows.forms.sendkeys.send
purpose not working , tried below ways call function.
system.windows.forms.application.doevents(); sendkeys.send("{+(tab)}"); system.windows.forms.application.doevents(); sendkeys.send("+{tab}"); system.windows.forms.application.doevents(); sendkeys.send("{+}{tab}"); system.windows.forms.application.doevents(); sendkeys.send("+{tab 1}");
can tell me right way ?
the proper syntax is:
sendkeys.send("+{tab}");
in light of comment trying implement pressing shift+tab
cycle between control fields, note can done more reliably without emulating keys. avoids issues where, instance, window has focus.
following method emulate behavior of shift_tab, cycling through tab stops in reverse order:
void emulateshifttab() { // form elements can focused var tabcontrols = this.controls.cast<control>() .where(a => a.canfocus) .orderby(a => a.tabindex); // last control before current focused element var lastcontrol = tabcontrols .takewhile(a => !a.focused) .lastordefault(a => a.tabstop); // if no control or first control on page focused, // select last control on page if (lastcontrol == null) lastcontrol = tabcontrols.lastordefault(); // change focus proper control if (lastcontrol != null) lastcontrol.focus(); }
edit
the deleted text cycle through controls in reverse order (emulating shift+tab), more done with built-in form.selectnextcontrol
method. following method emulate behavior of shift_tab, cycling through tab stops in reverse order.
void emulateshifttab() { this.selectnextcontrol( activecontrol, forward: false, tabstoponly:true, nested: true, wrap:true); }
Comments
Post a Comment