M
makai
Guest
what might be the equivalent of the VB6 AutoRedraw = True (on a form)?
Public Class Form1
Inherits System.Windows.Forms.Form
Private b1 As Bitmap
Protected Overrides Sub OnActivated(ByVal e As System.EventArgs)
Me.Text = "AutoRedraw Test"
Me.BackColor = System.Drawing.Color.White
FormPrint(".NET Printing", 10, 10)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
FormPrint("2nd Printing", 100, 100)
End Sub
Private Sub FormPrint(ByVal t$, ByVal x1%, ByVal y1%)
Dim g1 As Graphics = Me.CreateGraphics()
System.Windows.Forms.Application.DoEvents()
g1.DrawString(t, New Font("Verdana", 12), _
Brushes.Black, x1, y1)
System.Windows.Forms.Application.DoEvents()
b1 = New Bitmap(Me.Size.Width, Me.Size.Height, g1)
End Sub
' Redraw the form.
Private Sub Form1_Paint( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) _
Handles MyBase.Paint
If Not (b1 Is Nothing) Then e.Graphics.DrawImage(b1, 0, 0)
End Sub
End Class
Option Strict On
Public Class Form1
Inherits System.Windows.Forms.Form
'Bitmap holds picture of the Form
Private b1 As Bitmap
'Graphics object (buffer)
Private g1 As Graphics
Private Sub Form1_Activated(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Activated
Static done As Boolean = False
If Not done Then
Text = "AutoRedraw Test"
BackColor = System.Drawing.Color.White
'Create the initial bitmap from Form
b1 = New Bitmap(Me.Size.Width, _
Me.Size.Height, Me.CreateGraphics())
'Create the Graphics Object buffer
' which ties the bitmap to it so that
' when you draw something on the object
' the bitmap is updated
g1 = Graphics.FromImage(b1)
'Print something
FormPrint(".NET Printing", 10, 10)
'Prevent reentry to initialization
done = True
End If
End Sub
'Print something else
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
FormPrint("2nd Printing", 100, 100)
End Sub
Private Sub FormPrint(ByVal t$, ByVal x1%, ByVal y1%)
'Printing to the graphics buffer (not form)
' updates the associated bitmap b1
g1.DrawString(t, New Font("Verdana", 12), _
Brushes.Black, x1, y1)
'Copy the bitmap to the form
Me.CreateGraphics.DrawImage(b1, 0, 0)
End Sub
Private Sub Form1_Paint( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) _
Handles MyBase.Paint
'Copy the bitmap to the form
e.Graphics.DrawImage(b1, 0, 0)
End Sub
End Class