怎样重写Canvas的OnRender事件,Canvas是一个窗体的子控件!
名字叫canvas1,重写后又如何调用!
------解决方案--------------------------------------------------------
重写后要在程序中调用cancas1.InvalidateVisual();
关于怎么重写给你个例子吧。
protected override void OnRender(System.Windows.Media.DrawingContext dc)
{
base.OnRender(dc);//
if (AnalyerGloablStatus.Instance.DicPoints != null)
{
// System.Diagnostics.Debug.WriteLine("{0}+{1}", DateTime.Now.Second.ToString() + ":" + DateTime.Now.Millisecond.ToString(), "begin");
for (int index = 0; index < AnalyerGloablStatus.Instance.DicPoints.Count - 1; index++)
{
//dc.DrawLine(new Pen(Brushes.Yellow, 1),
// new Point(AnalyerGloablStatus.Instance.DicPoints[index].PhyicPointX, AnalyerGloablStatus.Instance.DicPoints[index].PhyicPointY),
// new Point(AnalyerGloablStatus.Instance.DicPoints[index + 1].PhyicPointX, AnalyerGloablStatus.Instance.DicPoints[index + 1].PhyicPointY));
FreqencyPoint point1 = (FreqencyPoint)AnalyerGloablStatus.Instance.DicPoints[index];
FreqencyPoint point2 = (FreqencyPoint)AnalyerGloablStatus.Instance.DicPoints[index + 1];
dc.DrawLine(new Pen(Brushes.Yellow, 1),
new Point(point1.PhyicPointX, point1.PhyicPointY),
new Point(point2.PhyicPointX, point2.PhyicPointY));
}
// System.Diagnostics.Debug.WriteLine("{0}+{1}", DateTime.Now.Second.ToString() + ":" + DateTime.Now.Millisecond.ToString(), "end");
}
}
给分啊!