makai
November 28th, 2002, 01:26 PM
Is there a .Net equivalent for AutoRedraw = True?
this is the code that does not work if you minimize the form and restore
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
the theory is simple - create a bitmap of the form with each text write and then copy that bitmap back to the form in the Paint event - evidently I do not understand the graphics methods - can anyone help?
this is the code that does not work if you minimize the form and restore
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
the theory is simple - create a bitmap of the form with each text write and then copy that bitmap back to the form in the Paint event - evidently I do not understand the graphics methods - can anyone help?