Page 1 of 1

How to draw a thick arrow in picturebox

Posted: Mon Oct 14, 2013 11:31 am
by polas
Hello I have here a problem with drawing on the picture.
Draw a picture on well but it's drawing a thin line and I need a thicker thickness of at least 4.5.

But I'd like to draw arrow and not line.

Need a simple arrows with no gradient and a much smaller and thinner.
Approximately 4.5 thickness used on the image.

Here's an example of what I need.

Image

how do i do that ?


So far, I have only this code.
Here is the code:

Code: Select all
  Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
        If _Previous IsNot Nothing Then
            If PictureBox1.Image Is Nothing Then
                Dim bmp As New Bitmap(PictureBox1.Width, PictureBox1.Height)
                Using g As Graphics = Graphics.FromImage(bmp)
                    g.Clear(Color.White)
                End Using
                PictureBox1.Image = bmp
            End If
            Using g As Graphics = Graphics.FromImage(PictureBox1.Image)
                g.DrawLine(Pens.Red, _Previous.Value, e.Location)
            End Using
            PictureBox1.Invalidate()
            _Previous = e.Location
        End If
    End Sub
 
    Private _Previous As System.Nullable(Of Point) = Nothing
    Private Sub pictureBox1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles PictureBox1.MouseDown
        _Previous = e.Location
        PictureBox1_MouseMove(sender, e)
    End Sub

Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
        _Previous = Nothing
    End Sub

Any help would benefit me.

Re: How to draw a thick arrow in picturebox in vb.net

Posted: Mon Oct 14, 2013 2:14 pm
by Dummy1912
Hello,

you can use this to draw a arrow
This will draw a arrow on the picturebox
Code: Select all
Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
b = New Bitmap(PictureBox1.Image)
e.Graphics. = Graphics.FromImage(b)
e.Graphics.DrawLine(Pens.Yellow, 100, 10, 110, 20)
e.Graphics.DrawLine(Pens.Yellow, 110, 20, 100, 30)
e.Graphics.DrawLine(Pens.Yellow, 90, 20, 110, 20)
PictureBox1.Image = b
e.Graphics.Dispose()
End Sub

Re: How to draw a thick arrow in picturebox

Posted: Mon Oct 14, 2013 5:02 pm
by polas
How to use it cuz b is not declarated

Re: How to draw a thick arrow in picturebox

Posted: Mon Oct 14, 2013 7:10 pm
by Filip
Try adding following code in first line after sub declatation:
Code: Select all
Dim b as Bitmap
I haven't been programming VB in a while now but I think this should work

Hope it helps!
-Filip

Re: How to draw a thick arrow in picturebox

Posted: Tue Oct 15, 2013 5:25 pm
by polas
still got error

e.Graphics. = Graphics.FromImage(b)

Re: How to draw a thick arrow in picturebox

Posted: Tue Oct 15, 2013 7:02 pm
by Filip
Can you paste the error which are you getting?

Re: How to draw a thick arrow in picturebox

Posted: Wed Oct 16, 2013 10:02 am
by polas
Here is where the error is
Code: Select all
e.Graphics. = Graphics.FromImage(b)

Re: How to draw a thick arrow in picturebox

Posted: Sat Oct 19, 2013 4:31 pm
by mandai
You can use this code to draw the arrow by mouse click:
Code: Select all
    Dim g As Graphics

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

        PictureBox1.Image = New Bitmap(PictureBox1.Width, PictureBox1.Height)

        g = Graphics.FromImage(PictureBox1.Image)

    End Sub

    Sub drawArrow(ByVal location As PointF, ByVal scale As Single)

        Dim points(8 - 1) As PointF

        points(0) = location
        points(1) = New PointF(location.X + (scale * 2), location.Y - (scale * 1.5))
        points(2) = New PointF(points(1).X, points(1).Y + scale)
        points(3) = New PointF(points(2).X + (scale * 2), points(2).Y)
        points(4) = New PointF(points(3).X, points(3).Y + scale)
        points(5) = New PointF(points(4).X - (scale * 2), points(4).Y)
        points(6) = New PointF(points(5).X, points(5).Y + scale)
        points(7) = location

        Dim pathTypes(points.Length - 1) As Byte
        For i As Integer = 0 To pathTypes.Length - 1
            pathTypes(i) = Drawing2D.PathPointType.Line
        Next

        Dim gp As Drawing2D.GraphicsPath = New Drawing2D.GraphicsPath(points, pathTypes)

        g.FillPath(Brushes.Red, gp)

    End Sub

    Private Sub PictureBox1_MouseUp(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp

        Dim location As PointF = New PointF(e.X, e.Y)
        Dim scale As Single = 30

        drawArrow(location, scale)

        PictureBox1.Refresh()

    End Sub
The scale can also be adjusted.