下面是我正在运行的代码:
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);
}
}
}当我运行它时,生成的三角形不是固定的,而是闪烁和故障。有什么方法可以停止油漆事件后,它产生三角形?
任何帮助都是非常感谢的。
发布于 2015-06-29 02:03:10
要停止闪烁,请将this.DoubleBuffered = true;添加到窗体的构造函数中。
为了每隔X分钟重新绘制表单,在timer tick事件中添加Invalidate(true); (我假设您有计时器)。
发布于 2015-12-23 14:46:06
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);https://stackoverflow.com/questions/31106597
复制相似问题