?
Solved

Topmost window wipes graphics of window below

Posted on 2006-07-24
8
Medium Priority
?
213 Views
Last Modified: 2010-04-23
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.
0
Comment
Question by:JeffvClayton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 6

Assisted Solution

by:Jayadev Nair
Jayadev Nair earned 200 total points
ID: 17168088
Your drawing just makes the current window drawn and just left the process. Any window on its top will erase the same drawing. While using GDI, draw the same on the Paint_Event of the Panel which will solve your issue.
0
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 800 total points
ID: 17168155
Hi JeffvClayton;

This sample code will draw a Gradient on the Panel control and will persist without a need to do anything else the system will handle it, so no need to place code in paint events.

Imports System.Drawing
Imports System.Drawing.Drawing2D

        Dim gradientImage As New Bitmap(Panel1.Width, Panel1.Height, Panel1.CreateGraphics)
        Dim gradientArea As Graphics = Graphics.FromImage(gradientImage)
        Dim mode As New LinearGradientMode
        mode = LinearGradientMode.Horizontal
        Dim startColor As Color = Color.Blue
        Dim endColor As Color = Color.Yellow
        Dim rect As New Rectangle(0, 0, Panel1.Width, Panel1.Height)
        Dim lgBrush As New LinearGradientBrush(rect, startColor, endColor, mode)
        gradientArea.FillRectangle(lgBrush, rect)
        Panel1.BackgroundImage = gradientImage
        If Not lgBrush Is Nothing Then
            lgBrush.Dispose()
        End If
        gradientArea.Dispose()


Fernando
0
 
LVL 3

Author Comment

by:JeffvClayton
ID: 17168731
Thanks for the reply compued, I have tried that out and it works fine (with a bit of flicker on the painted text on top of the gradient)

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.Control, ByVal color1 As Color, ByVal color2 As Color, ByVal mode As System.Drawing.Drawing2D.LinearGradientMode)


        If pan.Width > 0 And pan.Height > 0 Then

            Dim a As New System.Drawing.Drawing2D.LinearGradientBrush(New RectangleF(0, 0, pan.Width, pan.Height), color1, color2, mode)
            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.DrawString("Company Name", pan.Font, myBrush, pan.Width - 200, 10)
            g.Dispose()

        End If
     
    End Sub
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 3

Author Comment

by:JeffvClayton
ID: 17168775
Here is how  I call the above

DrawGradienC(Me.Panel1, Color.Gainsboro, Color.SteelBlue, Drawing.Drawing2D.LinearGradientMode.Horizontal)
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 17168928
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
0
 
LVL 3

Author Comment

by:JeffvClayton
ID: 17173991
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.
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 17175497
Glad I was able to help. ;=)
0
 
LVL 6

Expert Comment

by:Jayadev Nair
ID: 17184046
ThanX Jeff
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month14 days, 15 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question