473,387 Members | 1,501 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

[VB.Net/Graphics] Drawing arrows on the picturebox

I want to create arrows using lines on a picture in the picture box.
On clicking the button "btnShowAll", the image is loaded and the lines drawn. "RGSShowAll()" calls "DrawObjs()" which does the actual drawing work.

But after displaying all the arrows in a flick, the arrows disappers.
I have debugged and came to know that the "Paint" event of the picturebox is refreshing the image, so the work done on the CreateGraphics created object is lost!

============== a trimmed-up code from the actual module...=============

Private bzrPen As New Pen(Color.Navy)
Private Location As String = "c:\test.jpg"

Private Sub btnShowAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowAll.Click

pcbMarkupImage.Image = CType(New Bitmap(Location), Image)
RGSShowAll(pcbMarkupImage)
End Sub

Public Sub RGSShowAll(ByVal PicBox As PictureBox)
Dim g As Graphics = Graphics.FromImage(i)

DrawObjs(g)

End Sub

Public Sub DrawObjs(ByRef objGrpahics As Graphics)
Try
Dim I, X1, Y1, X2, Y2 As Integer
' assigned values to the above line coordinates
X1 = 100
Y1 = 200
X2 = 150
Y2 = 300

objGrpahics.DrawLine(bzrPen, X1, Y1, X1, Y2)
objGrpahics.DrawLine(bzrPen, X1, Y1, X2, Y1)
objGrpahics.DrawLine(bzrPen, X2, Y2, X2, Y1)
objGrpahics.DrawString("title1", Me.Font, strBrush, x1 -5 , y1 + 5 )
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
================================================== ==================

--
Message posted via http://www.dotnetmonster.com
Nov 21 '05 #1
2 10310

You must also call your piant routine in the Picturebox.Paint event.

Robby

"kalp suth via DotNetMonster.com" <fo***@DotNetMonster.com> wrote in message
news:13******************************@DotNetMonste r.com...
I want to create arrows using lines on a picture in the picture box.
On clicking the button "btnShowAll", the image is loaded and the lines
drawn. "RGSShowAll()" calls "DrawObjs()" which does the actual drawing
work.

But after displaying all the arrows in a flick, the arrows disappers.
I have debugged and came to know that the "Paint" event of the picturebox
is refreshing the image, so the work done on the CreateGraphics created
object is lost!

============== a trimmed-up code from the actual module...=============

Private bzrPen As New Pen(Color.Navy)
Private Location As String = "c:\test.jpg"

Private Sub btnShowAll_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnShowAll.Click

pcbMarkupImage.Image = CType(New Bitmap(Location), Image)
RGSShowAll(pcbMarkupImage)
End Sub

Public Sub RGSShowAll(ByVal PicBox As PictureBox)
Dim g As Graphics = Graphics.FromImage(i)

DrawObjs(g)

End Sub

Public Sub DrawObjs(ByRef objGrpahics As Graphics)
Try
Dim I, X1, Y1, X2, Y2 As Integer
' assigned values to the above line coordinates
X1 = 100
Y1 = 200
X2 = 150
Y2 = 300

objGrpahics.DrawLine(bzrPen, X1, Y1, X1, Y2)
objGrpahics.DrawLine(bzrPen, X1, Y1, X2, Y1)
objGrpahics.DrawLine(bzrPen, X2, Y2, X2, Y1)
objGrpahics.DrawString("title1", Me.Font, strBrush, x1 -5 , y1 + 5 )
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
================================================== ==================

--
Message posted via http://www.dotnetmonster.com

Nov 21 '05 #2
this piece of code works for me, place it inside a button click event, what
it does is creates a bitmap based on the image in the picturebox, the it
draws the lines on this bitmap and place the new bitmap in the picturebox:

Dim g As Graphics
b = New Bitmap(PictureBox1.Image)
g = Graphics.FromImage(b)
g.DrawLine(Pens.Yellow, 100, 10, 110, 20)
g.DrawLine(Pens.Yellow, 110, 20, 100, 30)
g.DrawLine(Pens.Yellow, 90, 20, 110, 20)
PictureBox1.Image = b
g.Dispose()

hth Peter

"Robby" <ed****@not.my.email.com> wrote in message
news:et**************@TK2MSFTNGP15.phx.gbl...

You must also call your piant routine in the Picturebox.Paint event.

Robby

"kalp suth via DotNetMonster.com" <fo***@DotNetMonster.com> wrote in message news:13******************************@DotNetMonste r.com...
I want to create arrows using lines on a picture in the picture box.
On clicking the button "btnShowAll", the image is loaded and the lines
drawn. "RGSShowAll()" calls "DrawObjs()" which does the actual drawing
work.

But after displaying all the arrows in a flick, the arrows disappers.
I have debugged and came to know that the "Paint" event of the picturebox is refreshing the image, so the work done on the CreateGraphics created
object is lost!

============== a trimmed-up code from the actual module...=============

Private bzrPen As New Pen(Color.Navy)
Private Location As String = "c:\test.jpg"

Private Sub btnShowAll_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnShowAll.Click

pcbMarkupImage.Image = CType(New Bitmap(Location), Image)
RGSShowAll(pcbMarkupImage)
End Sub

Public Sub RGSShowAll(ByVal PicBox As PictureBox)
Dim g As Graphics = Graphics.FromImage(i)

DrawObjs(g)

End Sub

Public Sub DrawObjs(ByRef objGrpahics As Graphics)
Try
Dim I, X1, Y1, X2, Y2 As Integer
' assigned values to the above line coordinates
X1 = 100
Y1 = 200
X2 = 150
Y2 = 300

objGrpahics.DrawLine(bzrPen, X1, Y1, X1, Y2)
objGrpahics.DrawLine(bzrPen, X1, Y1, X2, Y1)
objGrpahics.DrawLine(bzrPen, X2, Y2, X2, Y1)
objGrpahics.DrawString("title1", Me.Font, strBrush, x1 -5 , y1 + 5 )
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
================================================== ==================

--
Message posted via http://www.dotnetmonster.com


Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Sanjay | last post by:
hi, We are currently porting our project from VB6 to VB .NET. Earlier we used to make scale transformations on objects like pictureBox , forms etc.Now Such transformations are made on the...
5
by: Steve Marshall | last post by:
Hi all, I am converting an app which used a picturebox to draw graphs etc onto, then saved them to a file. I can certainly draw things onto a picturbox in VB.NET, but how do I save them to a...
2
by: Notgiven | last post by:
Assuming I find some code that allows you to drag graphics around the page, ideally, I want the relationship between two graphics to be displayed as linked arrows. For example (imagine this in...
2
by: Overseer | last post by:
What is the best way to draw graphics like Task Manager's Performance Graphic??
3
by: Peter Webb | last post by:
When I started my current extremely graphics intensive project, I ignored advice in this ng to use the Paint method, and used the alternate CreateGraphics approach. I thought there were some good...
11
by: Slickuser | last post by:
I have this function that will fill the ellipse every 10 seconds with specific x,y,w,h. Now I want do the the reverse, to clear the ellipse with given x,y using Timer at every 30s. Or I have...
4
by: AWW | last post by:
XP VB 2005 drawing line graphics in a PictureBox - from a simple minded former FORTRAN programmer. The help examples have the graphics drawing code (lines & rectangles) in the PictureBox paint...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.