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 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
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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
by: Overseer |
last post by:
What is the best way to draw graphics like Task Manager's Performance
Graphic??
|
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...
|
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...
|
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...
|
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,...
|
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$) {
}
...
|
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...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
| |