我们可以在Tabstrip控件中放置一个Frame控件吗



下面的代码给了我一个错误。是否可以在tabstrip控件中创建Frame?如果没有,还有其他选择吗?

    Dim NewFrame As MSForms.Frame
    Dim NewTabStrip As MSForms.TabStrip
    Set NewTabStrip = Controls.Add("Forms.TabStrip.1")
    Set NewFrame = NewTabStrip.Controls.Add("Forms.TabStrip.1")

Tab strip的使用与例如Multi page不同,因为它不是控件的容器,因此代码NewTabstrip.Controls.Add...失败。Tab strip没有任何控件,但它安装了并维护了User form的一组控件。


有关更多信息,请参阅:如何在UserForm 中使用TabStrip控件

这里:如何在UserForm中使用多页控件是关于多页的信息。它是一个控件的容器,页面有自己的控件,所以这可能就是您想要的。


如何使用Tabstrip控件根据所选选项卡更改NewFrame的颜色的示例。(使用名为AddTabstrip的命令按钮创建新用户窗体的示例)HTH

Option Explicit
Private WithEvents NewTabStrip  As TabStrip
Private NewFrame As MSForms.Frame
Private Sub AddTabstrip_Click()
    If Not NewTabStrip Is Nothing Then
        MsgBox "Tabstrip was allready added.", vbExclamation
        Exit Sub
    End If
    Set NewTabStrip = Me.Controls.Add("Forms.TabStrip.1")
    With NewTabStrip
        .Height = Me.Height - 90
        .Width = Me.Width - 30
        .Top = 15
        .Left = 15
    End With
    NewTabStrip.Tabs(0).Caption = "Tab 1"
    NewTabStrip.Tabs(1).Caption = "Tab 2"
    NewTabStrip.Tabs.Add "Tab3", "Tab 3"
    Set NewFrame = Me.Controls.Add("Forms.Frame.1")
    With NewFrame
        .Height = NewTabStrip.Height - 30
        .Width = NewTabStrip.Width - 30
        .Top = NewTabStrip.Top + 20
        .Left = NewTabStrip.Left + 15
    End With
    Call NewTabStripChanged
End Sub
Private Sub NewTabStrip_Change()
   Call NewTabStripChanged
End Sub
Private Sub NewTabStripChanged()
    ' This procedure runs when the TabStrip control named NewTabStrip
    ' changes. This procedure will change the color of the NewFrame
    ' control based on which tab the user selects.
    Dim i As Integer
    i = NewTabStrip.SelectedItem.Index
    Select Case i
        Case 0
            ' First tab selected, change color to red.
            NewFrame.BackColor = RGB(255, 0, 0)
        Case 1
            ' Second tab selected, change color to green.
            NewFrame.BackColor = RGB(0, 255, 0)
        Case 2
            ' Third tab selected, change color to blue.
            NewFrame.BackColor = RGB(0, 0, 255)
    End Select
End Sub

相关内容

  • 没有找到相关文章

最新更新