Private Shared Function AddUserTab(Of T As {New, UserControl})(ByVal title As String, ByVal control As TabControl) As TabPage
Dim page As New TabPage(title) With {.Name = GetType(TabPage).Name & control.TabPages.Count.ToString()} 'basic naming
Dim uc As New T() With {.Name = GetType(T).Name & "1"} 'initialize a new instance of the generic type (hence the New() constraint)
uc.Dock = DockStyle.Fill 'fill the whole tab
page.Controls.Add(uc) 'add the UserControl to the page (obviously)
control.TabPages.Add(page) 'finally, add the TabPage to the UserControl.
Return page
End Function
Dim tab As TabPage = AddUserPage(Of <Name_Of_Your_UserControl_Class_Here>)("I like boys", Me.TabControl1)
Private Shared _MainWriter As UserControl
Public Shared Property MainWriter() As Writer
Get
Return _MainWriter
End Get
Set(ByVal value As Writer)
_MainWriter = value
End Set
End Property
Private Sub Open()
' Check()
Dim Odlg As New OpenFileDialog
With Odlg
.Title = "Save"
.Filter = "Text files |*.txt|Richtext files |*.rtf|All files |*.*"
.RestoreDirectory = True
End With
If Odlg.ShowDialog = Windows.Forms.DialogResult.OK Then
Filename = Odlg.FileName
Safefilename = System****.Path.GetFileName(Filename)
Dim ext As String = System****.Path.GetExtension(Odlg.FileName)
ext = ext.ToUpper()
Dim tab As TabPage = AppManager.AddUserTab(Of Writer)("Untitled " & tabnumber, Me.TabControl1)
tabnumber += 1
TabControl1.SelectedTab = tab
Select Case ext
Case ".RTF"
AppManager.MainWriter.MyRichTextBox.LoadFile(Filename)
AppManager.MainWriter.MyRichTextBo*****lectionStart = 0
AppManager.MainWriter.MyRichTextBo*****lectionLength = 0
Case ".TXT"
Dim txtReader As System****.StreamReader
txtReader = New System****.StreamReader(Odlg.FileName)
AppManager.MainWriter.MyRichTextBox.Text = txtReader.ReadToEnd
txtReader.Close()
txtReader = Nothing
AppManager.MainWriter.MyRichTextBo*****lectionStart = 0
AppManager.MainWriter.MyRichTextBo*****lectionLength = 0
Case Else
MessageBox.Show("File type is not supported", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Select
End If