Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleDraw lines on a picture and erase them
Keywordspicture, SavePicture, erase, Cls
CategoriesGraphics
 
When a program draws on a PictureBox, the control's Image property contains the image the PictureBox uses to redisplay itself (for example, if it gets covered by another window and then exposed). The Picture property stores the PictureBox's permanent value. After drawing text, lines, or other stuff on the picture, the program can make it permanent by setting the Picture property equal to the Image property.

When you call a PictureBox's Cls method, it resets its image to the value stored in the Picture property. That means you can draw temporary lines on the picture and erase them by calling Cls.

To make the lines permanent, set the Picture property equal to the Image property.

Use this program's Load Picture button to load a picture. Click and drag to scribble on the picture. Click the picCats.Cls button to erase the scribbles and restore the picture.

Click the "picCats.Picture = picCats.Image" button to make the scribbles permanent. Then scribble some more and click the picCats.Cls button to remove the more recent scribbles.

Use the Clear button to clear the picture completely.

 
' Load the picture.
Private Sub cmdLoadPicture_Click()
    picCats.Picture = LoadPicture(m_FilePath & "cats.jpg")
End Sub

' Clear any non-saved lines.
Private Sub cmdCls_Click()
    picCats.Cls
End Sub

' Make the current image permanent.
Private Sub cmdSaveImage_Click()
    picCats.Picture = picCats.Image
End Sub

' Clear the control's image completely.
Private Sub cmdClear_Click()
    picCats.Picture = LoadPicture()
End Sub
 
For more information on graphics programming in Visual Basic, see my book Visual Basic Graphics Programming.
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated