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:
wenn ich den Code für mehrere PictureBoxen schreibe dann funktioniert Garnichts mehr....
vielen Dank schonmal für die Hilfe und beste Grüße
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
- Public Class Form1
- Private MouseD As Boolean
- Private Col As Color
- Private NewPen As Pen
- Private bmp As Bitmap
- Private Plist As List(Of Point)
- Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
- MouseD = True
- Plist.Add(New Point(e.X, e.Y))
- NewPen = Pens.Black
- ' NewPen = New Pen(Col, CSng(ComboBox2.SelectedItem))
- End Sub
- Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
- If MouseD Then
- MouseD = False
- Using gr = Graphics.FromImage(bmp)
- Draw(gr)
- gr.Flush()
- End Using
- Plist.Clear()
- PictureBox1.Invalidate()
- End If
- End Sub
- Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
- If MouseD Then
- Plist.Add(New Point(e.X, e.Y))
- PictureBox1.Invalidate()
- End If
- End Sub
- Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
- If MouseD Then Draw(e.Graphics)
- End Sub
- Private Sub Draw(ByVal g As Graphics)
- If Plist.Count > 0 Then
- Dim bs As Byte() = New Byte(Plist.Count - 1) {}
- bs(0) = CByte(System.Drawing.Drawing2D.PathPointType.Start)
- For a = 1 To Plist.Count - 1
- bs(a) = CByte(System.Drawing.Drawing2D.PathPointType.Line)
- g.DrawPath(NewPen, New System.Drawing.Drawing2D.GraphicsPath(Plist.ToArray, bs))
- Next
- End If
- End Sub
- Private Function GetColors() As List(Of String)
- Dim colors As New List(Of String)()
- Dim colorNames As String() = [Enum].GetNames(GetType(KnownColor))
- For Each colorName As String In colorNames
- Dim knownColor As KnownColor = DirectCast([Enum].Parse(GetType(KnownColor), colorName), KnownColor)
- If knownColor > knownColor.Transparent Then
- colors.Add(colorName)
- End If
- Next
- Return colors
- End Function
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- PictureBox1.BackColor = Color.White
- bmp = New Bitmap(PictureBox1.Width, PictureBox1.Height)
- PictureBox1.Image = bmp
- Plist = New List(Of Point)
- Me.DoubleBuffered = True
- For Each c As String In GetColors()
- ComboBox1.Items.Add(c)
- Next
- For a = 1 To 25
- ComboBox2.Items.Add(a.ToString)
- Next
- ComboBox1.SelectedItem = ComboBox1.Items(0)
- ComboBox2.SelectedItem = ComboBox2.Items(0)
- End Sub
- Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
- Col = Color.FromName(ComboBox1.SelectedItem)
- End Sub
- Private Sub Button1_Click(ByVal sender As System.Object, _
- ByVal e As System.EventArgs) Handles Button1.Click
- Using g = Graphics.FromImage(PictureBox1.Image)
- g.Clear(Color.White)
- End Using
- PictureBox1.Invalidate()
- End Sub
- 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