Code:
'...
Public Class Mainform
'...
Dim pbArrow As PictureBox = Nothing
'... Private Sub Mainform_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'...
DrawArrow2()
End Sub
Sub DrawArrow2()
If pbArrow IsNot Nothing Then Exit Sub 'Ist PFeil schon da? Dann nicht nochmal ausführen
Const Awidth = 250 'Pfeil-Gesamtlänge
Const Aheight = 76 'Pfeil-Höhe und Länge der Pfeilspitze
Dim Bmp = New Bitmap(Awidth, Aheight)
Dim Point0 As New Point(10, Aheight \ 2 - 8) 'Pos. für Text
'Eckpunkte für Pfeil
Dim Point1 As New Point(Awidth, Aheight \ 2)
Dim Point2 As New Point(Point1.X - Aheight, Point1.Y + Aheight \ 2 - 5)
Dim Point3 As New Point(Point2.X, Point1.Y + Aheight \ 4)
Dim Point4 As New Point(0, Point3.Y)
Dim Point5 As New Point(0, Point1.Y - Aheight \ 4)
Dim Point6 As New Point(Point2.X, Point5.Y)
Dim Point7 As New Point(Point2.X, 5)
Dim curvePoints As PointF() = {Point1, Point2, Point3, Point4, Point5, Point6, Point7}
'PictureBox für PFeil
pbArrow = New PictureBox With {
.Size = New Size(Awidth, Aheight)
}
pbArrow.Location = New Point(Panel1.Location.X + TB1.Location.X - Awidth, Panel1.Location.Y + TB1.Location.Y + TB1.Height \ 2 - pbArrow.Height \ 2)
Dim rect As New Rectangle(pbArrow.Location.X, pbArrow.Location.Y, pbArrow.Location.X + Awidth, pbArrow.Location.Y + Aheight)
Me.DrawToBitmap(Bmp, rect)
Dim g As Graphics = Graphics.FromImage(Bmp)
'pens
Dim penBlue As New Pen(Color.Blue)
Dim penwhite As New Pen(Color.White)
penBlue.Width = 5
penwhite.Width = 7
'font
Dim drawFont As New Font("Arial", 11)
Dim drawFormat As New StringFormat
'brushes
Dim brushRed As New SolidBrush(Color.Red)
Dim brushBlue As New SolidBrush(Color.Blue)
Dim brushYellow As New SolidBrush(Color.Yellow)
g.Clear(Color.Transparent)
g.FillPolygon(brushRed, curvePoints)
g.DrawPolygon(penwhite, curvePoints)
g.DrawPolygon(penBlue, curvePoints)
g.DrawString("Bitte Text eingeben:", drawFont, brushYellow, Point0, drawFormat)
pbArrow.BackColor = Nothing
pbArrow.Image = Bmp
Me.Controls.Add(pbArrow)
pbArrow.BringToFront()
'pbArrow.Dispose() --> passiert in TextChanged, wenn Text nicht leer ist
End Sub
Private Sub TB1_TextChanged(sender As Object, e As EventArgs) Handles TB1.TextChanged, TextBox1.TextChanged
If TB1.Text = "" Then
DrawArrow2()
Else
If pbArrow IsNot Nothing Then pbArrow.Dispose()
pbArrow = Nothing
End If
End Sub