WPF 图表控件之曲线绘制与移动
作者:互联网
目的:绘制简单轻量级的曲线视图
二、实现效果:
1,绘制标准基准线
2,可拖动
三、用到控件
1,Canvas
2,Ellipse
XAML代码:
<Canvas Background="#232323" Grid.Row="1" x:Name="MainCanvas" SizeChanged="LiveChar_SizeChanged"
Width="600" Height="300" MouseMove="MainCanvas_MouseMove"
ClipToBounds="True" MouseLeftButtonDown="MainCanvas_MouseLeftButtonDown"
MouseLeftButtonUp="MainCanvas_MouseLeftButtonUp"/>
CS代码:
1,定义类型
/// <summary> /// 画板宽度 /// </summary> public double BoardWidth { get; set; } /// <summary> /// 画板高度 /// </summary> public double BoardHeight { get; set; } /// <summary> /// 平行(横向)边距(画图区域距离左右两边长度) /// </summary> public double HorizontalMargin { get; set; } /// <summary> /// 垂直(纵向)边距(画图区域距离左右两边长度) /// </summary> public double VerticalMargin { get; set; } /// <summary> /// 水平刻度间距像素 /// </summary> public double horizontalBetween { get; set; } /// <summary> /// 垂直刻度间距像素 /// </summary> public double verticalBetween { get; set; } /// <summary> /// 图表区域宽度 /// </summary> public double ChartWidth; /// <summary> /// 图表区域高度 /// </summary> public double ChartHeight; /// <summary> /// <summary> /// 坐标点数据源 /// </summary> public PointCollection DataSourse; /// <summary> /// 画图区域起点 /// </summary> public Point StartPostion; /// <summary> /// 画图区域终点 /// </summary> public Point EndPostion; /// <summary> /// x轴最大值 /// </summary> public double MaxX { get; set; } /// <summary> /// y轴最大值 /// </summary> public double MaxY { get; set; } /// <summary> /// x轴最小值 /// </summary> public double MinX { get; set; } /// <summary> /// y轴最小值 /// </summary> public double MinY { get; set; } double MapLocationX = 0; double MapLocationY = 0;
TextBox moushPonit;
Point pBefore = new Point();//鼠标点击前坐标
Point eBefore = new Point();//圆移动前坐标
bool isMove = false;//是否需要移动
public enum DrawType
{
//Line
L,
//Horizontal line
H,
//Vertical line
V,
//Cubic Bezier curve
C,
//Quadratic Bezier curve
Q,
//Smooth cubic Bezier curve
S,
//smooth quadratic Bezier curve
T
}
public class SpeedOrPower
{
public double SpeedNum { get; set; }
public double PowerNum { get; set; }
}
标签:控件,set,get,Bezier,double,Point,图表,WPF,public 来源: https://www.cnblogs.com/zt199510/p/14002264.html