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
 
 
 
 
 
 
TitleUse a PictureBox's Image property to implement AutoRedraw in VB .NET
DescriptionThis example shows how to use a PictureBox's Image property to implement AutoRedraw in VB .NET. It draws on a Bitmap and then assigns the Bitmap to a PictureBox's Image property.
KeywordsVB .NET, AutoRedraw, PictureBox, Image, Bitmap
CategoriesGraphics
 
When the program starts, it makes a Bitmap object to fit the form. It draws on the Bitmap and then assigns it to a PictureBox's Image property. Visual Basic automatically refreshes the image if it is covered and exposed.
 
Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
    e As System.EventArgs) Handles MyBase.Load
    ' Make a Bitmap to fill the PictureBox.
    Dim wid As Integer = Me.ClientSize.Width
    Dim hgt As Integer = Me.ClientSize.Height
    Dim bm As New Bitmap(wid, hgt)
    Dim gr As Graphics = Graphics.FromImage(bm)

    ' Draw some stuff.
    Dim w, h As Integer
    Dim num As New Random
    For i As Integer = 1 To 100
        w = num.Next(10, 50)
        h = num.Next(10, 50)
        gr.FillEllipse( _
            New SolidBrush(RandomQBColor()), _
            num.Next(0, wid - w), num.Next(0, hgt - h), _
            w, h)
    Next i

    ' Make the image permanent.
    Me.PictureBox1.Image = bm
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated