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

时间:2016-05-02 02:15:59

标签: vba userform

以下代码给我一个错误。是否可以在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")

1 个答案:

答案 0 :(得分:0)

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

有关详细信息,请参阅:How to Use the TabStrip Control in a UserForm

这里:How to Use the MultiPage Control in a UserForm是有关Multipage的信息。它是控件的容器,页面有自己的控件,所以也许这就是你要找的东西。

如何使用Tabstrip控件根据所选Tab键更改NewFrame的颜色。 (使用示例使用名为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 的命令按钮创建新用户表单) HTH

python test.py | aplay