首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >图表绘制事件

图表绘制事件
EN

Stack Overflow用户
提问于 2015-06-29 01:36:40
回答 2查看 1.5K关注 0票数 0

下面是我正在运行的代码:

代码语言:javascript
复制
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Drawing;

namespace ChartTeste
{
    public partial class Form1 : Form
    {
        Graphics g;

        public Form1()
        {
            InitializeComponent();
            chart1.ChartAreas["Triangulos"].AxisY.Minimum = 0;
            chart1.ChartAreas["Triangulos"].AxisY.Maximum = 40;
            chart1.ChartAreas["Triangulos"].AxisX.Minimum = 0;
            chart1.ChartAreas["Triangulos"].AxisX.Maximum = 5;
            g = chart1.CreateGraphics();
        }

        private void chart1_Paint(object sender, PaintEventArgs e)
        {
            Paint();
        }

        private void Paint()
        {
            Pen p = new Pen(Brushes.Red);
                chart1.Series["PreçoT"].Points.AddXY(1, 0);

                double posiX = chart1.ChartAreas["Triangulos"].AxisX.ValueToPixelPosition(1);
                double posiY = chart1.ChartAreas["Triangulos"].AxisY.ValueToPixelPosition(13);
                double posiY2 = chart1.ChartAreas["Triangulos"].AxisY.ValueToPixelPosition(16);
                double max = chart1.ChartAreas["Triangulos"].AxisY.ValueToPixelPosition(19);
                double min = chart1.ChartAreas["Triangulos"].AxisY.ValueToPixelPosition(10);


                Point[] points = { new Point(Convert.ToInt32(posiX - 20), Convert.ToInt32(posiY)), new Point(Convert.ToInt32(posiX + 20), Convert.ToInt32(posiY)), new Point(Convert.ToInt32(posiX + 20), Convert.ToInt32(posiY2)) };

                g.DrawLine(p,Convert.ToInt32(posiX),Convert.ToInt32(min),Convert.ToInt32(posiX),Convert.ToInt32(max));
                g.FillPolygon(Brushes.Red, points);
        }
    }
}

当我运行它时,生成的三角形不是固定的,而是闪烁和故障。有什么方法可以停止油漆事件后,它产生三角形?

任何帮助都是非常感谢的。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-06-29 02:03:10

要停止闪烁,请将this.DoubleBuffered = true;添加到窗体的构造函数中。

为了每隔X分钟重新绘制表单,在timer tick事件中添加Invalidate(true); (我假设您有计时器)。

票数 -2
EN

Stack Overflow用户

发布于 2015-12-23 14:46:06

代码语言:javascript
复制
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31106597

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档