How to draw a thick arrow in picturebox

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
8 posts Page 1 of 1
Contributors
User avatar
polas
New Member
New Member
Posts: 13
Joined: Sun Dec 20, 2009 6:32 pm

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.
User avatar
Dummy1912
VIP - Donator
VIP - Donator
Posts: 1969
Joined: Sat Aug 21, 2010 2:17 pm

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
visit us on:


http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
User avatar
polas
New Member
New Member
Posts: 13
Joined: Sun Dec 20, 2009 6:32 pm

How to use it cuz b is not declarated
Filip
Coding Guru
Coding Guru
Posts: 833
Joined: Wed Jan 05, 2011 3:59 pm

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
CodenStuff wrote:
Nope, it's just your sick and dirty mind. You sick twisted warped little pervo :D
User avatar
polas
New Member
New Member
Posts: 13
Joined: Sun Dec 20, 2009 6:32 pm

still got error

e.Graphics. = Graphics.FromImage(b)
Filip
Coding Guru
Coding Guru
Posts: 833
Joined: Wed Jan 05, 2011 3:59 pm

Can you paste the error which are you getting?
CodenStuff wrote:
Nope, it's just your sick and dirty mind. You sick twisted warped little pervo :D
User avatar
polas
New Member
New Member
Posts: 13
Joined: Sun Dec 20, 2009 6:32 pm

Here is where the error is
Code: Select all
e.Graphics. = Graphics.FromImage(b)
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

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.
8 posts Page 1 of 1
Return to “Coding Help & Support”