Im actually trying to do something similar, except Im drawing a gradient across the MDI client area. The relevant code:
[VB]
Dim cli as MDIClient
Private Sub Form1_Load(.....)
Dim ctrl as Control
For Each ctrl in Me.Controls
If TypeOf (ctrl) Is MDIClient Then
cli = ctrl
AddHandler cli.Paint, AddressOf cli_Paint
End If
Next
End Sub
Private Sub cli_Paint(ByVal sender as Object, ByVal e as PaintEventArgs)
Dim G as Graphics = e.Graphics
Dim br As New System.Drawing.Drawing2D.LinearGradientBrush(New Point(0, 0), _
New Point(Me.Width, Me.Height), Color.Azure, Color.DarkBlue)
G.FillRectangle(br, e.ClipRectangle)
G.Dispose()
End Sub
[/VB]
My problem is with getting rid of the flicker when the form is resized. Ive tried putting these lines in the forms constructor:
[VB]
SetStyle(ControlStyles.DoubleBuffer, True)
SetStyle(ControlStyles.UserPaint, True)
SetStyle(ControlStyles.AllPaintingInWmPaint, True)
SetStyle(ControlStyles.ResizeRedraw, True)
[/VB]
If I comment out the last line, it doesnt flicker, but it doesnt redraw the gradient for the new client size, either. I thought about adding another handler for cli.Resize, but the Event Argument that gets passed doesnt contain a graphics object.
Does anyone know of a way to get rid of resizing flicker in this situation?