Guest makai Posted November 27, 2002 Posted November 27, 2002 what might be the equivalent of the VB6 AutoRedraw = True (on a form)? Quote
*Gurus* Derek Stone Posted November 28, 2002 *Gurus* Posted November 28, 2002 There isn't an equivalent. Just redraw what needs redrawing in the control's/form's Paint event. Quote Posting Guidelines
Guest makai Posted November 28, 2002 Posted November 28, 2002 I have spent a whole day trying to do exactly that with no progress the concept seems simple - create a bitmap of the form whenever anything is written to it and then simply copy the bitmap to the form in the Paint event I am not even anywhere close to getting it Quote
wyrd Posted November 28, 2002 Posted November 28, 2002 Paste your forms paint event here in this thread so we can have a look. It would help a lot more if we could see the code ourselves. :) Quote Gamer extraordinaire. Programmer wannabe.
Guest makai Posted November 28, 2002 Posted November 28, 2002 if you minimize and then restore the text is gone - trying the text generated in form activate and the button event 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 Quote
*Gurus* Derek Stone Posted November 28, 2002 *Gurus* Posted November 28, 2002 Call FormPrint in Form1_Paint. Quote Posting Guidelines
Guest makai Posted November 28, 2002 Posted November 28, 2002 no then I have to print everything that I already printed (something that I would not be able to do without restarting the whole program) - I just want to refresh what has already BEEN printed the trick is knowing the graphics methods work in order to copy the form to a bitmap and then copying it back to the form in the paint event apparently there is something to the graphics that does not work in my code Quote
wyrd Posted November 28, 2002 Posted November 28, 2002 I see what you're trying to do (I think). You have to call the Refresh method to trigger the Paint Event... so in your FormPrint method, add this as the last line; Me.Refresh() Quote Gamer extraordinaire. Programmer wannabe.
Guest makai Posted November 29, 2002 Posted November 29, 2002 after 2 days I finally arrived at the solution - as I suspected it is fairly simple application of the Graphics Object 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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.