I'm a noob to the .net world and I was wondering how I would go about creating a rich text box by triggering a click event button. I am trying to shrink the data currently in my form. One way of doing this would be to take away the two rich text boxes I have drag/dropped into the form and just adding a button. When the button is clicked, a rich text box will pop up. Any guidance will be greatly appreciated.

Dani AI

Generated

If the goal is to keep the main form compact, create the editor only when needed and either host it in a small popup or reuse a single instance instead of leaving two drag-dropped controls on the form. 's answer shows the basic dynamic-creation idea; below are practical patterns, event/cleanup notes, and small examples you can apply immediately for 's scenario.

A modal editor (keeps the main UI tiny): create a lightweight Form that contains a RichTextBox docked to fill, show it with ShowDialog, then read rtb.Rtf or rtb.Text after the dialog closes.

Dim editor As New Form With {.Text = "Editor", .Size = New Size(600, 400)}
Dim rtb As New RichTextBox With {.Dock = DockStyle.Fill, .AcceptsTab = True}
editor.Controls.Add(rtb)
If editor.ShowDialog() = DialogResult.OK Then
    Dim content As String = rtb.Rtf   ' or rtb.Text
End If

Reuse a single dynamic control if you want a modeless popup or an embedded panel—create once, AddHandler for events, then show/hide or move it rather than re-creating each click. Remove handlers and Dispose when you truly no longer need it.

Private editorRtb As RichTextBox

Sub ShowOrCreateEditor(hostPanel As Panel)
    If editorRtb Is Nothing Then
        editorRtb = New RichTextBox With {.Dock = DockStyle.Fill}
        AddHandler editorRtb.TextChanged, AddressOf OnEditorTextChanged
        hostPanel.Controls.Add(editorRtb)
    End If
    editorRtb.Visible = True
End Sub

Quick tips: prefer rtb.Rtf for formatted text, SaveFile/LoadFile for persistence, call RemoveHandler then Dispose to avoid leaks, and use DockStyle.Fill or a FlowLayoutPanel for responsive layout. If loading large documents from a background thread, marshal updates with Invoke. These patterns give a smaller main form while keeping the editor responsive and safe.

do:

Private rtb1 As RichTextBox
Private Sub button1_Click(sender As Object, e As EventArgs)
    rtb1 = New RichTextBox()
    rtb1.Name = "rtb1"
    rtb1.Size = New Size(300, 200)
    'set it
    rtb1.Location = New Point(20, 20)
    'set it
    Me.Controls.Add(rtb1)
End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.