如何将 TabControl 转换为 .NET 中的向导样式? [英] How to convert TabControl into wizard style in .NET?

查看:28
本文介绍了如何将 TabControl 转换为 .NET 中的向导样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的表单采用向导样式,因此我使用 TabControl 将向导的页面作为我的 TabPages.有一些小问题需要更正,例如使选项卡在运行时显示.我继承了 TabControl 并添加了一个名为TabsVisible"的属性并更正了它.它工作得很好.(请参阅:http://dotnetrix.co.uk/tabcontrol.htm - 添加 HideTabs属性来打开/关闭 Tabitem)

I want to have my form in a wizard style and so I used TabControl to have the pages of the Wizard as my TabPages. There were small issues to be corrected, such as, making the tabs being displayed in runtime. I inherited the TabControl and I added a property called "TabsVisible" and corrected it. It worked fine. (See : http://dotnetrix.co.uk/tabcontrol.htm - Add a HideTabs property to turn on/off the Tabitems)

但是还有其他一些小问题,例如:1. 当按下 Ctrl + Tab 时,选项卡会发生变化.这是通过覆盖 OnKeyDown 方法禁用的2. 当活动光标在标签列表中时,如果按下方向键,当前标签页就会改变.我怎样才能禁用这个??

But there are other small issues like : 1. When Ctrl + Tab is pressed the tabs get changed. This is disabled by overriding the OnKeyDown method 2. When the active cursor is in the tab list, and if Arrow keys are pressed, the current tab page gets changed. How can I disable this??

所以我的问题是 - 如何禁用 tabControl 中的箭头键以便标签页不会被更改?

So my question is - How can disable Arrow keys in tabControl so that the tab page doesn't get changed?

推荐答案

我做了以下.如果所选选项卡正在从代码中更改,则有一个标志.如果是这样,我允许它,否则它是不允许的.以下代码对我来说效果很好.

I did it the following. Had a flag if the selected tab was being changed from the code. If so I allowed it or else it is disallowed. The following code worked fine for me.

    Private _selectedTabBeingChangedFromCode As Boolean

    Private Function IsDesignMode() As Boolean
        Return Me.Site IsNot Nothing AndAlso Me.Site.DesignMode = True
    End Function

    Public Shadows Property SelectedTab() As System.Windows.Forms.TabPage
        Get
            Return MyBase.SelectedTab
        End Get
        Set(ByVal value As System.Windows.Forms.TabPage)
            _selectedTabBeingChangedFromCode = True
            MyBase.SelectedTab = value
            _selectedTabBeingChangedFromCode = False
        End Set
    End Property

    Private Sub WizardTabControl_Selecting(ByVal sender As Object, ByVal e As System.Windows.Forms.TabControlCancelEventArgs) Handles Me.Selecting
        If IsDesignMode() Then
            Return
        End If

        If _selectedTabBeingChangedFromCode = False Then
            e.Cancel = True
        End If
    End Sub

这篇关于如何将 TabControl 转换为 .NET 中的向导样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆