473,763 Members | 6,638 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[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.jp g"

Private Sub btnShowAll_Clic k(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles btnShowAll.Clic k

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

Public Sub RGSShowAll(ByVa l PicBox As PictureBox)
Dim g As Graphics = Graphics.FromIm age(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.Dra wLine(bzrPen, X1, Y1, X1, Y2)
objGrpahics.Dra wLine(bzrPen, X1, Y1, X2, Y1)
objGrpahics.Dra wLine(bzrPen, X2, Y2, X2, Y1)
objGrpahics.Dra wString("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 10339

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

Robby

"kalp suth via DotNetMonster.c om" <fo***@DotNetMo nster.com> wrote in message
news:13******** *************** *******@DotNetM onster.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.jp g"

Private Sub btnShowAll_Clic k(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnShowAll.Clic k

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

Public Sub RGSShowAll(ByVa l PicBox As PictureBox)
Dim g As Graphics = Graphics.FromIm age(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.Dra wLine(bzrPen, X1, Y1, X1, Y2)
objGrpahics.Dra wLine(bzrPen, X1, Y1, X2, Y1)
objGrpahics.Dra wLine(bzrPen, X2, Y2, X2, Y1)
objGrpahics.Dra wString("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(PictureB ox1.Image)
g = Graphics.FromIm age(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.Ima ge = b
g.Dispose()

hth Peter

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

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

Robby

"kalp suth via DotNetMonster.c om" <fo***@DotNetMo nster.com> wrote in message news:13******** *************** *******@DotNetM onster.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.jp g"

Private Sub btnShowAll_Clic k(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnShowAll.Clic k

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

Public Sub RGSShowAll(ByVa l PicBox As PictureBox)
Dim g As Graphics = Graphics.FromIm age(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.Dra wLine(bzrPen, X1, Y1, X1, Y2)
objGrpahics.Dra wLine(bzrPen, X1, Y1, X2, Y1)
objGrpahics.Dra wLine(bzrPen, X2, Y2, X2, Y1)
objGrpahics.Dra wString("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
2386
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 graphics object of the form/pictureBox. Should It be better if make a graphics object from my pictureBox in load event handler of the form and store it as member variable of the form , make
5
2538
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 file? I've looked at Bitmap objects, which support saving, but can't see a way to grab what I have drawn and make a bitmap from it, or whatever. Anybody done this? Thanks for any suggestions
2
2534
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 graphical form): icon1 <----------> icon2 Then the user can drag icon1 around the page and the arrow will still be "connected" to to both. How would you go about doing something like that?
2
4225
by: Overseer | last post by:
What is the best way to draw graphics like Task Manager's Performance Graphic??
3
1547
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 reasons for that, which I won't go into. Anyway, there has always been one tiny bug that has annoyed me - the code that draws the initial graphic image into PictureBox1 will only work if wire it up to a button, it doesn't actually do anything if...
11
6730
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 put these (x,y,w,h) to an array? Later go back the array and fill ellipse with the same color as background? Is there an easy way?
4
2444
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 event handler - making it a static display. But I don't want a static display - I want to draw dynamic data so how do I get the data to the event handler - if I need to do that. I have also done line drawings on the Form but those drawings have an...
0
9387
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10148
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10002
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8822
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2794
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.