Question Remove a graphical object!!

atr232000

Member
Joined
Jan 9, 2010
Messages
17
Programming Experience
Beginner
Hi

I was wondering if any of you clever people can help me.

I am writing a app and I have a treeview. This treeview gets populated with parent and children.
I also have a panel and a picturebox with a image in the picturebox.
On top of the picturebox I and writing some Graphical objects.

see code

Dim theG As Graphics = Graphics.FromImage(PictureBox1.Image)
Dim ComputerName As String = ""
Dim UserName As String = ""
Dim NodeIP As String = ""
Dim sqlSearch As SqlCommand = sqlconn.CreateCommand
Dim sqlsubitemSearch As SqlCommand = sqlconn.CreateCommand
sqlSearch.CommandText = "select ******** to make it shorter"
Dim sqlDR As SqlDataReader = sqlSearch.ExecuteReader
While sqlDR.Read
'do stuff with your returned data

ComputerName = (sqlDR.Item("NODE_NAME").ToString)
UserName = (sqlDR.Item("INFO_VALUE").ToString)
NodeIP = sqlDR.Item("Node_IP").ToString

End While
sqlDR.Close()

theG.PageUnit = GraphicsUnit.Millimeter

Dim aFont As New Font("Arial", 10, FontStyle.Regular)

theG.DrawString(ComputerName, aFont, Brushes.Black, 150, 56)
theG.DrawString(UserName, aFont, Brushes.Black, 150, 63)
theG.DrawString(ComputerName, aFont, Brushes.Black, 150, 69)
theG.DrawString(NodeIP, aFont, Brushes.Black, 150, 75)

When Afterselect on the treeview item this code runs.

However when I select another child/node the code runs again whcih is great it write over the top on the previous text.

What is the command or how do I clear/delete/remove the theG.drawStrings from the first AfterSelect from the treeview so the new drwstrings are clear.

I hope this makes some sense.

thanks

Alan
 
You can't. GDI+ Drawing on an Image object is permanent. You should draw on the PictureBox itself instead, because that is inherently transient. You draw on a control on its Paint event. To change the drawing you simply change the data that describes the drawing and Refresh the control. In the Paint event handler you read the data that describes the drawing and draw accordingly.
 
Back
Top