ColtSeavers
Member
- Joined
 - Aug 18, 2019
 
- Messages
 - 8
 
- Programming Experience
 - Beginner
 
Hallo experts,
i'm a beginner. For learning purposes i craeted some RadioButtons and one GroupBox dynamically.
This is working but i can show only one RadioButton in the GroupBox not all 5?????
Please help me i have got no idea to solve this problem!
	
	
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
	
	
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
Many thanks for your help!!!!
Best regards,
Colt Seavers
	
		
			
		
		
	
				
			i'm a beginner. For learning purposes i craeted some RadioButtons and one GroupBox dynamically.
This is working but i can show only one RadioButton in the GroupBox not all 5?????
Please help me i have got no idea to solve this problem!
			
				VB.NET:
			
		
		
		Option Strict On
Public Class Form1
    Dim Ctrl As ControlService = New ControlService
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim CmdArr(0 To 2) As Control
        Dim TxtArr(0 To 3) As Control
        Dim RdoArr(0 To 4) As Control
        Dim GrpBoxArr(0 To 1) As Control
        Dim RadioNames(0 To 4) As String
        RadioNames(0) = "Holz"
        RadioNames(1) = "Aluminium"
        RadioNames(2) = "Glas"
        RadioNames(3) = "Eisen"
        RadioNames(4) = "Blei"
        CmdArr(0) = Ctrl.SetButton("CmdFunction", "Function", 350, 100, 30, 100)
        CmdArr(1) = Ctrl.SetButton("CmdSub", "Sub", 350, 180, 30, 100)
        CmdArr(2) = Ctrl.SetButton("CmdSubByRef", "Sub (ByRef)", 325, 260, 30, 150)
        TxtArr(0) = Ctrl.SetTextBox("TxtDurchmesser", " ", 20, 55, 80, 180, True)
        TxtArr(1) = Ctrl.SetTextBox("TxtErgebnisFunction", " ", 600, 100, 80, 200, False)
        TxtArr(2) = Ctrl.SetTextBox("TxtErgebnisSub", " ", 600, 180, 80, 200, False)
        TxtArr(3) = Ctrl.SetTextBox("TxtErgebnisSubByRef", " ", 600, 260, 80, 200, False)
        RdoArr(0) = Ctrl.SetRadioButton("Rdo" & String.Concat(RadioNames(0)), RadioNames(0), 40, 40, 40, 80, GrpBoxArr(0))
        RdoArr(1) = Ctrl.SetRadioButton("Rdo" & String.Concat(RadioNames(1)), RadioNames(1), 40, 60, 40, 80, GrpBoxArr(0))
      
        GrpBoxArr(0) = Ctrl.SetGroupBox("GrpMaterial", "Material", 20, 100, 280, 150, 1, RdoArr(1))
        GrpBoxArr(0) = Ctrl.SetGroupBox("GrpMaterial", "Material", 20, 100, 280, 150, 1, RdoArr(1))
        'CtrlArr(8) = Ctrl.SetLabel("LblDurchmesser", "Durchmesser in (cm)", 15, 25, 50, 250)
        For Each i As Control In CmdArr
            Me.Controls.Add(i)
        Next
        For Each i As Control In TxtArr
            Me.Controls.Add(i)
        Next
        For Each i As Control In GrpBoxArr
            Me.Controls.Add(i)
        Next
    End Sub
End Class
	
			
				VB.NET:
			
		
		
		Imports System.ComponentModel
Imports System.Windows.Forms.Control
Public Class ControlService
#Region "BUTTON"
    Public Function SetButton(pName As String, pText As String, pLeft As Integer, pTop As Integer,
                                                    pHeight As Integer, pWidth As Integer) As Control
        Dim CmdButton = New Button
        With CmdButton
            .Name = pName
            .Text = pText
            .Left = pLeft
            .Top = pTop
            .Height = pHeight
            .Width = pWidth
        End With
        'AddHandler CmdButton.Click, AddressOf CmdButton_Click
        Return CmdButton
    End Function
#End Region
#Region "TEXTBOX"
    Public Function SetTextBox(pName As String, pText As String, pLeft As Integer, pTop As Integer,
                         pHeight As Integer, pWidth As Integer, pEnabled As Boolean) As Control
        Dim TxtBox = New TextBox
        With TxtBox
            .Name = pName
            .Text = pText
            .Left = pLeft
            .Top = pTop
            .Height = pHeight
            .Width = pWidth
            .Enabled = pEnabled
        End With
        Return TxtBox
    End Function
#End Region
#Region "GROUPBOX"
    Public Function SetGroupBox(pName As String, pText As String, pLeft As Integer, pTop As Integer,
                         pHeight As Integer, pWidth As Integer, pBorderSyle As Integer, pControl As Control) As Control
        Dim GrpBox = New GroupBox
        With GrpBox
            .Parent = Form1
            .Name = pName
            .Text = pText
            .Left = pLeft
            .Top = pTop
            .Height = pHeight
            .Width = pWidth
            .Controls.Add(pControl)
        End With
        Return GrpBox
    End Function
#End Region
#Region "LABEL"
    Public Function SetLabel(pName As String, pText As String, pLeft As Integer, pTop As Integer,
                         pHeight As Integer, pWidth As Integer) As Control
        Dim LblField = New Label
        With LblField
            .Name = pName
            .Text = pText
            .Left = pLeft
            .Top = pTop
            .Height = pHeight
            .Width = pWidth
        End With
        Return LblField
    End Function
#End Region
#Region "RADIOBUTTON"
    Public Function SetRadioButton(pName As String, pText As String, pLeft As Integer, pTop As Integer,
                         pHeight As Integer, pWidth As Integer, pParent As Control) As Control
        Dim RdoButton = New RadioButton
        With RdoButton
            .Parent = pParent
            .Name = pName
            .Text = pText
            .Left = pLeft
            .Top = pTop
            .Height = pHeight
            .Width = pWidth
        End With
        Return RdoButton
    End Function
#End Region
#Region "EVENTS"
    Sub CmdButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        'Form1.TxtBox.Text = "Test"
    End Sub
#End Region
End Class
	Best regards,
Colt Seavers