当网格位于选项卡页上时如何使用 ctrl-TAB 退出网格(当网格不在选项卡页上时 onkeydown 起作用)
winforms .net 3.5 Ultrawingrid 9.2
在我的 Ultrawingrid.Ultragrid 子类中:
Protected Overrides Sub OnKeyDown(ByVal e As System.Windows.Forms.KeyEventArgs)
If e.KeyCode = Windows.Forms.Keys.Tab andalso e.control = True then
SetFocusToNextControl(True)
End if
Mybase.OnKeyDown(e)
End Sub
这工作正常。但是,当将网格放在 TabControl 选项卡页上时,ctrl-tab 看起来与上面的子选项卡非常不同。 e.keycode 被视为 controlkey {17}
我意识到默认情况下 cntrl-Tab 在标签页之间移动。我需要重写这种行为。我的想法是我可能需要 tabControl 的一个子类,它将像表单一样传递组合键,但我承认我对如何实现这一点一无所知。我尝试重写 tabcontrol 子类的 onkeydown ,如果按下 ctrl-tab 组合,则只发出 return 而不是对 onkeydown 的基本调用,但它似乎也将 e.keycode 视为 controlkey 。
FWIW 我尝试了不同的组合,例如 ctrl-E ,得到了几乎相同的结果,焦点从网格中消失,但没有去到我能检测到的任何地方。子系统仍然将 e.control 视为控制键。
奇怪的是,ctrl-X、ctrl-A 等都在网格中工作,并且我放入子类中用于删除行的 ctrl-Delete 组合工作正常。
再次 - 直接在表单上网格,一切正常。
我对这件事绝对是不知所措。非常感谢指导。 vb 或 c# 都可以。
TIA
winforms .net 3.5 Ultrawingrid 9.2
In my subclass of Ultrawingrid.Ultragrid :
Protected Overrides Sub OnKeyDown(ByVal e As System.Windows.Forms.KeyEventArgs)
If e.KeyCode = Windows.Forms.Keys.Tab andalso e.control = True then
SetFocusToNextControl(True)
End if
Mybase.OnKeyDown(e)
End Sub
This works fine. But when the grid is dropped on a TabControl tabpage, the ctrl-tab looks very different to the sub above. e.keycode is seen as controlkey {17}
I realize that by default cntrl-Tab moves between tabpages. I need to override this behavior. My thought is I probably need a subclass of the tabControl which will pass the keycombo through just as the form does but I confess to being clueless as to how to accomplish that. I tried to override the onkeydown of a tabcontrol subclass and just issuing a return and not and base call to onkeydown if the ctrl-tab combo was pressed but it seemed to see the e.keycode as controlkey as well.
FWIW I tried a different combination like ctrl-E and got pretty much the same result with focus disappearing from the grid but not going anywhere I could detect. The sub still saw the e.control as controlkey.
Oddly, ctrl-X, ctrl-A etc all work in the grid and a ctrl-Delete combo I put in the subclass for deleting a row works fine.
Once again - grid directly on form and it all works.
I'm definitely over my head on this one. Guidance much appreciated. vb or c# fine.
TIA
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我很高兴你问这个问题;-)
通过 TabControl 传递 ctrl-tab :
根据明智的人的建议,我已将导航代码移至我的基本表单类(在 Ultragrid 中使用 ctrl-Delete 删除单行的代码仍然存在)在网格子类的 onkeydown 中)
我需要显式地将 focus() 设置为包含 Ultragrid 的组框的 Leave 上的下一个控件,因为它似乎忘记了基于表单的 TabOrderController 应该去哪里,但这是一个小问题付出的代价。我希望很快就能将该部分通用化。
将为任何感兴趣的人发布进一步的改进。
I'm glad you asked that question ;-)
To pass the ctrl-tab through the TabControl :
On the advice of someone wiser I have moved the navigation code to my baseform class (code to delete single row with ctrl-Delete in Ultragrid remains in onkeydown of grid subclass)
I need to explicitly set the focus() to the next control on the Leave of the groupbox containing the Ultragrid as it seems to forget where it is supposed to go based on the form's TabOrderController, but this is a small price to pay. I hope to have that part genericised shortly.
Will post further refinements for anyone interested.