' Draws the bitmaps on the form.
Protected Overrides Sub OnPaint(e As PaintEventArgs)
Dim arialFont As Font
Dim blackBrush As Brush
arialFont = New Font("Arial", 10, FontStyle.Regular)
blackBrush = New SolidBrush(Color.Black)
' Set the size of the sides of the bitmap,
' and get one-third of it for the center bitmap.
Dim sidesize As Integer = 75
Dim third As Integer = CInt(sidesize / 3)
' Create bitmap.
Dim source As Bitmap = CreateBitmap(sidesize)
' Copy entirely as a clone.
Dim clone As Bitmap = CopyBitmap(source)
' Copy the center part of the bitmap.
Dim center As Bitmap = _
CopyBitmap(source, New Rectangle(third, third, third, third))
' Save the bitmap to a file.
clone.Save("newbitmap.bmp", ImageFormat.Bmp)
' Draw the source, clone, and partial
' bitmaps vertically down the screen.
Dim y As Integer = 10
e.Graphics.DrawString("source bitmap:", ArialFont, BlackBrush, 10, y)
y += 20
e.Graphics.DrawImage(source, 10, y)
y += source.Height + 10
e.Graphics.DrawString("clone bitmap:", ArialFont, BlackBrush, 10, y)
y += 20
e.Graphics.DrawImage(clone, 10, y)
y += clone.Height + 10
e.Graphics.DrawString("center part of bitmap:", ArialFont, BlackBrush, 10, y)
y += 20
e.Graphics.DrawImage(center, 10, y)
y += center.Height + 10
' Dispose graphic objects.
arialFont.Dispose()
blackBrush.Dispose()
End Sub