c# - How do I prevent a tab from rendering when selected? -


i able have user able run through tabs, setting focus each one, when hit enter, tabpage render.

you think paint event involved, don't know how "cancel out" of it, if job..

first, should caution you're overriding standard windows behavior. in property page dialog or anywhere else uses tabs in user interface, using left , right arrow keys flip through tabs , cause them display contents in tab control. not have press enter selected tab page display. make sure users understand application different (and you understand needs of users) if decide go route.

that said, you can override behavior handling keydown event tabcontrol, detecting when 1 of arrow keys has been pressed, , cancelling it. example:

private void mytabcontrol_keydown(object sender, system.windows.forms.keyeventargs e) {     //check see if arrow key pressed     if ((e.keycode == keys.left) || (e.keycode == keys.right))     {         //cancel keypress indicating handled         e.handled = true;     } } 

however, once this, there no way user set focus particular tab page's tab, because once tab gets focus, tab page brought view. handled parent tabcontrol , unrelated paint event (which responsible how control gets painted, not when or why).

of course, can determine if enter key pressed in same keydown event , activate tab page wish (such using counter variable incremented/ decremented each time corresponding arrow key pressed), there no visible indication user tab brought view. focus rectangle not drawn.

also aware pressing ctrl+tab or ctrl+page up/page down switch between tab pages. if also undesirable, you'll need watch , cancel these key combinations well.
any time start trying override default behaviors, you're in lot more trouble if design application around it. if there's particular reason want require enter key commit tab page switching, might able come easier , better solution.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -