Hello,

I am currently using VB 2005 and having a problem I hope that some one
can help me with. Currently in my project, I create and add a panel at
run time and on this panel, I draw a gradient along with several text
strings. This panel is docked at the top of the form and I also create
another that is docked at the bottom of the form. The problem I am
experiencing is that whenever I hover over the min/max button or bring
up any shortcut menus like clicking on the control box, where ever the
tooltip or pop up menu was will leave nothing but the background color
of the panel instead of refreshing the the gradient and any strings
drawn in that section as well. However, this only happens when the
first one pops up, if any more pop up after that, the panel seems to
paint correctly in that area when the popup/tooltip disappears
(although the previous area will remain blank). If I minimize the form
and then bring it back up, the entire form is correctly drawn, but the
problem happens exactly as it did before where the first popup causes a
problem and the rest do not. The second part of the problem is when
tabbing over to another control... all of a sudden both panels drawn
will go completely blank to whatever the default background color is
and will only come back if minimizing the form and bringing it back up
again. Below is the code I am using in my form (the panels
uxHeader/uxFooter are simply added during the form_load event with all
their defaults aside of dock and height), hopefully someone can see my
problem or suggest a resolution to it, thanks in advance:

Public Class form_main

Private Sub form_main_Paint( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) Handles
Me.Paint

DrawGradient( _
0, 0, uxHeader.Width, uxHeader.Height, _
Color.Black, Color.LightSlateGray, uxHeader,
Drawing.Drawing2D.LinearGradientMode.Vertical)
DrawGradient( _
0, 0, uxFooter.Width, uxFooter.Height, _
Color.LightSlateGray, Color.Black, uxFooter,
Drawing.Drawing2D.LinearGradientMode.Vertical)
DrawString( _
uxHeader, "Data Copy Setup", Brushes.SteelBlue, 11, 48,
_
New Font("Trebuchet MS", 14, FontStyle.Bold,
GraphicsUnit.Pixel))
DrawString( _
uxHeader, "Data Copy Setup", Brushes.White, 10, 47, _
New Font("Trebuchet MS", 14, FontStyle.Bold,
GraphicsUnit.Pixel))
DrawString( _
uxHeader, "Citizens Bank", Brushes.SteelBlue, 306, 10,
_
New Font("Trebuchet MS", 12, FontStyle.Bold,
GraphicsUnit.Pixel))
DrawString( _
uxHeader, "Citizens Bank", Brushes.White, 305, 9, _
New Font("Trebuchet MS", 12, FontStyle.Bold,
GraphicsUnit.Pixel))
DrawString( _
uxHeader, "Wintel Services", Brushes.SteelBlue, 306,
23, _
New Font("Trebuchet MS", 24, FontStyle.Bold,
GraphicsUnit.Pixel))
DrawString( _
uxHeader, "Wintel Services", Brushes.White, 305, 22, _
New Font("Trebuchet MS", 24, FontStyle.Bold,
GraphicsUnit.Pixel))
DrawString( _
uxHeader, "Migration Data Copy Tool",
Brushes.SteelBlue, 338, 48, _
New Font("Trebuchet MS", 12, FontStyle.Bold,
GraphicsUnit.Pixel))
DrawString( _
uxHeader, "Migration Data Copy Tool", Brushes.White,
337, 47, _
New Font("Trebuchet MS", 12, FontStyle.Bold,
GraphicsUnit.Pixel))
DrawString( _
uxFooter, "version 1.0.0", Brushes.SteelBlue, 416, 21,
_
New Font("Trebuchet MS", 10, FontStyle.Bold,
GraphicsUnit.Pixel))
DrawString( _
uxFooter, "version 1.0.0", Brushes.White, 415, 20, _
New Font("Trebuchet MS", 10, FontStyle.Bold,
GraphicsUnit.Pixel))

End Sub


'---------------------------------------------------------------------------------------------------------------------------------
' Sample Call:
'
' DrawGradient( _
' 0, 0, uxHeader.Width, uxHeader.Height, _
' Color.Black, Color.Gainsboro, uxHeader,
Drawing.Drawing2D.LinearGradientMode.Vertical)

'---------------------------------------------------------------------------------------------------------------------------------
Private Sub DrawGradient( _
ByVal x As Integer, _
ByVal y As Integer, _
ByVal w As Integer, _
ByVal h As Integer, _
ByVal color1 As Color, _
ByVal color2 As Color, _
ByVal ctrl As Control, _
ByVal mode As System.Drawing.Drawing2D.LinearGradientMode)

Dim a As New System.Drawing.Drawing2D.LinearGradientBrush(New
RectangleF(0, 0, ctrl.Width, ctrl.Height), color1, color2, mode)
Dim g As Graphics = ctrl.CreateGraphics
g.FillRectangle(a, New RectangleF(x, y, w, h))
g.Dispose()

End Sub


'---------------------------------------------------------------------------------------------------------------------------------
' Sample Call:
'
' DrawGradientString( _
' "Sample", Color.Blue, Color.Firebrick, _
' Drawing.Drawing2D.LinearGradientMode.Vertical)

'---------------------------------------------------------------------------------------------------------------------------------
Private Sub DrawGradientString( _
ByVal text As String, _
ByVal color1 As Color, _
ByVal color2 As Color, _
ByVal mode As System.Drawing.Drawing2D.LinearGradientMode)

Dim a As New System.Drawing.Drawing2D.LinearGradientBrush(New
RectangleF(0, 0, 100, 19), color1, color2, mode)
Dim g As Graphics = Me.CreateGraphics
Dim f As Font
f = New Font("verdana", 16, FontStyle.Bold, GraphicsUnit.Pixel)
g.DrawString(text, f, a, 10, 100)
g.Dispose()

End Sub


'---------------------------------------------------------------------------------------------------------------------------------
' Sample Call:
'
' DrawString( _
' Me, "Wintel Operations", Brushes.Black, 12, 102, _
' New Font("Trebuchet MS", 24, FontStyle.Bold,
GraphicsUnit.Pixel))

'---------------------------------------------------------------------------------------------------------------------------------
Private Sub DrawString( _
ByVal ctrl As Control, _
ByVal text As String, _
ByVal b As Brush, _
ByVal x As Integer, _
ByVal y As Integer, _
ByVal f As Font)

Dim g As Graphics = ctrl.CreateGraphics

g.DrawString(text, f, b, x, y)
g.Dispose()

End Sub

End Class