当网格位于选项卡页上时如何使用 ctrl-TAB 退出网格(当网格不在选项卡页上时 onkeydown 起作用)

发布于 2024-09-03 10:44:58 字数 909 浏览 12 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

那支青花 2024-09-10 10:44:58

我很高兴你问这个问题;-)

通过 TabControl 传递 ctrl-tab :

Public Class MyTabControl
Inherits MicroFour.StrataFrame.UI.Windows.Forms.TabControl

Protected Overrides Sub OnKeyDown(ByVal e As System.Windows.Forms.KeyEventArgs)
If e.KeyCode = Keys.Tab AndAlso e.Control Then
    e.Handled = False
    e.SuppressKeyPress = False
Else
    MyBase.OnKeyDown(e)
End If

End Sub
End Class

根据明智的人的建议,我已将导航代码移至我的基本表单类(在 Ultragrid 中使用 ctrl-Delete 删除单行的代码仍然存在)在网格子类的 onkeydown 中)

Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, _
                                       ByVal keyData As System.Windows.Forms.Keys) _
                                       As Boolean
    '-- check for unique keystrokes
    Select Case keyData
        Case Keys.Control Or Keys.Tab

            '-- created to be able to tab out of a Grid control 
            '-- Unfortunately direct at this point still moot for grids on 
            '-- tabcontrols as I have to set focus() to next control 
            '-- explicitly on leaving groupbox containing grid on tabpage

            Me.SelectNextControl(Me.ActiveControl, True, True, True, True)
        Case Keys.Control Or Keys.Shift Or Keys.Tab
            Me.SelectNextControl(Me.ActiveControl, False, True, True, True)
        Case Keys.Control Or Keys.E

    End Select

    Return MyBase.ProcessCmdKey(msg, keyData)
End Function

我需要显式地将 focus() 设置为包含 Ultragrid 的组框的 Leave 上的下一个控件,因为它似乎忘记了基于表单的 TabOrderController 应该去哪里,但这是一个小问题付出的代价。我希望很快就能将该部分通用化。

将为任何感兴趣的人发布进一步的改进。

I'm glad you asked that question ;-)

To pass the ctrl-tab through the TabControl :

Public Class MyTabControl
Inherits MicroFour.StrataFrame.UI.Windows.Forms.TabControl

Protected Overrides Sub OnKeyDown(ByVal e As System.Windows.Forms.KeyEventArgs)
If e.KeyCode = Keys.Tab AndAlso e.Control Then
    e.Handled = False
    e.SuppressKeyPress = False
Else
    MyBase.OnKeyDown(e)
End If

End Sub
End Class

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)

Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, _
                                       ByVal keyData As System.Windows.Forms.Keys) _
                                       As Boolean
    '-- check for unique keystrokes
    Select Case keyData
        Case Keys.Control Or Keys.Tab

            '-- created to be able to tab out of a Grid control 
            '-- Unfortunately direct at this point still moot for grids on 
            '-- tabcontrols as I have to set focus() to next control 
            '-- explicitly on leaving groupbox containing grid on tabpage

            Me.SelectNextControl(Me.ActiveControl, True, True, True, True)
        Case Keys.Control Or Keys.Shift Or Keys.Tab
            Me.SelectNextControl(Me.ActiveControl, False, True, True, True)
        Case Keys.Control Or Keys.E

    End Select

    Return MyBase.ProcessCmdKey(msg, keyData)
End Function

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文