JeffvClayton
asked on
Topmost window wipes graphics of window below
I have a form that contains a panel with a gradient drawn in 2 colours. I have a call to the procedure that draws the gradient in the form paint and form resize events otherwise it gets wiped out. However, I have now noticed that when a new form is opened on top, as you move the new form around it wipes out the colour gradient drawn on the form below just like a photoshop eraser tool. How can I stop this happening, do I have to start calling the gradient drawing procedure from the new form or is there another event in the original form that I need to put the call in. Hopefully ther latter, or having a gradient is going to be more trouble than its worth! Any help appreciated.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Here is how I call the above
DrawGradienC(Me.Panel1, Color.Gainsboro, Color.SteelBlue, Drawing.Drawing2D.LinearGr adientMode .Horizonta l)
DrawGradienC(Me.Panel1, Color.Gainsboro, Color.SteelBlue, Drawing.Drawing2D.LinearGr
My code is persistant because I create an image and then assign that image to the Panel1.BackgroundImage = gradientImage. In doing this the system will handle the painting no need to execute the code again, no flicker.
The Imports statement should not give a syntax error unless you do not have a reference to System.Drawing or System.Drawing.Drawing2D.
Fernando
The Imports statement should not give a syntax error unless you do not have a reference to System.Drawing or System.Drawing.Drawing2D.
Fernando
ASKER
Thanks to both of you for giving 2 ways to solve the problem.
I have gone with the solution from Fernando for most of the points as I only need to draw the graphics once i.e. the graphics are persistant. I solved the Imports syntax error by putting the imports statements above the following lines
Imports System.Drawing
Imports System.Drawing.Drawing2D
Public Class Form3
Inherits System.Windows.Forms.Form
Thanks for the help.
Regards
Jeff.
I have gone with the solution from Fernando for most of the points as I only need to draw the graphics once i.e. the graphics are persistant. I solved the Imports syntax error by putting the imports statements above the following lines
Imports System.Drawing
Imports System.Drawing.Drawing2D
Public Class Form3
Inherits System.Windows.Forms.Form
Thanks for the help.
Regards
Jeff.
Glad I was able to help. ;=)
ThanX Jeff
ASKER
Fernando, I get a syntax error with the word imports. However, here is the code I have used (in a module) which is now called by form resize,paint,load, and panel paint. I am using VB.Net 2003. To me it looks like it basically does the same thing so I don't understand why it would be persistant!
Public Sub DrawGradient(ByVal pan As System.Windows.Forms.Contr
If pan.Width > 0 And pan.Height > 0 Then
Dim a As New System.Drawing.Drawing2D.L
Dim g As Graphics = pan.CreateGraphics
g.FillRectangle(a, New RectangleF(0, 0, pan.Width, pan.Height))
Dim myBrush As New SolidBrush(Color.White)
pan.CreateGraphics.DrawStr
g.Dispose()
End If
End Sub