这是我正在运行的代码:
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);
}
}
}
当我运行它时,生成的三角形不固定,它会闪烁并出现故障。有没有什么办法可以在生成三角形后停止Paint事件?
感谢任何帮助。
答案 0 :(得分:1)
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
答案 1 :(得分:-2)
要停止闪烁,请将this.DoubleBuffered = true;
添加到表单的构造函数。
要每隔X分钟重新绘制一次表单,请在计时器刻度事件中添加Invalidate(true);
(我假设您有计时器) )。