add buttons mit Controls.Add

  • VB.NET

Es gibt 2 Antworten in diesem Thema. Der letzte Beitrag () ist von gomanza.

    add buttons mit Controls.Add

    Hi leutz,

    habe lange versucht mehrere Buttons mit Control.Add(Button()) in meine Form zu holen. Ganz kurz was ich vorhabe:
    Ich möchte mehrere Panels (gleich aufgebaut) mit den gleichen Buttons,checkboxen dynamisch in meine Form holen, die Anzahl hängt von einer Db ab.Ich habe hier mal ganz einfach 2solcher panels veruscht anzuzeigen. (ne ganz einfache version). Das problem das ich habe ist, dass er mir den Inhalt des ersten panels, das ich hinzufüge super anzeigt, nur nummer 2 ist ohne inhalt, obwohl ich sogar neue buttons mit new erstelle
    Ne Idee woran das liegen könnte?

    VB.NET-Quellcode

    1. Imports System.Windows.Forms
    2. Public Class Form1
    3. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4. CreateMyTabPage()
    5. End Sub
    6. Public Sub CreateMyTabPage()
    7. Dim panel2 As New Panel()
    8. Dim xLabel As Integer = 5
    9. Dim yLabel As Integer = 8
    10. '----------------
    11. panel2.Location = New Point(0, 30)
    12. panel2.Size = New Size(364, 243)
    13. panel2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
    14. Dim location As System.Drawing.Point
    15. location.X = 5
    16. location.Y = 7
    17. Dim buttonPasswdCh As New Button()
    18. Dim buttonDeleteUser As New Button()
    19. Dim panelInside As Panel 'New addUderHelperClass()
    20. panelInside = addUserHelperFunction(buttonPasswdCh, buttonDeleteUser, location.X, location.Y)
    21. panel2.Controls.Add(panelInside)
    22. location.X = 5
    23. location.Y += 102
    24. Dim buttonPasswdCh2 As New Button()
    25. Dim buttonDeleteUser2 As New Button()
    26. Dim panelInside2 As Panel 'New addUderHelperClass()
    27. panelInside2 = addUserHelperFunction(buttonPasswdCh2, buttonDeleteUser2, location.X, location.Y)
    28. panel2.Controls.Add(panelInside2)
    29. location.X = 5
    30. location.Y += 102
    31. 'Me.Controls.Add(buttonPasswdCh)
    32. 'Me.Controls.Add(buttonPasswdCh2)
    33. Me.Controls.Add(panelInside)
    34. Me.Controls.Add(panelInside2)
    35. End Sub
    36. Private Function addUserHelperFunction(ByVal buttonPassWd As Button, ByVal buttonDelUser As Button, ByVal locationX As Integer, ByVal locationY As Integer) As Panel
    37. Dim panelInside As New Panel()
    38. MsgBox(locationX & " " & locationY)
    39. Dim xLabel As Integer = locationX
    40. Dim yLabel As Integer = locationY
    41. panelInside.Location = New Point(0, yLabel)
    42. panelInside.Size = New Size(350, 100)
    43. panelInside.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
    44. buttonPassWd.Location = New System.Drawing.Point(xLabel + 236, yLabel - 4) '(xLabel + 236, yLabel - 2)
    45. buttonPassWd.Size = New System.Drawing.Size(51, 23)
    46. buttonPassWd.Text = "Passwd"
    47. buttonDelUser.Size = New System.Drawing.Size(51, 23)
    48. buttonDelUser.Location = New System.Drawing.Point(xLabel + 290, yLabel - 4)
    49. buttonDelUser.Text = "Delete"
    50. 'AddHandler buttonDelUser.Click, AddressOf buttonDelUser_Click
    51. 'füge buttons hinzu
    52. panelInside.Controls.Add(buttonPassWd)
    53. panelInside.Controls.Add(buttonDelUser)
    54. Return panelInside
    55. End Function
    56. End Class

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „gomanza“ ()