none
Programmatically Create Groupbox in Windows Forms

    Question

  • Hello Everyone, I'm going to use a button to create groupboxes programatically in windows forms and within the groupbox there is a button where I could add multiple richtextboxes..  Can somebody please guide me into making this feature please?
    Thursday, July 04, 2013 1:59 AM

Answers

  • I'm going to use a button to create groupboxes programatically in windows forms and within the groupbox there is a button where I could add multiple richtextboxes.

    This code will create a groupbox that contains a button.  If you are creating these controls for some particular reason, or with some particular layout in mind, then additional or different code may be required.

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim myGroupBox As New GroupBox
            myGroupBox.Location = New Point(100, 100)
            Me.Controls.Add(myGroupBox)
    
            Dim myNewButton As New Button
            myNewButton.Location = New Point(20, 20)
            myNewButton.Text = "Button"
            myGroupBox.Controls.Add(myNewButton)
    
        End Sub

    Thursday, July 04, 2013 2:14 AM
  • Warning: I HAVE NO EXPERTISE!

    You may need to add event handlers for the button(s) created in the groupbox(s) so that the button(s) can create ritchtextbox(s) in the groupbox(s). And then add event handlers for the richtextbox(s) if they're necessary.

    You probably also need to increment locations, add specific names for controls to distinguish them maybe, add text to controls that use text, etc.

    Public Class Form1
    
        Dim myGroupBox As New GroupBox
    
        Dim myNewButton As New Button
    
        Dim myRichTextBox As New RichTextBox
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.Text = "Testing"
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            myGroupBox.Location = New Point(100, 100)
            myGroupBox.Size = New Size(200, 200)
            myGroupBox.BackColor = Color.PeachPuff
            Me.Controls.Add(myGroupBox)
    
            myNewButton.Location = New Point(20, 20)
            myNewButton.Text = "Button"
            AddHandler myNewButton.Click, AddressOf ClickIt
            myGroupBox.Controls.Add(myNewButton)
        End Sub
    
        Private Sub ClickIt(ByVal sender As System.Object, ByVal e As System.EventArgs)
            myRichTextBox.Location = New Point(20, 60)
            AddHandler myRichTextBox.TextChanged, AddressOf TextChangedAgain
            myGroupBox.Controls.Add(myRichTextBox)
        End Sub
    
        Private Sub TextChangedAgain(ByVal sender As System.Object, ByVal e As System.EventArgs)
            Me.Text = myRichTextBox.Text
        End Sub
    
    End Class


    You've taught me everything I know but not everything you know. _________________________________________________________________________________________________________________ This search engine is for MSDN Library and has many features. http://social.msdn.microsoft.com/Search/en-US?query=search%20msdn%20library&beta=0&ac=8





    Thursday, July 04, 2013 2:24 AM

All replies

  • I'm going to use a button to create groupboxes programatically in windows forms and within the groupbox there is a button where I could add multiple richtextboxes.

    This code will create a groupbox that contains a button.  If you are creating these controls for some particular reason, or with some particular layout in mind, then additional or different code may be required.

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim myGroupBox As New GroupBox
            myGroupBox.Location = New Point(100, 100)
            Me.Controls.Add(myGroupBox)
    
            Dim myNewButton As New Button
            myNewButton.Location = New Point(20, 20)
            myNewButton.Text = "Button"
            myGroupBox.Controls.Add(myNewButton)
    
        End Sub

    Thursday, July 04, 2013 2:14 AM
  • Warning: I HAVE NO EXPERTISE!

    You may need to add event handlers for the button(s) created in the groupbox(s) so that the button(s) can create ritchtextbox(s) in the groupbox(s). And then add event handlers for the richtextbox(s) if they're necessary.

    You probably also need to increment locations, add specific names for controls to distinguish them maybe, add text to controls that use text, etc.

    Public Class Form1
    
        Dim myGroupBox As New GroupBox
    
        Dim myNewButton As New Button
    
        Dim myRichTextBox As New RichTextBox
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.Text = "Testing"
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            myGroupBox.Location = New Point(100, 100)
            myGroupBox.Size = New Size(200, 200)
            myGroupBox.BackColor = Color.PeachPuff
            Me.Controls.Add(myGroupBox)
    
            myNewButton.Location = New Point(20, 20)
            myNewButton.Text = "Button"
            AddHandler myNewButton.Click, AddressOf ClickIt
            myGroupBox.Controls.Add(myNewButton)
        End Sub
    
        Private Sub ClickIt(ByVal sender As System.Object, ByVal e As System.EventArgs)
            myRichTextBox.Location = New Point(20, 60)
            AddHandler myRichTextBox.TextChanged, AddressOf TextChangedAgain
            myGroupBox.Controls.Add(myRichTextBox)
        End Sub
    
        Private Sub TextChangedAgain(ByVal sender As System.Object, ByVal e As System.EventArgs)
            Me.Text = myRichTextBox.Text
        End Sub
    
    End Class


    You've taught me everything I know but not everything you know. _________________________________________________________________________________________________________________ This search engine is for MSDN Library and has many features. http://social.msdn.microsoft.com/Search/en-US?query=search%20msdn%20library&beta=0&ac=8





    Thursday, July 04, 2013 2:24 AM
  • Thank you
    Friday, July 05, 2013 1:53 AM