WinCE下动态显示绘图控件

一、要点

    本控件解决了CE下绘图闪烁的问题

二、源代码

namespace RealTimeGraphCtlCF

{

public partial class GraphPane : UserControl

{

private Graphics gHdc;

 

private XAxis xAxis;

 

private YAxis yAxis;

 

private int _xMax;

[EditorBrowsable(EditorBrowsableState.Always)]

[DefaultValue(100)]

public int XAxisMax

{

get { return _xMax; }

set { _xMax = value; }

}

 

private int _yMax;

[EditorBrowsable(EditorBrowsableState.Always)]

[DefaultValue(100)]

public int YAxisMax

{

get { return _yMax; }

set { _yMax = value; }

}

 

private string _xTitle = "X";

[EditorBrowsable(EditorBrowsableState.Always)]

[DefaultValue("X")]

public string XAxisTitle

{

get { return _xTitle; }

set { _xTitle = value; }

}

 

private string _yTitle = "Y";

[EditorBrowsable(EditorBrowsableState.Always)]

[DefaultValue("Y")]

public string YAxisTitle

{

get { return _yTitle; }

set { _yTitle = value; }

}

 

private int _xTicCount = 100;

[EditorBrowsable(EditorBrowsableState.Always)]

[DefaultValue(100)]

public int XAxisTicCount

{

get { return _xTicCount; }

set { _xTicCount = value; }

}

 

private int _yTicCount = 100;

[EditorBrowsable(EditorBrowsableState.Always)]

[DefaultValue(100)]

public int YAxisTicCount

{

get { return _yTicCount; }

set { _yTicCount = value; }

}

 

private Pen _linePen;

[EditorBrowsable(EditorBrowsableState.Never)]

public Pen LinePen

{

get { return _linePen; }

set { _linePen = value; }

}

 

public List<Point> PointList;

 

private const int ticLength = 2;

 

 

 

public GraphPane()

{

InitializeComponent();

this.PointList = new List<Point>();

this._linePen = new Pen(Color.Black, 1);

 

}

 

private void GraphPane_Paint(object sender, PaintEventArgs e)

{

Bitmap b = new Bitmap(this.Width, this.Height);

gHdc = Graphics.FromImage((System.Drawing.Image)b);

 

gHdc.FillRectangle(new SolidBrush(Color.White), this.ClientRectangle);

 

Point orgin = new Point(20, 20);

 

int yAxisLength = ClientRectangle.Height - 2 * orgin.Y;

yAxis = new YAxis(gHdc, this.ClientRectangle, orgin, yAxisLength, _yMax, _yTitle);

yAxis.Draw(_yTicCount, ticLength);

 

int xAxisLength = ClientRectangle.Width - 2 * orgin.X;

xAxis = new XAxis(gHdc, this.ClientRectangle, orgin, xAxisLength, _xMax, _xTitle);

xAxis.Draw(_xTicCount, ticLength);

 

DrawLines(gHdc);

 

e.Graphics.DrawImage((System.Drawing.Image)b, 0, 0);

b.Dispose();

}

 

public void DrawLines(Graphics gHdc)

{

Point previous = new Point();

Point current = new Point();

 

if (PointList.Count >= 2)

{

previous = PointList[0];

for (int i = 1; i < PointList.Count; i++)

{

current = PointList[i];

gHdc.DrawLine(LinePen, previous.X, previous.Y, current.X, current.Y);

previous = current;

}

}

}

 

 

protected override void OnPaintBackground(PaintEventArgs e)

{

}

 

}

}

 

三、参考文献

http://blog.csdn.net/yefanqiu/archive/2006/11/21/1402520.aspx

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值