版权声明:本文为博主原创文章,转载请在显著位置标明本文出处以及作者网名,未经作者允许不得用于商业目的。
本节看看如何用代码增、删选项卡等操作。
增加选项卡:
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim tabpagename As String
tabpagename = InputBox("输入选项卡名称")
Dim newtabpage As New TabPage()
newtabpage.Text = tabpagename
newtabpage.ImageIndex = 1
TabControl1.TabPages.Add(newtabpage)
End Sub
在当前选择的选项卡前面插入新的选项卡:
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
Dim tabpagename As String
tabpagename = InputBox("输入选项卡名称")
Dim newtabpage As New TabPage()
newtabpage.Text = tabpagename
newtabpage.ImageIndex = 0
TabControl1.TabPages.Insert(TabControl1.SelectedIndex, newtabpage)
End Sub
删除当前选择的选项卡:
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
TabControl1.TabPages.RemoveAt(TabControl1.SelectedIndex)
End Sub
清除所有选项卡:
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
TabControl1.TabPages.Clear()
End Sub
在当前选项卡上增加控件:
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
Dim currenttabpage As New TabPage
currenttabpage = TabControl1.SelectedTab
Dim btnControl As New Button
btnControl.Left = 100
btnControl.Top = 50
btnControl.Text = "按钮" & TabControl1.SelectedIndex
currenttabpage.Controls.Add(btnControl)
End Sub
设置选中的选项卡:
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
TabControl1.SelectedIndex = 0 ‘选项卡索引,从0开始
End Sub
运行效果:
由于.net平台下C#和vb.NET很相似,本文也可以为C#爱好者提供参考。
学习更多vb.net知识,请参看vb.net 教程 目录