Go through the following instructions:
1) Create new "Windows application" project
2) Copy code below
3) Paste it between
Public Class Form1 ... End Class
tags
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
CreateTabControlWithRichTextBoxOnEachPage()
End Sub
Private Sub CreateTabControlWithRichTextBoxOnEachPage(Optional ByVal iCountOfPages As Integer = 3)
Dim tc As TabControl = Nothing, tp As TabPage = Nothing, rtb As RichTextBox = Nothing
Dim i As Integer = 0
Try
tc = New TabControl()
With tc
.Parent = Me
.Dock = DockStyle.Fill
End With
For i = 1 To iCountOfPages
tp = New TabPage
With tp
.Name = "TabPage" & i.ToString
.Text = .Name
End With
rtb = New RichTextBox
With rtb
.Parent = tp
.Dock = DockStyle.Fill
.Name = "RichTextBox" & i.ToString
AddHandler rtb.MouseEnter, AddressOf rtb_MouseEnter
AddHandler rtb.MouseLeave, AddressOf rtb_MouseLeave
End With
tc.TabPages.Add(tp)
Next
Me.Refresh()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error...")
Finally
rtb = Nothing
tp = Nothing
tc = Nothing
End Try
End Sub
Private Sub rtb_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseLeave
Me.Text = "MouseEnter event in " & sender.Name
End Sub
Private Sub rtb_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseLeave
Me.Text = "MouseLeave event in " & sender.Name
End Sub
All controls are added in run-time. All working great!
Test it and try to use in your application.
More about events for RichTextBox control:
OnMouseEnter[
^]
OnMouseLeave[
^]