Erstellte Textboxen addieren

  • VB.NET

Es gibt 31 Antworten in diesem Thema. Der letzte Beitrag () ist von JamalR3.

    Hier sind mehr Infos zum FlowLayoutPanel. Füg einfach mal eines hinzu und zieh ein paar Controls drauf dann weißt du warum ich dir das empfehle ;)
    Spoiler anzeigen

    VB.NET-Quellcode

    1. Public Class Form1
    2. 'Speicher für die Letzte Verticale PositionPrivate intLetztePositionY As Integer = 0
    3. 'Speicher für die Anzahl der Button aufrufePrivate intAnzahlButtonClicks As Integer = 0
    4. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    5. 'Aufruf +1
    6. intAnzahlButtonClicks += 1
    7. 'Position +25 Pixel
    8. intLetztePositionY += 25
    9.  
    10. 'Erstellt neues TextBox SteuerelementDim textBoxLinks As TextBox = New TextBox()
    11. With textBoxLinks
    12. 'Vergibt einen Namen für das Element.Name = String.Format("TextboxLinks{0}", intAnzahlButtonClicks)
    13. 'Definiert die Größe.Size = New Size(244, 20)
    14. 'Definiert die Position.Location = New Point(25, intLetztePositionY)
    15. End With
    16. 'Fügt es der Form hinzu
    17. Panel2.Controls.Add(textBoxLinks)
    18. 'Erstellt neues TextBox SteuerelementDim textBoxRechts As TextBox = New TextBox()
    19. With textBoxRechts
    20. 'Vergibt einen Namen für das Element.Name = String.Format("TextboxRechts{0}", intAnzahlButtonClicks)
    21. 'Definiert die Größe.Size = New Size(120, 20)
    22. 'Definiert die Position, 5 Pixel Rechts neben der Linken Textbox.Location = New Point(25, intLetztePositionY)
    23. End With
    24. Panel3.Controls.Add(textBoxRechts)
    25.  
    26. 'Erstellt neues Checkbox SteuerelementDim checkbox As CheckBox = New CheckBox()
    27. With checkbox
    28. 'Vergibt einen Namen für das Element.Name = String.Format("Checkbox{0}", intAnzahlButtonClicks)
    29. 'Defniert die Größe.Size = New Size(81, 17)
    30. 'Defniert die Position, 5 pixel links neben der linken textbox.Location = New Point(5, intLetztePositionY)
    31. End With
    32. 'Fügt es der Form hinzu
    33. Panel1.Controls.Add(checkbox)
    34.  
    35. End Sub
    36.  
    37.  
    38.  
    39.  
    40. 'Kosten berechnen
    41. Dim Ergebnis As IntegerPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    42.  
    43. Ergebnis = 0For Each txt As TextBox In Panel3.Controls
    44. Ergebnis += Val(txt.Text)
    45. Next
    46. Label1.Text = Ergebnis
    47.  
    48.  
    49.  
    50. End Sub
    51.  Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    52. For Each che As CheckBox In Panel1.Controls
    53. If che.Checked ThenFor Each txt1 As TextBox In Panel2.Controls
    54. If txt1.Location.Y = che.Location.Y Then
    55. Panel2.Controls.Remove(txt1)
    56. ElseIf txt1.Location.Y > che.Location.Y Then
    57. txt1.Top -= 25 'Ob += oder -= weiß ich nicht sicher
    58. End If
    59. NextFor Each txt2 As TextBox In Panel3.Controls
    60. If txt2.Location.Y = che.Location.Y Then
    61. Panel3.Controls.Remove(txt2)
    62. ElseIf txt2.Location.Y > che.Location.Y Then
    63. txt2.Top -= 25 'Ob += oder -= weiß ich nicht sicher
    64. End If
    65.  
    66. Panel1.Controls.Remove(che)
    67. Ort_für_die_neue_CheckBox -= 25
    68. Ort_für_die_neue_TextBox -= 25
    69. Next
    70.  
    71. End Sub
    72. End Class


    Er unterstreicht es..

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „JamalR3“ ()

    du schreibst jetzt noch zwischen Public Class Form1 und Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click (also sehr weit oben!)

    das hier:

    Dim intAnzahlButtonClicks As Integer = 0
    Dim intLetztePositionY As Integer = 0

    Gruß Einsteiger
    es klappt fast !!!



    noch en paar fehler... checkboxen löschen sich nicht

    mein momentaner code :


    Spoiler anzeigen

    VB.NET-Quellcode

    1. Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.ClickFor Each che As CheckBox In Panel1.Controls
    2. If che.Checked ThenFor Each txt1 As TextBox In Panel2.Controls
    3. If txt1.Location.Y = che.Location.Y Then
    4. Panel2.Controls.Remove(txt1)
    5. ElseIf txt1.Location.Y > che.Location.Y Then
    6. txt1.Top -= 25 'Ob += oder -= weiß ich nicht sicher
    7. End If
    8. NextFor Each txt2 As TextBox In Panel3.Controls
    9. If txt2.Location.Y = che.Location.Y Then
    10. Panel3.Controls.Remove(txt2)
    11. ElseIf txt2.Location.Y > che.Location.Y Then
    12. txt2.Top -= 25 'Ob += oder -= weiß ich nicht sicher
    13. End If
    14. Next
    15. ' For Each che1 As CheckBox In Panel1.Controls
    16. ' If che1.Location.Y = che.Location.Y Then
    17. 'Panel1.Controls.Remove(che1)
    18. ' ElseIf che1.Location.Y > che.Location.Y Then
    19. ' che1.Top -= 25 'Ob += oder -= weiß ich nicht sicher
    20. intLetztePositionY -= 25
    21. End If
    22. ' Next
    23. ' Panel1.Controls.Remove(che)
    24.  
    25. Next
    26.  
    27.  End Sub
    nach den Änderungen müssts gehen:

    VB.NET-Quellcode

    1. Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    2. For Each che As CheckBox In Panel1.Controls
    3. If che.Checked Then
    4. For Each txt1 As TextBox In Panel2.Controls
    5. If txt1.Location.Y = che.Location.Y Then
    6. Panel2.Controls.Remove(txt1)
    7. ElseIf txt1.Location.Y > che.Location.Y Then
    8. txt1.Top -= 25 'Ob += oder -= weiß ich nicht sicher
    9. End If
    10. NextFor Each txt2 As TextBox In Panel3.Controls
    11. If txt2.Location.Y = che.Location.Y Then
    12. Panel3.Controls.Remove(txt2)
    13. ElseIf txt2.Location.Y > che.Location.Y Then
    14. txt2.Top -= 25 'Ob += oder -= weiß ich nicht sicher
    15. End If
    16. Next
    17. intLetztePositionY -= 25
    18. Panel1.Controls.Remove(che)
    19. End If
    20.  
    21. Next
    22.  
    23.  End Sub


    Hoffentlich stimmts jetzt endlich man

    Gruß Einsteiger