Click here to Skip to main content
16,016,738 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I am making an application in C # using Windows Form and I use an UserControl to draw a 3D graph. I use the Paint method to call the routines that draw the graph. First I call a routine that creates several GraphicsPath with the points the graph, then I call a routine that fills these GraphicsPath with differents tones giving the impression of 3D.

But when I minimize the application the areas that were filled loose fill and when I minimize again the fill back . How do I not miss the fill of graph each new called the Paint method. Below I put a part of my code if anyone can help me I thank you.

Paint method of the UserControl

C#
private void wucGraficoBarras3D_Paint(object sender, PaintEventArgs e)
        {          
            oCriarGrafico.OGrafico = e.Graphics; 

            oCriarGrafico.CriarCaminhosEstrutura();

            oCriarGrafico.PreencherEstrutura();
}


Method that creates GraphicsPath with points

C#
 public void CriarCaminhosEstrutura()
        {          
       	    PointF[] pontosBaseS = {new PointF(0.00f, 0.00f), new PointF(14.14f, -14.14f),
            new PointF(294.14f, -14.14f), new PointF(280.00f, 0.00f)};
           
            GraphicsPath caminhoBaseF = new GraphicsPath();

            oGrafico.TranslateTransform(origemX, origemY); 
         
            caminhoBaseF.AddLines(pontosBaseF);  
            caminhoBaseF.CloseFigure();
}


Method that fills the GraphicsPath with various shades

C#
public void PreencherEstrutura()
        {
            mistura.Factors = fatoresBlend;
            mistura.Positions = posicoesBlend;
           
            pontoInicialEstruturaBlend = new PointF(0.00f, 4.00f);
            pontoFinalEstruturaBlend = new PointF(280.00f, 4.00f);
            corEstrutura1 = Color.FromArgb(255, Color.DarkGray);
            corEstrutura2 = Color.FromArgb(255, Color.Gray);
            LinearGradientBrush escovaEstrutura = new LinearGradientBrush(pontoInicialEstruturaBlend,
                pontoFinalEstruturaBlend, corEstrutura1, corEstrutura2);
            escovaEstrutura.Blend = mistura;
            oGrafico.FillPath(escovaEstrutura, caminhoBaseF);
}
Posted

1 solution

Basically, you are on a right track already, but you should understand yet another thing: the event Paint is fired (or the virtual method OnPaint is called) every time the Windows message WM_PAINT is sent, and it happens every time some part of a control is invalidated. So, you need to handle painting (graphics rendering) based on some data; and you need to keep this data by yourself.

Please see the further detail in my past answers:
Drawing Lines between mdi child forms[^],
capture the drawing on a panel[^],
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^].

Good luck,
—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900