Mehrere Unterschriftenfelder in einer Form

  • VB.NET

Es gibt 6 Antworten in diesem Thema. Der letzte Beitrag () ist von dutschr.

    Mehrere Unterschriftenfelder in einer Form

    Hallo Liebes Forum,

    Ich hab eine Form in der drei PictureBoxen drin sind jede soll ein Feld sein für eine Unterschrift.

    Bei einer PictureBox hab ich das hinbekommen aber mit mehreren kriege ich das nicht richtig hin.
    Hier ist mal mein Code für eine Form mit nur einer PictureBox und einem Löschen Button:

    VB.NET-Quellcode

    1. Public Class Form1
    2. Private MouseD As Boolean
    3. Private Col As Color
    4. Private NewPen As Pen
    5. Private bmp As Bitmap
    6. Private Plist As List(Of Point)
    7. Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
    8. MouseD = True
    9. Plist.Add(New Point(e.X, e.Y))
    10. NewPen = Pens.Black
    11. ' NewPen = New Pen(Col, CSng(ComboBox2.SelectedItem))
    12. End Sub
    13. Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
    14. If MouseD Then
    15. MouseD = False
    16. Using gr = Graphics.FromImage(bmp)
    17. Draw(gr)
    18. gr.Flush()
    19. End Using
    20. Plist.Clear()
    21. PictureBox1.Invalidate()
    22. End If
    23. End Sub
    24. Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
    25. If MouseD Then
    26. Plist.Add(New Point(e.X, e.Y))
    27. PictureBox1.Invalidate()
    28. End If
    29. End Sub
    30. Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
    31. If MouseD Then Draw(e.Graphics)
    32. End Sub
    33. Private Sub Draw(ByVal g As Graphics)
    34. If Plist.Count > 0 Then
    35. Dim bs As Byte() = New Byte(Plist.Count - 1) {}
    36. bs(0) = CByte(System.Drawing.Drawing2D.PathPointType.Start)
    37. For a = 1 To Plist.Count - 1
    38. bs(a) = CByte(System.Drawing.Drawing2D.PathPointType.Line)
    39. g.DrawPath(NewPen, New System.Drawing.Drawing2D.GraphicsPath(Plist.ToArray, bs))
    40. Next
    41. End If
    42. End Sub
    43. Private Function GetColors() As List(Of String)
    44. Dim colors As New List(Of String)()
    45. Dim colorNames As String() = [Enum].GetNames(GetType(KnownColor))
    46. For Each colorName As String In colorNames
    47. Dim knownColor As KnownColor = DirectCast([Enum].Parse(GetType(KnownColor), colorName), KnownColor)
    48. If knownColor > knownColor.Transparent Then
    49. colors.Add(colorName)
    50. End If
    51. Next
    52. Return colors
    53. End Function
    54. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    55. PictureBox1.BackColor = Color.White
    56. bmp = New Bitmap(PictureBox1.Width, PictureBox1.Height)
    57. PictureBox1.Image = bmp
    58. Plist = New List(Of Point)
    59. Me.DoubleBuffered = True
    60. For Each c As String In GetColors()
    61. ComboBox1.Items.Add(c)
    62. Next
    63. For a = 1 To 25
    64. ComboBox2.Items.Add(a.ToString)
    65. Next
    66. ComboBox1.SelectedItem = ComboBox1.Items(0)
    67. ComboBox2.SelectedItem = ComboBox2.Items(0)
    68. End Sub
    69. Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
    70. Col = Color.FromName(ComboBox1.SelectedItem)
    71. End Sub
    72. Private Sub Button1_Click(ByVal sender As System.Object, _
    73. ByVal e As System.EventArgs) Handles Button1.Click
    74. Using g = Graphics.FromImage(PictureBox1.Image)
    75. g.Clear(Color.White)
    76. End Using
    77. PictureBox1.Invalidate()
    78. End Sub
    79. End Class


    wenn ich den Code für mehrere PictureBoxen schreibe dann funktioniert Garnichts mehr....

    vielen Dank schonmal für die Hilfe und beste Grüße

    dutschr schrieb:

    dann funktioniert Garnichts mehr....
    Wie äußeert sich das?
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    also wenn ich da erstmal eine zweite picturebox einfüge und die Mouse Aktivitäten für die zweite Picturebox anpasse kann ich zwar malen aber der strich bleibt nicht erhalten
    und wenn eine zweite picturebox da ist kann ich den Inhalt der ersten nicht mehr löschen mit dem button....
    Nicht

    dutschr schrieb:

    VB.NET-Quellcode

    1. Graphics.FromImage(PictureBox1.Image)
    sondern nutze das Paint-Event! ==> GDI
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    @dutschr: Jede PictureBox hat ihr eigenes Paint-Event, Du kannst sie natürlich auch zusammenfassen:

    VB.NET-Quellcode

    1. Private Sub PictureBox1_Paint(sender As System.Object, e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint, PictureBox2.Paint, PictureBox3.Paint
    2. Dim g = e.Graphics
    3. If sender Is PictureBox1 Then
    4. g.Clear(Color.Black)
    5. ElseIf sender Is PictureBox2 Then
    6. g.Clear(Color.Red)
    7. ElseIf sender Is PictureBox3 Then
    8. g.Clear(Color.Gold)
    9. End If
    10. End Sub
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!