本文介绍了如何在TabControl中隐藏和显示标签页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生,



我想隐藏标签页3号。我使用的是下面的代码,但没有用....



Sir,

I want to hide tab page no 3. I am using below code but not works....

Dim cmd As System.Data.SqlClient.SqlCommand
        Dim dr As System.Data.SqlClient.SqlDataReader
        Dim cn As System.Data.SqlClient.SqlConnection
        Try
            cn = New System.Data.SqlClient.SqlConnection(DBset())
            cn.Open()
            cmd = New System.Data.SqlClient.SqlCommand("Select [BackupPath] from Owner", cn)
            dr = cmd.ExecuteReader
            While dr.Read
                bkp_path = dr(0)
            End While
        Catch ex As Exception
        End Try
        dr.Close()
        cn.Close()
        If bkp_path = "No" Then
            TabPage3.Hide()
        Else
            TabPage3.Show()
        End If





请帮助我............



Please help me............

推荐答案

Public Class MyTabControl
    Inherits TabControl

#Region "DELEGATES_EVENTS"
    Public Event HasError(ByVal sender As Object, ByVal e As EventArgs)
#End Region

#Region "VARS"
    Dim RemoveTabs As List(Of TabPage)
    Dim _lastRemoveException As Exception
#End Region

#Region "CONSTRUCTORS_DESTRUCTORS"
    Public Sub New()
        RemoveTabs = New List(Of TabPage)
    End Sub
#End Region

#Region "SUBS_FUNCS"
    Private Sub OnError(ByVal e As Exception)
        _lastRemoveException = e
        RaiseEvent HasError(Me, EventArgs.Empty)
    End Sub
    Public Function GetLastExcceptio() As Exception
        Return _lastRemoveException
    End Function
    Public Function RemoveCurrentTab(ByVal tp As TabPage) As Boolean
        Dim result As Boolean
        Try
            TabPages.Remove(tp)
            RemoveTabs.Add(tp)
            result = True
        Catch ex As Exception
            OnError(ex)
        End Try
        Return result
    End Function
    Public Function AddTabBack(ByVal title As String) As Boolean
        Dim result As Boolean
        Try
            If Not String.IsNullOrEmpty(title) Then
                For Each tp As TabPage In RemoveTabs
                    If String.Compare(tp.Text, title) = 0 Then
                        RemoveTabs.Remove(tp)
                        TabPages.Add(tp)
                        result = True
                        Exit For
                    End If
                Next
            End If
        Catch ex As Exception
            OnError(ex)
        End Try
        Return result
    End Function
#End Region

#Region "CONTROL_EVENTS"
    Private Sub MyTabControl_DoubleClick(sender As Object, e As EventArgs) Handles Me.DoubleClick
        RemoveCurrentTab(Me.SelectedTab)
    End Sub
#End Region

End Class





regs

ron O。



regs
ron O.


MSDN写道:





该成员对此控件没有意义。



要隐藏TabControl中的选项卡,必须将其从控件的TabPages集合中删除。



来源: []



因此,一些成员建议使用非常难看的解决方案,其中两个TabControl放在同一个表单上TabPages在t之间移动下摆。

注意:我不推荐这个。而不是它,请按照以下链接:

[]

[]


Source: TabPage.Visible Property [^]

So, some members recommend very ugly solution for this, where two TabControls are placed on the same form and TabPages are moved between them.
Note: I do NOT recommend this. Rather then it, follow these links:
Wizards[^]
Wizards: Design Guidelines[^]


这篇关于如何在TabControl中隐藏和显示标签页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 02:16