c# - TabControl - Autoscroll doesnt work proper -
i have following problem, i'm creating tabcontrol few tabpages, content within tabpages dynamic generated, decided make autoscroll = true. when change on tab, first have press on textbox or checkbox, can scroll, thats annoying. better, when scrollfunction instantly active, when change tab. tried few things, focus, doesnt changed anything.
tabcontrol tc = new tabcontrol(); tc.tabpages.addrange(new tabpage[] { new tabpage("noten 2015"), new tabpage("noten 2014"), new tabpage("history 2013-2010"), new tabpage("sonstiges")}); } (int = 0; <= 3; i++) { tc.tabpages[i].autoscroll = true; }
the complaint vague, won't have trouble operating scrollbars. have guess real problem related mouse wheel. mouse wheel messages sent control has focus. tabcontrol when click tab. doesn't have use scroll message, client tab page implements scrolling.
so workaround looking automatically moving focus control inside tab page right after tab selected. implement event handler selectedindexchanged event:
private void tabcontrol1_selectedindexchanged(object sender, eventargs e) { var page = tabcontrol1.selectedtab; page.selectnextcontrol(page, true, true, true, true); }
it not perfect solution, still won't work correctly when use tab or cursor keys navigate tab control. or if tab page doesn't have controls can receive focus. more universal solution requires more surgery, you'd need forward mouse wheel message tab control active tab page. add new class project , paste code shown below. compile. drag new control top of toolbar onto form, replacing existing one.
using system; using system.windows.forms; class tabcontrolex : tabcontrol { private bool recurse; protected override void wndproc(ref message m) { const int wm_mousewheel = 0x20a; if (!recurse && m.msg == wm_mousewheel && this.selectedtab != null) { recurse = true; sendmessage(this.selectedtab.handle, m.msg, m.wparam, m.lparam); recurse = false; m.result = intptr.zero; return; } base.wndproc(ref m); } [system.runtime.interopservices.dllimport("user32.dll")] private static extern intptr sendmessage(intptr hwnd, int msg, intptr wp, intptr lp); }
Comments
Post a Comment