K
kalp suth via DotNetMonster.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
====================================================================
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
====================================================================