9 个解决方案
#1
建议你用SStab控件,比TabStrip好用
引用system32/TABCTL32.OCX
引用system32/TABCTL32.OCX
#2
你就使用sstab控件…!它使作起来比较方便…!!
可以有多种方式调整…!!
你可以在工具箱旧击右键--->部件--->然后选取"Microsoft tabbed dialog control 6.0 就行了…!
可以有多种方式调整…!!
你可以在工具箱旧击右键--->部件--->然后选取"Microsoft tabbed dialog control 6.0 就行了…!
#3
MSDN里这方面的例子,找找看
#4
就用sstab吧.
#5
TabStrip 例子 (一)
===============================================================
VERSION 5.00
Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.2#0"; "comctl32.ocx"
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 2760
ClientLeft = 1635
ClientTop = 1545
ClientWidth = 3420
LinkTopic = "Form1"
ScaleHeight = 2760
ScaleWidth = 3420
Begin VB.Frame ChoiceFrame
BorderStyle = 0 'None
Height = 1695
Index = 1
Left = 1800
TabIndex = 2
Top = 1560
Width = 2655
Begin VB.OptionButton DogsOption
Caption = "Bohdi"
Height = 255
Index = 3
Left = 240
TabIndex = 11
Top = 1200
Width = 975
End
Begin VB.OptionButton DogsOption
Caption = "Mahto"
Height = 255
Index = 2
Left = 240
TabIndex = 10
Top = 840
Width = 975
End
Begin VB.OptionButton DogsOption
Caption = "Veda"
Height = 255
Index = 1
Left = 240
TabIndex = 9
Top = 480
Width = 975
End
Begin VB.OptionButton DogsOption
Caption = "Snortimer"
Height = 255
Index = 0
Left = 240
TabIndex = 8
Top = 120
Value = -1 'True
Width = 975
End
End
Begin VB.Frame ChoiceFrame
BorderStyle = 0 'None
Height = 1695
Index = 2
Left = 1080
TabIndex = 3
Top = 1080
Width = 2655
Begin VB.OptionButton PoepleOption
Caption = "Darcy"
Height = 255
Index = 3
Left = 240
TabIndex = 7
Top = 1200
Width = 1095
End
Begin VB.OptionButton PoepleOption
Caption = "Julia"
Height = 255
Index = 2
Left = 240
TabIndex = 6
Top = 840
Width = 1095
End
Begin VB.OptionButton PoepleOption
Caption = "Michelle"
Height = 255
Index = 1
Left = 240
TabIndex = 5
Top = 480
Width = 1095
End
Begin VB.OptionButton PoepleOption
Caption = "Rod"
Height = 255
Index = 0
Left = 240
TabIndex = 4
Top = 120
Value = -1 'True
Width = 1095
End
End
Begin VB.Frame ChoiceFrame
BorderStyle = 0 'None
Height = 1695
Index = 0
Left = 360
TabIndex = 1
Top = 600
Width = 2655
Begin VB.OptionButton CatsOption
Caption = "Corky"
Height = 255
Index = 2
Left = 240
TabIndex = 14
Top = 840
Width = 1335
End
Begin VB.OptionButton CatsOption
Caption = "Cobe"
Height = 255
Index = 1
Left = 240
TabIndex = 13
Top = 480
Width = 1335
End
Begin VB.OptionButton CatsOption
Caption = "Merlin"
Height = 255
Index = 0
Left = 240
TabIndex = 12
Top = 120
Value = -1 'True
Width = 1335
End
End
Begin ComctlLib.TabStrip TabStrip1
Height = 2175
Left = 240
TabIndex = 0
Top = 240
Width = 2895
_ExtentX = 5106
_ExtentY = 3836
_Version = 327682
BeginProperty Tabs {0713E432-850A-101B-AFC0-4210102A8DA7}
NumTabs = 3
BeginProperty Tab1 {0713F341-850A-101B-AFC0-4210102A8DA7}
Caption = "&Cats"
Object.Tag = ""
ImageVarType = 2
EndProperty
BeginProperty Tab2 {0713F341-850A-101B-AFC0-4210102A8DA7}
Caption = "&Dogs"
Object.Tag = ""
ImageVarType = 2
EndProperty
BeginProperty Tab3 {0713F341-850A-101B-AFC0-4210102A8DA7}
Caption = "&People"
Object.Tag = ""
ImageVarType = 2
EndProperty
EndProperty
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
' Note that the TabStrip numbers tabs starting
' with 1 not 0.
' The index of the selected frame.
Private SelectedTab As Integer
Private Sub Form_Load()
Dim i As Integer
' Move all the frames to the same position
' and make them all invisible.
For i = 1 To ChoiceFrame.UBound
ChoiceFrame(i).Move _
ChoiceFrame(0).Left, _
ChoiceFrame(0).Top, _
ChoiceFrame(0).Width, _
ChoiceFrame(0).Height
ChoiceFrame(i).Visible = False
Next i
' Select the first tab.
SelectedTab = 1
TabStrip1.SelectedItem = TabStrip1.Tabs(SelectedTab)
ChoiceFrame(SelectedTab - 1).Visible = True
End Sub
Private Sub TabStrip1_Click()
ChoiceFrame(SelectedTab - 1).Visible = False
SelectedTab = TabStrip1.SelectedItem.Index
ChoiceFrame(SelectedTab - 1).Visible = True
End Sub
===============================================================
VERSION 5.00
Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.2#0"; "comctl32.ocx"
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 2760
ClientLeft = 1635
ClientTop = 1545
ClientWidth = 3420
LinkTopic = "Form1"
ScaleHeight = 2760
ScaleWidth = 3420
Begin VB.Frame ChoiceFrame
BorderStyle = 0 'None
Height = 1695
Index = 1
Left = 1800
TabIndex = 2
Top = 1560
Width = 2655
Begin VB.OptionButton DogsOption
Caption = "Bohdi"
Height = 255
Index = 3
Left = 240
TabIndex = 11
Top = 1200
Width = 975
End
Begin VB.OptionButton DogsOption
Caption = "Mahto"
Height = 255
Index = 2
Left = 240
TabIndex = 10
Top = 840
Width = 975
End
Begin VB.OptionButton DogsOption
Caption = "Veda"
Height = 255
Index = 1
Left = 240
TabIndex = 9
Top = 480
Width = 975
End
Begin VB.OptionButton DogsOption
Caption = "Snortimer"
Height = 255
Index = 0
Left = 240
TabIndex = 8
Top = 120
Value = -1 'True
Width = 975
End
End
Begin VB.Frame ChoiceFrame
BorderStyle = 0 'None
Height = 1695
Index = 2
Left = 1080
TabIndex = 3
Top = 1080
Width = 2655
Begin VB.OptionButton PoepleOption
Caption = "Darcy"
Height = 255
Index = 3
Left = 240
TabIndex = 7
Top = 1200
Width = 1095
End
Begin VB.OptionButton PoepleOption
Caption = "Julia"
Height = 255
Index = 2
Left = 240
TabIndex = 6
Top = 840
Width = 1095
End
Begin VB.OptionButton PoepleOption
Caption = "Michelle"
Height = 255
Index = 1
Left = 240
TabIndex = 5
Top = 480
Width = 1095
End
Begin VB.OptionButton PoepleOption
Caption = "Rod"
Height = 255
Index = 0
Left = 240
TabIndex = 4
Top = 120
Value = -1 'True
Width = 1095
End
End
Begin VB.Frame ChoiceFrame
BorderStyle = 0 'None
Height = 1695
Index = 0
Left = 360
TabIndex = 1
Top = 600
Width = 2655
Begin VB.OptionButton CatsOption
Caption = "Corky"
Height = 255
Index = 2
Left = 240
TabIndex = 14
Top = 840
Width = 1335
End
Begin VB.OptionButton CatsOption
Caption = "Cobe"
Height = 255
Index = 1
Left = 240
TabIndex = 13
Top = 480
Width = 1335
End
Begin VB.OptionButton CatsOption
Caption = "Merlin"
Height = 255
Index = 0
Left = 240
TabIndex = 12
Top = 120
Value = -1 'True
Width = 1335
End
End
Begin ComctlLib.TabStrip TabStrip1
Height = 2175
Left = 240
TabIndex = 0
Top = 240
Width = 2895
_ExtentX = 5106
_ExtentY = 3836
_Version = 327682
BeginProperty Tabs {0713E432-850A-101B-AFC0-4210102A8DA7}
NumTabs = 3
BeginProperty Tab1 {0713F341-850A-101B-AFC0-4210102A8DA7}
Caption = "&Cats"
Object.Tag = ""
ImageVarType = 2
EndProperty
BeginProperty Tab2 {0713F341-850A-101B-AFC0-4210102A8DA7}
Caption = "&Dogs"
Object.Tag = ""
ImageVarType = 2
EndProperty
BeginProperty Tab3 {0713F341-850A-101B-AFC0-4210102A8DA7}
Caption = "&People"
Object.Tag = ""
ImageVarType = 2
EndProperty
EndProperty
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
' Note that the TabStrip numbers tabs starting
' with 1 not 0.
' The index of the selected frame.
Private SelectedTab As Integer
Private Sub Form_Load()
Dim i As Integer
' Move all the frames to the same position
' and make them all invisible.
For i = 1 To ChoiceFrame.UBound
ChoiceFrame(i).Move _
ChoiceFrame(0).Left, _
ChoiceFrame(0).Top, _
ChoiceFrame(0).Width, _
ChoiceFrame(0).Height
ChoiceFrame(i).Visible = False
Next i
' Select the first tab.
SelectedTab = 1
TabStrip1.SelectedItem = TabStrip1.Tabs(SelectedTab)
ChoiceFrame(SelectedTab - 1).Visible = True
End Sub
Private Sub TabStrip1_Click()
ChoiceFrame(SelectedTab - 1).Visible = False
SelectedTab = TabStrip1.SelectedItem.Index
ChoiceFrame(SelectedTab - 1).Visible = True
End Sub
#6
TabStrip 例子 (二)
这个例子的 目的是 使用 TabStrip 去管理 Multiple DBGrids.
===============================================================
VERSION 5.00
Object = "{00028C01-0000-0000-0000-000000000046}#1.0#0"; "DBGRID32.OCX"
Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.2#0"; "comctl32.ocx"
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 2985
ClientLeft = 1620
ClientTop = 1545
ClientWidth = 5760
LinkTopic = "Form1"
ScaleHeight = 2985
ScaleWidth = 5760
Begin VB.CommandButton Command1
Caption = "Open"
Height = 495
Left = 2280
TabIndex = 0
Top = 2400
Width = 1215
End
Begin VB.Data Data2
Caption = "Data2"
Connect = "Access"
DatabaseName = ""
DefaultCursorType= 0 'DefaultCursor
DefaultType = 2 'UseODBC
Exclusive = 0 'False
Height = 345
Left = 3120
Options = 0
ReadOnly = 0 'False
RecordsetType = 1 'Dynaset
RecordSource = "SELECT DepartmentName, Manager FROM Departments"
Top = 1800
Visible = 0 'False
Width = 2580
End
Begin VB.Data Data1
Caption = "Data1"
Connect = "Access"
DatabaseName = ""
DefaultCursorType= 0 'DefaultCursor
DefaultType = 2 'UseODBC
Exclusive = 0 'False
Height = 345
Left = 3120
Options = 0
ReadOnly = 0 'False
RecordsetType = 1 'Dynaset
RecordSource = "SELECT Name, Department, Manager FROM Employees, Departments WHERE Employees.Department = Departments.DepartmentName"
Top = 1440
Visible = 0 'False
Width = 2580
End
Begin VB.Frame ChoiceFrame
BorderStyle = 0 'None
Height = 1815
Index = 1
Left = 600
TabIndex = 4
Top = 720
Width = 5415
Begin MSDBGrid.DBGrid DataGrid
Bindings = "Form1.frx":0000
Height = 1695
Index = 1
Left = 0
OleObjectBlob = "Form1.frx":0010
TabIndex = 5
Top = 0
Width = 5295
End
End
Begin VB.Frame ChoiceFrame
BorderStyle = 0 'None
Height = 1695
Index = 0
Left = 240
TabIndex = 2
Top = 480
Width = 5295
Begin MSDBGrid.DBGrid DataGrid
Bindings = "Form1.frx":09E7
Height = 1695
Index = 0
Left = 0
OleObjectBlob = "Form1.frx":09F7
TabIndex = 3
Top = 0
Width = 5295
End
End
Begin ComctlLib.TabStrip TabStrip1
Height = 2175
Left = 120
TabIndex = 1
Top = 120
Width = 5535
_ExtentX = 9763
_ExtentY = 3836
_Version = 327682
BeginProperty Tabs {0713E432-850A-101B-AFC0-4210102A8DA7}
NumTabs = 2
BeginProperty Tab1 {0713F341-850A-101B-AFC0-4210102A8DA7}
Caption = "Employees"
Object.Tag = ""
ImageVarType = 2
EndProperty
BeginProperty Tab2 {0713F341-850A-101B-AFC0-4210102A8DA7}
Caption = "Departments"
Object.Tag = ""
ImageVarType = 2
EndProperty
EndProperty
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private SelectedTab As Integer
Private Sub Command1_Click()
Select Case SelectedTab
Case 1
MsgBox "Open Employee form."
Case 2
MsgBox "Open Department form."
End Select
End Sub
Private Sub DataGrid_RowColChange(Index As Integer, LastRow As Variant, ByVal LastCol As Integer)
With DataGrid(Index).SelBookmarks
' Deselect current selections.
Do While .Count > 0
.Remove 0
Loop
' Select the active row.
.Add DataGrid(Index).RowBookmark(DataGrid(Index).Row)
End With
End Sub
Private Sub Form_Load()
Const MARGIN = 30
Dim i As Integer
Dim wid As Single
Dim hgt As Single
Data1.DatabaseName = App.Path & "\CoData.mdb"
Data2.DatabaseName = App.Path & "\CoData.mdb"
' Move all the frames to the same position,
' make them all invisible and the same size.
For i = 1 To ChoiceFrame.UBound
ChoiceFrame(i).Move _
ChoiceFrame(0).Left, _
ChoiceFrame(0).Top, _
ChoiceFrame(0).Width, _
ChoiceFrame(0).Height
ChoiceFrame(i).Visible = False
Next i
' Select the first tab.
SelectedTab = 1
TabStrip1.SelectedItem = TabStrip1.Tabs(SelectedTab)
ChoiceFrame(SelectedTab - 1).Visible = True
End Sub
Private Sub TabStrip1_Click()
ChoiceFrame(SelectedTab - 1).Visible = False
SelectedTab = TabStrip1.SelectedItem.Index
ChoiceFrame(SelectedTab - 1).Visible = True
End Sub
这个例子的 目的是 使用 TabStrip 去管理 Multiple DBGrids.
===============================================================
VERSION 5.00
Object = "{00028C01-0000-0000-0000-000000000046}#1.0#0"; "DBGRID32.OCX"
Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.2#0"; "comctl32.ocx"
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 2985
ClientLeft = 1620
ClientTop = 1545
ClientWidth = 5760
LinkTopic = "Form1"
ScaleHeight = 2985
ScaleWidth = 5760
Begin VB.CommandButton Command1
Caption = "Open"
Height = 495
Left = 2280
TabIndex = 0
Top = 2400
Width = 1215
End
Begin VB.Data Data2
Caption = "Data2"
Connect = "Access"
DatabaseName = ""
DefaultCursorType= 0 'DefaultCursor
DefaultType = 2 'UseODBC
Exclusive = 0 'False
Height = 345
Left = 3120
Options = 0
ReadOnly = 0 'False
RecordsetType = 1 'Dynaset
RecordSource = "SELECT DepartmentName, Manager FROM Departments"
Top = 1800
Visible = 0 'False
Width = 2580
End
Begin VB.Data Data1
Caption = "Data1"
Connect = "Access"
DatabaseName = ""
DefaultCursorType= 0 'DefaultCursor
DefaultType = 2 'UseODBC
Exclusive = 0 'False
Height = 345
Left = 3120
Options = 0
ReadOnly = 0 'False
RecordsetType = 1 'Dynaset
RecordSource = "SELECT Name, Department, Manager FROM Employees, Departments WHERE Employees.Department = Departments.DepartmentName"
Top = 1440
Visible = 0 'False
Width = 2580
End
Begin VB.Frame ChoiceFrame
BorderStyle = 0 'None
Height = 1815
Index = 1
Left = 600
TabIndex = 4
Top = 720
Width = 5415
Begin MSDBGrid.DBGrid DataGrid
Bindings = "Form1.frx":0000
Height = 1695
Index = 1
Left = 0
OleObjectBlob = "Form1.frx":0010
TabIndex = 5
Top = 0
Width = 5295
End
End
Begin VB.Frame ChoiceFrame
BorderStyle = 0 'None
Height = 1695
Index = 0
Left = 240
TabIndex = 2
Top = 480
Width = 5295
Begin MSDBGrid.DBGrid DataGrid
Bindings = "Form1.frx":09E7
Height = 1695
Index = 0
Left = 0
OleObjectBlob = "Form1.frx":09F7
TabIndex = 3
Top = 0
Width = 5295
End
End
Begin ComctlLib.TabStrip TabStrip1
Height = 2175
Left = 120
TabIndex = 1
Top = 120
Width = 5535
_ExtentX = 9763
_ExtentY = 3836
_Version = 327682
BeginProperty Tabs {0713E432-850A-101B-AFC0-4210102A8DA7}
NumTabs = 2
BeginProperty Tab1 {0713F341-850A-101B-AFC0-4210102A8DA7}
Caption = "Employees"
Object.Tag = ""
ImageVarType = 2
EndProperty
BeginProperty Tab2 {0713F341-850A-101B-AFC0-4210102A8DA7}
Caption = "Departments"
Object.Tag = ""
ImageVarType = 2
EndProperty
EndProperty
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private SelectedTab As Integer
Private Sub Command1_Click()
Select Case SelectedTab
Case 1
MsgBox "Open Employee form."
Case 2
MsgBox "Open Department form."
End Select
End Sub
Private Sub DataGrid_RowColChange(Index As Integer, LastRow As Variant, ByVal LastCol As Integer)
With DataGrid(Index).SelBookmarks
' Deselect current selections.
Do While .Count > 0
.Remove 0
Loop
' Select the active row.
.Add DataGrid(Index).RowBookmark(DataGrid(Index).Row)
End With
End Sub
Private Sub Form_Load()
Const MARGIN = 30
Dim i As Integer
Dim wid As Single
Dim hgt As Single
Data1.DatabaseName = App.Path & "\CoData.mdb"
Data2.DatabaseName = App.Path & "\CoData.mdb"
' Move all the frames to the same position,
' make them all invisible and the same size.
For i = 1 To ChoiceFrame.UBound
ChoiceFrame(i).Move _
ChoiceFrame(0).Left, _
ChoiceFrame(0).Top, _
ChoiceFrame(0).Width, _
ChoiceFrame(0).Height
ChoiceFrame(i).Visible = False
Next i
' Select the first tab.
SelectedTab = 1
TabStrip1.SelectedItem = TabStrip1.Tabs(SelectedTab)
ChoiceFrame(SelectedTab - 1).Visible = True
End Sub
Private Sub TabStrip1_Click()
ChoiceFrame(SelectedTab - 1).Visible = False
SelectedTab = TabStrip1.SelectedItem.Index
ChoiceFrame(SelectedTab - 1).Visible = True
End Sub
#7
各位大佬都吓死人了,我想贴子主人的意思没想这么复杂
label控件应放在frame上,然后利用TabStrip的CLICK事件,判定是哪一个INDEX被单击,然后将对应的"FRAME" ZORDER 0就好了。
例:
如你的TABSTRIP共有N个选项,哪就生成FRAME1(0) FRAME1(N-1)共N个FRAME
在FORM的load 事件中用以下代码将各FRAME移到TABSTRIP上,并改变到合适大小
For i = 0 To Frame1.Count - 1
With Frame1(i)
.Move Tabrtf.ClientLeft, Tabrtf.ClientTop,Tabrtf.ClientWidth,Tabrtf.ClientHeight
End With
Next i
在Tabrtf_Click()事件中用以下代码,达到控制目的
Frame1(Tabrtf.SelectedItem.Index - 1).ZOrder 0
Select Case Tabrtf.SelectedItem.Index
Case 1
...
Case 2
...
END SELECT
label控件应放在frame上,然后利用TabStrip的CLICK事件,判定是哪一个INDEX被单击,然后将对应的"FRAME" ZORDER 0就好了。
例:
如你的TABSTRIP共有N个选项,哪就生成FRAME1(0) FRAME1(N-1)共N个FRAME
在FORM的load 事件中用以下代码将各FRAME移到TABSTRIP上,并改变到合适大小
For i = 0 To Frame1.Count - 1
With Frame1(i)
.Move Tabrtf.ClientLeft, Tabrtf.ClientTop,Tabrtf.ClientWidth,Tabrtf.ClientHeight
End With
Next i
在Tabrtf_Click()事件中用以下代码,达到控制目的
Frame1(Tabrtf.SelectedItem.Index - 1).ZOrder 0
Select Case Tabrtf.SelectedItem.Index
Case 1
...
Case 2
...
END SELECT
#8
我是应帖主要求 帖出代码的.
如果 帖主需要, 这里 还有:
===================================================
Programmatically select a tab in a TabStrip (3K)
http://www.vb-helper.com/HowTo/tabstr2.zip
Use the TabStrip control with frames (3K)
http://www.vb-helper.com/HowTo/tabframe.zip
如果 帖主需要, 这里 还有:
===================================================
Programmatically select a tab in a TabStrip (3K)
http://www.vb-helper.com/HowTo/tabstr2.zip
Use the TabStrip control with frames (3K)
http://www.vb-helper.com/HowTo/tabframe.zip
#9
感谢各位大虾的回复。小弟我是应一个朋友的要求,用VB帮他写一个图书管理系统。我本来无所谓用TabStrip或SSTab的,只不过我刚学VB一个星期,不知道有SSTab控件的。我用了一下,觉得SSTab比较好用一点。因为可以直接在控件上设计界面的。再问个小问题,TabStrip控件不可以直接设计界面的吗?必须要在程序中用代码控制各页的ZOrder才可以的吗?还有,各位大虾有没有关于VB的电子图书,我在网上下载不到(公司的网络有问题)。我还想问一个关于MDI程序的问题,就是MDI的子窗口最大化后,各控件的位置就变的很难看了,怎么样才可以控制控件的位置让他们在最大化的时候比较好看?
#1
建议你用SStab控件,比TabStrip好用
引用system32/TABCTL32.OCX
引用system32/TABCTL32.OCX
#2
你就使用sstab控件…!它使作起来比较方便…!!
可以有多种方式调整…!!
你可以在工具箱旧击右键--->部件--->然后选取"Microsoft tabbed dialog control 6.0 就行了…!
可以有多种方式调整…!!
你可以在工具箱旧击右键--->部件--->然后选取"Microsoft tabbed dialog control 6.0 就行了…!
#3
MSDN里这方面的例子,找找看
#4
就用sstab吧.
#5
TabStrip 例子 (一)
===============================================================
VERSION 5.00
Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.2#0"; "comctl32.ocx"
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 2760
ClientLeft = 1635
ClientTop = 1545
ClientWidth = 3420
LinkTopic = "Form1"
ScaleHeight = 2760
ScaleWidth = 3420
Begin VB.Frame ChoiceFrame
BorderStyle = 0 'None
Height = 1695
Index = 1
Left = 1800
TabIndex = 2
Top = 1560
Width = 2655
Begin VB.OptionButton DogsOption
Caption = "Bohdi"
Height = 255
Index = 3
Left = 240
TabIndex = 11
Top = 1200
Width = 975
End
Begin VB.OptionButton DogsOption
Caption = "Mahto"
Height = 255
Index = 2
Left = 240
TabIndex = 10
Top = 840
Width = 975
End
Begin VB.OptionButton DogsOption
Caption = "Veda"
Height = 255
Index = 1
Left = 240
TabIndex = 9
Top = 480
Width = 975
End
Begin VB.OptionButton DogsOption
Caption = "Snortimer"
Height = 255
Index = 0
Left = 240
TabIndex = 8
Top = 120
Value = -1 'True
Width = 975
End
End
Begin VB.Frame ChoiceFrame
BorderStyle = 0 'None
Height = 1695
Index = 2
Left = 1080
TabIndex = 3
Top = 1080
Width = 2655
Begin VB.OptionButton PoepleOption
Caption = "Darcy"
Height = 255
Index = 3
Left = 240
TabIndex = 7
Top = 1200
Width = 1095
End
Begin VB.OptionButton PoepleOption
Caption = "Julia"
Height = 255
Index = 2
Left = 240
TabIndex = 6
Top = 840
Width = 1095
End
Begin VB.OptionButton PoepleOption
Caption = "Michelle"
Height = 255
Index = 1
Left = 240
TabIndex = 5
Top = 480
Width = 1095
End
Begin VB.OptionButton PoepleOption
Caption = "Rod"
Height = 255
Index = 0
Left = 240
TabIndex = 4
Top = 120
Value = -1 'True
Width = 1095
End
End
Begin VB.Frame ChoiceFrame
BorderStyle = 0 'None
Height = 1695
Index = 0
Left = 360
TabIndex = 1
Top = 600
Width = 2655
Begin VB.OptionButton CatsOption
Caption = "Corky"
Height = 255
Index = 2
Left = 240
TabIndex = 14
Top = 840
Width = 1335
End
Begin VB.OptionButton CatsOption
Caption = "Cobe"
Height = 255
Index = 1
Left = 240
TabIndex = 13
Top = 480
Width = 1335
End
Begin VB.OptionButton CatsOption
Caption = "Merlin"
Height = 255
Index = 0
Left = 240
TabIndex = 12
Top = 120
Value = -1 'True
Width = 1335
End
End
Begin ComctlLib.TabStrip TabStrip1
Height = 2175
Left = 240
TabIndex = 0
Top = 240
Width = 2895
_ExtentX = 5106
_ExtentY = 3836
_Version = 327682
BeginProperty Tabs {0713E432-850A-101B-AFC0-4210102A8DA7}
NumTabs = 3
BeginProperty Tab1 {0713F341-850A-101B-AFC0-4210102A8DA7}
Caption = "&Cats"
Object.Tag = ""
ImageVarType = 2
EndProperty
BeginProperty Tab2 {0713F341-850A-101B-AFC0-4210102A8DA7}
Caption = "&Dogs"
Object.Tag = ""
ImageVarType = 2
EndProperty
BeginProperty Tab3 {0713F341-850A-101B-AFC0-4210102A8DA7}
Caption = "&People"
Object.Tag = ""
ImageVarType = 2
EndProperty
EndProperty
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
' Note that the TabStrip numbers tabs starting
' with 1 not 0.
' The index of the selected frame.
Private SelectedTab As Integer
Private Sub Form_Load()
Dim i As Integer
' Move all the frames to the same position
' and make them all invisible.
For i = 1 To ChoiceFrame.UBound
ChoiceFrame(i).Move _
ChoiceFrame(0).Left, _
ChoiceFrame(0).Top, _
ChoiceFrame(0).Width, _
ChoiceFrame(0).Height
ChoiceFrame(i).Visible = False
Next i
' Select the first tab.
SelectedTab = 1
TabStrip1.SelectedItem = TabStrip1.Tabs(SelectedTab)
ChoiceFrame(SelectedTab - 1).Visible = True
End Sub
Private Sub TabStrip1_Click()
ChoiceFrame(SelectedTab - 1).Visible = False
SelectedTab = TabStrip1.SelectedItem.Index
ChoiceFrame(SelectedTab - 1).Visible = True
End Sub
===============================================================
VERSION 5.00
Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.2#0"; "comctl32.ocx"
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 2760
ClientLeft = 1635
ClientTop = 1545
ClientWidth = 3420
LinkTopic = "Form1"
ScaleHeight = 2760
ScaleWidth = 3420
Begin VB.Frame ChoiceFrame
BorderStyle = 0 'None
Height = 1695
Index = 1
Left = 1800
TabIndex = 2
Top = 1560
Width = 2655
Begin VB.OptionButton DogsOption
Caption = "Bohdi"
Height = 255
Index = 3
Left = 240
TabIndex = 11
Top = 1200
Width = 975
End
Begin VB.OptionButton DogsOption
Caption = "Mahto"
Height = 255
Index = 2
Left = 240
TabIndex = 10
Top = 840
Width = 975
End
Begin VB.OptionButton DogsOption
Caption = "Veda"
Height = 255
Index = 1
Left = 240
TabIndex = 9
Top = 480
Width = 975
End
Begin VB.OptionButton DogsOption
Caption = "Snortimer"
Height = 255
Index = 0
Left = 240
TabIndex = 8
Top = 120
Value = -1 'True
Width = 975
End
End
Begin VB.Frame ChoiceFrame
BorderStyle = 0 'None
Height = 1695
Index = 2
Left = 1080
TabIndex = 3
Top = 1080
Width = 2655
Begin VB.OptionButton PoepleOption
Caption = "Darcy"
Height = 255
Index = 3
Left = 240
TabIndex = 7
Top = 1200
Width = 1095
End
Begin VB.OptionButton PoepleOption
Caption = "Julia"
Height = 255
Index = 2
Left = 240
TabIndex = 6
Top = 840
Width = 1095
End
Begin VB.OptionButton PoepleOption
Caption = "Michelle"
Height = 255
Index = 1
Left = 240
TabIndex = 5
Top = 480
Width = 1095
End
Begin VB.OptionButton PoepleOption
Caption = "Rod"
Height = 255
Index = 0
Left = 240
TabIndex = 4
Top = 120
Value = -1 'True
Width = 1095
End
End
Begin VB.Frame ChoiceFrame
BorderStyle = 0 'None
Height = 1695
Index = 0
Left = 360
TabIndex = 1
Top = 600
Width = 2655
Begin VB.OptionButton CatsOption
Caption = "Corky"
Height = 255
Index = 2
Left = 240
TabIndex = 14
Top = 840
Width = 1335
End
Begin VB.OptionButton CatsOption
Caption = "Cobe"
Height = 255
Index = 1
Left = 240
TabIndex = 13
Top = 480
Width = 1335
End
Begin VB.OptionButton CatsOption
Caption = "Merlin"
Height = 255
Index = 0
Left = 240
TabIndex = 12
Top = 120
Value = -1 'True
Width = 1335
End
End
Begin ComctlLib.TabStrip TabStrip1
Height = 2175
Left = 240
TabIndex = 0
Top = 240
Width = 2895
_ExtentX = 5106
_ExtentY = 3836
_Version = 327682
BeginProperty Tabs {0713E432-850A-101B-AFC0-4210102A8DA7}
NumTabs = 3
BeginProperty Tab1 {0713F341-850A-101B-AFC0-4210102A8DA7}
Caption = "&Cats"
Object.Tag = ""
ImageVarType = 2
EndProperty
BeginProperty Tab2 {0713F341-850A-101B-AFC0-4210102A8DA7}
Caption = "&Dogs"
Object.Tag = ""
ImageVarType = 2
EndProperty
BeginProperty Tab3 {0713F341-850A-101B-AFC0-4210102A8DA7}
Caption = "&People"
Object.Tag = ""
ImageVarType = 2
EndProperty
EndProperty
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
' Note that the TabStrip numbers tabs starting
' with 1 not 0.
' The index of the selected frame.
Private SelectedTab As Integer
Private Sub Form_Load()
Dim i As Integer
' Move all the frames to the same position
' and make them all invisible.
For i = 1 To ChoiceFrame.UBound
ChoiceFrame(i).Move _
ChoiceFrame(0).Left, _
ChoiceFrame(0).Top, _
ChoiceFrame(0).Width, _
ChoiceFrame(0).Height
ChoiceFrame(i).Visible = False
Next i
' Select the first tab.
SelectedTab = 1
TabStrip1.SelectedItem = TabStrip1.Tabs(SelectedTab)
ChoiceFrame(SelectedTab - 1).Visible = True
End Sub
Private Sub TabStrip1_Click()
ChoiceFrame(SelectedTab - 1).Visible = False
SelectedTab = TabStrip1.SelectedItem.Index
ChoiceFrame(SelectedTab - 1).Visible = True
End Sub
#6
TabStrip 例子 (二)
这个例子的 目的是 使用 TabStrip 去管理 Multiple DBGrids.
===============================================================
VERSION 5.00
Object = "{00028C01-0000-0000-0000-000000000046}#1.0#0"; "DBGRID32.OCX"
Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.2#0"; "comctl32.ocx"
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 2985
ClientLeft = 1620
ClientTop = 1545
ClientWidth = 5760
LinkTopic = "Form1"
ScaleHeight = 2985
ScaleWidth = 5760
Begin VB.CommandButton Command1
Caption = "Open"
Height = 495
Left = 2280
TabIndex = 0
Top = 2400
Width = 1215
End
Begin VB.Data Data2
Caption = "Data2"
Connect = "Access"
DatabaseName = ""
DefaultCursorType= 0 'DefaultCursor
DefaultType = 2 'UseODBC
Exclusive = 0 'False
Height = 345
Left = 3120
Options = 0
ReadOnly = 0 'False
RecordsetType = 1 'Dynaset
RecordSource = "SELECT DepartmentName, Manager FROM Departments"
Top = 1800
Visible = 0 'False
Width = 2580
End
Begin VB.Data Data1
Caption = "Data1"
Connect = "Access"
DatabaseName = ""
DefaultCursorType= 0 'DefaultCursor
DefaultType = 2 'UseODBC
Exclusive = 0 'False
Height = 345
Left = 3120
Options = 0
ReadOnly = 0 'False
RecordsetType = 1 'Dynaset
RecordSource = "SELECT Name, Department, Manager FROM Employees, Departments WHERE Employees.Department = Departments.DepartmentName"
Top = 1440
Visible = 0 'False
Width = 2580
End
Begin VB.Frame ChoiceFrame
BorderStyle = 0 'None
Height = 1815
Index = 1
Left = 600
TabIndex = 4
Top = 720
Width = 5415
Begin MSDBGrid.DBGrid DataGrid
Bindings = "Form1.frx":0000
Height = 1695
Index = 1
Left = 0
OleObjectBlob = "Form1.frx":0010
TabIndex = 5
Top = 0
Width = 5295
End
End
Begin VB.Frame ChoiceFrame
BorderStyle = 0 'None
Height = 1695
Index = 0
Left = 240
TabIndex = 2
Top = 480
Width = 5295
Begin MSDBGrid.DBGrid DataGrid
Bindings = "Form1.frx":09E7
Height = 1695
Index = 0
Left = 0
OleObjectBlob = "Form1.frx":09F7
TabIndex = 3
Top = 0
Width = 5295
End
End
Begin ComctlLib.TabStrip TabStrip1
Height = 2175
Left = 120
TabIndex = 1
Top = 120
Width = 5535
_ExtentX = 9763
_ExtentY = 3836
_Version = 327682
BeginProperty Tabs {0713E432-850A-101B-AFC0-4210102A8DA7}
NumTabs = 2
BeginProperty Tab1 {0713F341-850A-101B-AFC0-4210102A8DA7}
Caption = "Employees"
Object.Tag = ""
ImageVarType = 2
EndProperty
BeginProperty Tab2 {0713F341-850A-101B-AFC0-4210102A8DA7}
Caption = "Departments"
Object.Tag = ""
ImageVarType = 2
EndProperty
EndProperty
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private SelectedTab As Integer
Private Sub Command1_Click()
Select Case SelectedTab
Case 1
MsgBox "Open Employee form."
Case 2
MsgBox "Open Department form."
End Select
End Sub
Private Sub DataGrid_RowColChange(Index As Integer, LastRow As Variant, ByVal LastCol As Integer)
With DataGrid(Index).SelBookmarks
' Deselect current selections.
Do While .Count > 0
.Remove 0
Loop
' Select the active row.
.Add DataGrid(Index).RowBookmark(DataGrid(Index).Row)
End With
End Sub
Private Sub Form_Load()
Const MARGIN = 30
Dim i As Integer
Dim wid As Single
Dim hgt As Single
Data1.DatabaseName = App.Path & "\CoData.mdb"
Data2.DatabaseName = App.Path & "\CoData.mdb"
' Move all the frames to the same position,
' make them all invisible and the same size.
For i = 1 To ChoiceFrame.UBound
ChoiceFrame(i).Move _
ChoiceFrame(0).Left, _
ChoiceFrame(0).Top, _
ChoiceFrame(0).Width, _
ChoiceFrame(0).Height
ChoiceFrame(i).Visible = False
Next i
' Select the first tab.
SelectedTab = 1
TabStrip1.SelectedItem = TabStrip1.Tabs(SelectedTab)
ChoiceFrame(SelectedTab - 1).Visible = True
End Sub
Private Sub TabStrip1_Click()
ChoiceFrame(SelectedTab - 1).Visible = False
SelectedTab = TabStrip1.SelectedItem.Index
ChoiceFrame(SelectedTab - 1).Visible = True
End Sub
这个例子的 目的是 使用 TabStrip 去管理 Multiple DBGrids.
===============================================================
VERSION 5.00
Object = "{00028C01-0000-0000-0000-000000000046}#1.0#0"; "DBGRID32.OCX"
Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.2#0"; "comctl32.ocx"
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 2985
ClientLeft = 1620
ClientTop = 1545
ClientWidth = 5760
LinkTopic = "Form1"
ScaleHeight = 2985
ScaleWidth = 5760
Begin VB.CommandButton Command1
Caption = "Open"
Height = 495
Left = 2280
TabIndex = 0
Top = 2400
Width = 1215
End
Begin VB.Data Data2
Caption = "Data2"
Connect = "Access"
DatabaseName = ""
DefaultCursorType= 0 'DefaultCursor
DefaultType = 2 'UseODBC
Exclusive = 0 'False
Height = 345
Left = 3120
Options = 0
ReadOnly = 0 'False
RecordsetType = 1 'Dynaset
RecordSource = "SELECT DepartmentName, Manager FROM Departments"
Top = 1800
Visible = 0 'False
Width = 2580
End
Begin VB.Data Data1
Caption = "Data1"
Connect = "Access"
DatabaseName = ""
DefaultCursorType= 0 'DefaultCursor
DefaultType = 2 'UseODBC
Exclusive = 0 'False
Height = 345
Left = 3120
Options = 0
ReadOnly = 0 'False
RecordsetType = 1 'Dynaset
RecordSource = "SELECT Name, Department, Manager FROM Employees, Departments WHERE Employees.Department = Departments.DepartmentName"
Top = 1440
Visible = 0 'False
Width = 2580
End
Begin VB.Frame ChoiceFrame
BorderStyle = 0 'None
Height = 1815
Index = 1
Left = 600
TabIndex = 4
Top = 720
Width = 5415
Begin MSDBGrid.DBGrid DataGrid
Bindings = "Form1.frx":0000
Height = 1695
Index = 1
Left = 0
OleObjectBlob = "Form1.frx":0010
TabIndex = 5
Top = 0
Width = 5295
End
End
Begin VB.Frame ChoiceFrame
BorderStyle = 0 'None
Height = 1695
Index = 0
Left = 240
TabIndex = 2
Top = 480
Width = 5295
Begin MSDBGrid.DBGrid DataGrid
Bindings = "Form1.frx":09E7
Height = 1695
Index = 0
Left = 0
OleObjectBlob = "Form1.frx":09F7
TabIndex = 3
Top = 0
Width = 5295
End
End
Begin ComctlLib.TabStrip TabStrip1
Height = 2175
Left = 120
TabIndex = 1
Top = 120
Width = 5535
_ExtentX = 9763
_ExtentY = 3836
_Version = 327682
BeginProperty Tabs {0713E432-850A-101B-AFC0-4210102A8DA7}
NumTabs = 2
BeginProperty Tab1 {0713F341-850A-101B-AFC0-4210102A8DA7}
Caption = "Employees"
Object.Tag = ""
ImageVarType = 2
EndProperty
BeginProperty Tab2 {0713F341-850A-101B-AFC0-4210102A8DA7}
Caption = "Departments"
Object.Tag = ""
ImageVarType = 2
EndProperty
EndProperty
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private SelectedTab As Integer
Private Sub Command1_Click()
Select Case SelectedTab
Case 1
MsgBox "Open Employee form."
Case 2
MsgBox "Open Department form."
End Select
End Sub
Private Sub DataGrid_RowColChange(Index As Integer, LastRow As Variant, ByVal LastCol As Integer)
With DataGrid(Index).SelBookmarks
' Deselect current selections.
Do While .Count > 0
.Remove 0
Loop
' Select the active row.
.Add DataGrid(Index).RowBookmark(DataGrid(Index).Row)
End With
End Sub
Private Sub Form_Load()
Const MARGIN = 30
Dim i As Integer
Dim wid As Single
Dim hgt As Single
Data1.DatabaseName = App.Path & "\CoData.mdb"
Data2.DatabaseName = App.Path & "\CoData.mdb"
' Move all the frames to the same position,
' make them all invisible and the same size.
For i = 1 To ChoiceFrame.UBound
ChoiceFrame(i).Move _
ChoiceFrame(0).Left, _
ChoiceFrame(0).Top, _
ChoiceFrame(0).Width, _
ChoiceFrame(0).Height
ChoiceFrame(i).Visible = False
Next i
' Select the first tab.
SelectedTab = 1
TabStrip1.SelectedItem = TabStrip1.Tabs(SelectedTab)
ChoiceFrame(SelectedTab - 1).Visible = True
End Sub
Private Sub TabStrip1_Click()
ChoiceFrame(SelectedTab - 1).Visible = False
SelectedTab = TabStrip1.SelectedItem.Index
ChoiceFrame(SelectedTab - 1).Visible = True
End Sub
#7
各位大佬都吓死人了,我想贴子主人的意思没想这么复杂
label控件应放在frame上,然后利用TabStrip的CLICK事件,判定是哪一个INDEX被单击,然后将对应的"FRAME" ZORDER 0就好了。
例:
如你的TABSTRIP共有N个选项,哪就生成FRAME1(0) FRAME1(N-1)共N个FRAME
在FORM的load 事件中用以下代码将各FRAME移到TABSTRIP上,并改变到合适大小
For i = 0 To Frame1.Count - 1
With Frame1(i)
.Move Tabrtf.ClientLeft, Tabrtf.ClientTop,Tabrtf.ClientWidth,Tabrtf.ClientHeight
End With
Next i
在Tabrtf_Click()事件中用以下代码,达到控制目的
Frame1(Tabrtf.SelectedItem.Index - 1).ZOrder 0
Select Case Tabrtf.SelectedItem.Index
Case 1
...
Case 2
...
END SELECT
label控件应放在frame上,然后利用TabStrip的CLICK事件,判定是哪一个INDEX被单击,然后将对应的"FRAME" ZORDER 0就好了。
例:
如你的TABSTRIP共有N个选项,哪就生成FRAME1(0) FRAME1(N-1)共N个FRAME
在FORM的load 事件中用以下代码将各FRAME移到TABSTRIP上,并改变到合适大小
For i = 0 To Frame1.Count - 1
With Frame1(i)
.Move Tabrtf.ClientLeft, Tabrtf.ClientTop,Tabrtf.ClientWidth,Tabrtf.ClientHeight
End With
Next i
在Tabrtf_Click()事件中用以下代码,达到控制目的
Frame1(Tabrtf.SelectedItem.Index - 1).ZOrder 0
Select Case Tabrtf.SelectedItem.Index
Case 1
...
Case 2
...
END SELECT
#8
我是应帖主要求 帖出代码的.
如果 帖主需要, 这里 还有:
===================================================
Programmatically select a tab in a TabStrip (3K)
http://www.vb-helper.com/HowTo/tabstr2.zip
Use the TabStrip control with frames (3K)
http://www.vb-helper.com/HowTo/tabframe.zip
如果 帖主需要, 这里 还有:
===================================================
Programmatically select a tab in a TabStrip (3K)
http://www.vb-helper.com/HowTo/tabstr2.zip
Use the TabStrip control with frames (3K)
http://www.vb-helper.com/HowTo/tabframe.zip
#9
感谢各位大虾的回复。小弟我是应一个朋友的要求,用VB帮他写一个图书管理系统。我本来无所谓用TabStrip或SSTab的,只不过我刚学VB一个星期,不知道有SSTab控件的。我用了一下,觉得SSTab比较好用一点。因为可以直接在控件上设计界面的。再问个小问题,TabStrip控件不可以直接设计界面的吗?必须要在程序中用代码控制各页的ZOrder才可以的吗?还有,各位大虾有没有关于VB的电子图书,我在网上下载不到(公司的网络有问题)。我还想问一个关于MDI程序的问题,就是MDI的子窗口最大化后,各控件的位置就变的很难看了,怎么样才可以控制控件的位置让他们在最大化的时候比较好看?