绘画方法的帮助 [英] Help with Paint Method

查看:150
本文介绍了绘画方法的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Windows窗体在C#中创建应用程序,并使用UserControl绘制3D图形.我使用Paint方法来调用绘制图形的例程.首先,我调用一个例程,该例程用图形的点创建几个GraphicsPath,然后调用一个例程,这些例程用不同的色调填充这些GraphicsPath,从而赋予3D印象.

但是,当我最小化应用程序时,填充的区域会松散填充,而当我再次最小化填充时,则会填充.我如何不错过每个称为Paint方法的新图形的填充.如果有人可以帮助我,请在下面放置我的代码的一部分,谢谢.

UserControl的绘制方法

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

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

            oCriarGrafico.CriarCaminhosEstrutura();

            oCriarGrafico.PreencherEstrutura();
}



用点创建GraphicsPath的方法



Method that creates GraphicsPath with points

 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();
}



用各种阴影填充GraphicsPath的方法



Method that fills the GraphicsPath with various shades

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);
}

推荐答案

基本上,您已经在正确的轨道上,但是您应该了解另一件事:事件Paint被触发(或每次发送Windows消息WM_PAINT时,都会调用虚拟方法OnPaint,并且每次控件的某些部分无效时都会发生这种情况.因此,您需要根据一些数据来处理绘画(图形渲染).您需要自己保留这些数据.

请查看我过去的答案中的更多详细信息:
在mdi子表单之间画线 [在面板上捕获图形 [ Paint是一种哪种好玩的方法? (DataGridViewImageCell.Paint(...)) [
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


这篇关于绘画方法的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆