none
Neue Checkbox aus dem Quellcode heraus erstellen RRS feed

  • Frage

  • Guten Morgen

    ich habe zu diesem thema nichts gefunden, also hab ich mir gedacht ich stell hier einfach die Frage ein.

    Ich möchte auf eine Form neue Checkboxen einfügen. Die Anzahl soll dabei von der Anzahl der Spalten in einem Excelsheet abhängen.

    Ich habe nur keinerlei Ahnung, wie ich eine neue Checkbox aus dem Quellcode heraus auf meine Form platzieren kann. Kann mir jemand sagen wie das geht?

    Merci für jede Antwort.

    Gruß armin
    Montag, 22. Februar 2010 11:02

Antworten

  • Hallo Armin,

    ich habe Dir mal kurz ein kleines Beispiel project zusammengestellt. Erstelle eine neues Win Forms project und ersetze den Form code mit dem untenstehenden code.

    Public Class Form1
        
    Private MyCheckBoxes() As CheckBox
        
    Private iCheckBox As Integer = -1
        
    Private MyButton As Button
        
    Private Sub MyButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
            iCheckBox = iCheckBox + 1
            
    ReDim Preserve MyCheckBoxes(iCheckBox)
            MyCheckBoxes(iCheckBox) = 
    New CheckBox
            MyCheckBoxes(iCheckBox).Location = 
    New Point(20, (iCheckBox + 1) * 20)
            MyCheckBoxes(iCheckBox).Text = 
    "Checkbox Nr." & (iCheckBox + 1).ToString
            
    Me.Controls.Add(MyCheckBoxes(iCheckBox))
        
    End Sub

        Private Sub Form1_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load
            
    Me.Size = New System.Drawing.Size(300, 300)
            MyButton = 
    New Button
            MyButton.AutoSize = 
    True
            MyButton.Text = "New Checkbox"
            MyButton.Location = New Point(184, 12)
            
    Me.Controls.Add(MyButton)
            
    AddHandler MyButton.Click, AddressOf MyButton_Click


        
    End Sub

        Protected Overrides Sub Finalize()
            
    MyBase.Finalize()
            
    RemoveHandler MyButton.Click, AddressOf MyButton_Click
        
    End Sub
    End
     Class


    Hannes

    If you have got questions about this, just ask.
    Mark the thread as answered if the answer helps you. This helps others who have the same problem !
    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/
    Montag, 22. Februar 2010 11:31

Alle Antworten

  • Hallo Armin,

    ich habe Dir mal kurz ein kleines Beispiel project zusammengestellt. Erstelle eine neues Win Forms project und ersetze den Form code mit dem untenstehenden code.

    Public Class Form1
        
    Private MyCheckBoxes() As CheckBox
        
    Private iCheckBox As Integer = -1
        
    Private MyButton As Button
        
    Private Sub MyButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
            iCheckBox = iCheckBox + 1
            
    ReDim Preserve MyCheckBoxes(iCheckBox)
            MyCheckBoxes(iCheckBox) = 
    New CheckBox
            MyCheckBoxes(iCheckBox).Location = 
    New Point(20, (iCheckBox + 1) * 20)
            MyCheckBoxes(iCheckBox).Text = 
    "Checkbox Nr." & (iCheckBox + 1).ToString
            
    Me.Controls.Add(MyCheckBoxes(iCheckBox))
        
    End Sub

        Private Sub Form1_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load
            
    Me.Size = New System.Drawing.Size(300, 300)
            MyButton = 
    New Button
            MyButton.AutoSize = 
    True
            MyButton.Text = "New Checkbox"
            MyButton.Location = New Point(184, 12)
            
    Me.Controls.Add(MyButton)
            
    AddHandler MyButton.Click, AddressOf MyButton_Click


        
    End Sub

        Protected Overrides Sub Finalize()
            
    MyBase.Finalize()
            
    RemoveHandler MyButton.Click, AddressOf MyButton_Click
        
    End Sub
    End
     Class


    Hannes

    If you have got questions about this, just ask.
    Mark the thread as answered if the answer helps you. This helps others who have the same problem !
    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/
    Montag, 22. Februar 2010 11:31
  • merci, das ist die antwort
    Montag, 22. Februar 2010 14:13