jsonTranexcel (2).gif

类设计

image.pngimage.png

主程序

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using Microsoft.Extensions.DependencyInjection;
  11. using CBB_Saker_Painting_1._0._0.Models;
  12. using System.Drawing.Drawing2D;
  13. using CBB_Saker_Painting_1._0._0.Global;
  14. using saker_Winform.UserControls;
  15. using System.IO;
  16. using System.Runtime.Serialization;
  17. using System.Runtime.Serialization.Formatters.Binary;
  18. namespace CBB_Saker_Painting_1._0._0 {
  19. public partial class Painting : UserControl {
  20. public Painting() {
  21. InitializeComponent();
  22. }
  23. #region 字段/属性/变量
  24. PaintPara paintPara = new PaintPara();
  25. DataManager dataManager = new DataManager();
  26. List<Data> listWaveDataSeriesCopy = new List<Data>();
  27. #endregion
  28. #region 方法:开双缓冲器
  29. /// <summary>
  30. /// 复写方法:双缓冲器打开
  31. /// </summary>
  32. protected override CreateParams CreateParams {
  33. get {
  34. CreateParams cp = base.CreateParams;
  35. cp.ExStyle |= 0x02000000;
  36. return cp;
  37. }
  38. }
  39. #endregion
  40. #region 方法:初始化显示
  41. private void Init() {
  42. paintPara.Init(this.pictureBox_Wave.Width, this.pictureBox_Wave.Height);
  43. this.ucChanLabel_CursorY1.Visible = paintPara.bCursorYShow;
  44. this.ucChanLabel_CursorY2.Visible = paintPara.bCursorYShow;
  45. this.ucChanLabelVertical_CursorX1.Visible = paintPara.bCursorXShow;
  46. this.ucChanLabelVertical_CursorX2.Visible = paintPara.bCursorXShow;
  47. this.ucCursorInfo_XY.Visible = paintPara.bCursorXYMesInfo;
  48. paintPara.MinValueY = -10;
  49. paintPara.MaxValueY = 10;
  50. paintPara.MinValueX = 0;
  51. paintPara.MaxValueX = 10;
  52. }
  53. #endregion
  54. #region 方法:绘图
  55. private void Drawing(List<Data> listWaveDataSeries) {
  56. if ((this.pictureBox_Wave.Width <= 0) || (this.pictureBox_Wave.Height <= 0)) {
  57. return;
  58. }
  59. Bitmap bmpClear = new Bitmap(pictureBox_Wave.Width, pictureBox_Wave.Height);
  60. Graphics gClear = Graphics.FromImage(bmpClear);
  61. gClear.Clear(System.Drawing.Color.Black);
  62. this.pictureBox_Wave.Image = bmpClear;
  63. // 先生成一个新的位图
  64. Bitmap bmp = new Bitmap(pictureBox_Wave.Width, pictureBox_Wave.Height);
  65. using (Graphics g = Graphics.FromImage(bmp)) {
  66. g.Clear(System.Drawing.Color.Black);
  67. g.SmoothingMode = SmoothingMode.AntiAlias;
  68. Pen pen = new Pen(Color.Gray, 1);
  69. pen.DashStyle = DashStyle.Solid;//画笔为实线
  70. Rectangle rectangle = new Rectangle(pictureBox_Wave.ClientRectangle.X, pictureBox_Wave.ClientRectangle.Y,
  71. pictureBox_Wave.ClientRectangle.X + pictureBox_Wave.ClientRectangle.Width,
  72. pictureBox_Wave.ClientRectangle.Y + pictureBox_Wave.ClientRectangle.Height);
  73. g.DrawRectangle(pen, rectangle);
  74. pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom; //虚线
  75. pen.DashPattern = new float[] { 2, 2 };
  76. StringFormat strFmt = new System.Drawing.StringFormat();
  77. strFmt.Alignment = StringAlignment.Center; //文本水平居中
  78. strFmt.LineAlignment = StringAlignment.Center; //文本垂直居中
  79. Font axisFont = new Font("微软雅黑", 9, FontStyle.Bold);
  80. //绘制顶部位置的纵坐标标示
  81. SizeF sf = g.MeasureString(paintPara.strTopY, axisFont);
  82. RectangleF rf = new RectangleF(0, 0, sf.Width, sf.Height);
  83. if (paintPara.bYMarking) {
  84. //s要绘制的字符串,font文本格式,brush文本的颜色和纹理,x左上角x坐标,y左上角y坐标,format文本对齐方式
  85. g.DrawString(paintPara.strTopY, axisFont, new SolidBrush(Color.White), rf, strFmt);
  86. }
  87. //绘制底部位置的纵坐标标示
  88. sf = g.MeasureString(paintPara.strBottomY, axisFont);
  89. rf = new RectangleF(0, this.pictureBox_Wave.Height - sf.Height, sf.Width, sf.Height);
  90. if (paintPara.bYMarking) {
  91. g.DrawString(paintPara.strBottomY, axisFont, new SolidBrush(Color.White), rf, strFmt);
  92. }
  93. //绘制Y轴刻度线
  94. for (int i = 1; i < paintPara.BisectrixY; i++) {
  95. float div = (float)this.pictureBox_Wave.ClientRectangle.Height / paintPara.BisectrixY;
  96. string strVertScale = PaintPara.Voltage2String(paintPara.MaxValueY - paintPara.VertScale / paintPara.BisectrixY * i);
  97. sf = g.MeasureString(strVertScale, axisFont);
  98. rf = new RectangleF(0, div * i - sf.Height / 2, sf.Width, sf.Height);
  99. //绘制纵坐标标示
  100. if (paintPara.bYMarking) {
  101. g.DrawString(strVertScale, axisFont, new SolidBrush(Color.White), rf, strFmt);
  102. }
  103. if (i == paintPara.BisectrixY / 2) {
  104. pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid; //实线
  105. if (paintPara.bDrawGridLineY) {
  106. //Pen线条样式,x1,y1,x2,y2
  107. g.DrawLine(pen, 0, div * i, pictureBox_Wave.ClientRectangle.Width, div * i);
  108. }
  109. }
  110. else {
  111. pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom; //虚线
  112. pen.DashPattern = new float[] { 2, 2 };
  113. if (paintPara.bDrawGridLineY) {
  114. g.DrawLine(pen, 0, div * i, pictureBox_Wave.ClientRectangle.Width, div * i);
  115. }
  116. }
  117. }
  118. //绘制最右侧水平坐标标示
  119. sf = g.MeasureString(paintPara.HorizRight, axisFont);
  120. rf = new RectangleF(this.pictureBox_Wave.Width - sf.Width, 0, sf.Width, sf.Height);
  121. if (paintPara.bXMarking) {
  122. g.DrawString(paintPara.HorizRight, axisFont, new SolidBrush(Color.Orange), rf, strFmt);
  123. }
  124. //绘制X轴刻度线条
  125. for (int i = 1; i < paintPara.BisectrixX; i++) {
  126. float div = (float)this.pictureBox_Wave.ClientRectangle.Width / paintPara.BisectrixX;
  127. string strHoriScale = PaintPara.Time2String(paintPara.MinValueX + paintPara.HoriScale / paintPara.BisectrixX * i);
  128. sf = g.MeasureString(strHoriScale, axisFont);
  129. rf = new RectangleF(div * i - sf.Width / 2, 0, sf.Width, sf.Height);
  130. //绘制横坐标标示
  131. if (paintPara.bXMarking) {
  132. g.DrawString(strHoriScale, axisFont, new SolidBrush(Color.Orange), rf, strFmt);
  133. }
  134. if (i == paintPara.BisectrixX / 2) {
  135. pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid; //实线
  136. if (paintPara.bDrawGridLineX) {
  137. //Pen线条样式,x1,y1,x2,y2
  138. g.DrawLine(pen, div * i, 0, div * i, pictureBox_Wave.ClientRectangle.Width);
  139. }
  140. }
  141. else {
  142. pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom; //虚线
  143. pen.DashPattern = new float[] { 2, 2 };
  144. if (paintPara.bDrawGridLineY) {
  145. g.DrawLine(pen, div * i, 0, div * i, pictureBox_Wave.ClientRectangle.Width);
  146. }
  147. }
  148. }
  149. //多图层绘制图层链表
  150. for (int i = 0; i < listWaveDataSeries.Count; i++) {
  151. Bitmap bitmap = new Bitmap(this.pictureBox_Wave.Width, this.pictureBox_Wave.Height);
  152. paintPara.listImages.Add(bitmap);
  153. }
  154. if(paintPara.IndexXFinish - paintPara.IndexXStart < 2) {
  155. return;
  156. }
  157. //并发绘制
  158. Parallel.For(0, listWaveDataSeries.Count, item => {
  159. Graphics graphics = Graphics.FromImage(paintPara.listImages[item]);
  160. graphics.SmoothingMode = SmoothingMode.AntiAlias;
  161. //paintPara.XScaleCount = listWaveDataSeries[item].listWaveData.Count;
  162. paintPara.XScaleCount = paintPara.IndexXFinish - paintPara.IndexXStart;
  163. //计算0值的坐标
  164. int tempv = (int)(-paintPara.MinValueY / paintPara.IntervalValueY);//得到0到最小值的间隔距离;
  165. float zeroY = paintPara.EndPosition.Y - tempv * paintPara.VerticalBetween;//值为0点Y抽坐标;
  166. if (listWaveDataSeries[item].listWaveData.Count > 1) {
  167. int dataIndex = 0;
  168. //PointF[] arrDataPoint = new PointF[listWaveDataSeries[item].listWaveData.Count];
  169. PointF[] arrDataPoint = new PointF[paintPara.IndexXFinish- paintPara.IndexXStart];
  170. int index = 0;
  171. int j = 0;
  172. foreach (PointF pf in listWaveDataSeries[item].listWaveData) {
  173. if(index>=paintPara.IndexXStart && index <= (paintPara.IndexXFinish-1)) {
  174. PointF temp = new PointF();
  175. temp.X = paintPara.StartPosition.X + paintPara.HorizontalBetween * j;
  176. temp.Y = zeroY - paintPara.VerticalBetween * pf.Y / paintPara.IntervalValueY;
  177. arrDataPoint[dataIndex++] = temp;
  178. j++;
  179. }
  180. index++;
  181. }
  182. //均值圆滑一下
  183. graphics.DrawCurve(new Pen(new SolidBrush(listWaveDataSeries[item].LineColor), 1F), arrDataPoint);
  184. }
  185. graphics.Dispose();
  186. });
  187. //清零计数
  188. foreach (Bitmap item in paintPara.listImages) {
  189. g.DrawImage(item, new Rectangle(0, 0, pictureBox_Wave.Width, pictureBox_Wave.Height));
  190. }
  191. g.Dispose();
  192. paintPara.listImages.Clear();
  193. }
  194. pictureBox_Wave.Image = bmp;
  195. }
  196. #endregion
  197. #region 方法:添加/刷新/移除Tag控件到PanelLeft中
  198. private void AddTagControl(List<Data> listWaveDataSeries) {
  199. foreach (var item in listWaveDataSeries) {
  200. //添加左侧Tag
  201. UCChanLabel uCChanLabel = new UCChanLabel();
  202. this.panel_Left.Controls.Add(uCChanLabel);
  203. uCChanLabel.setLabel(item.TagName, item.LineColor);
  204. uCChanLabel.Location = new Point(uCChanLabel.Location.X, (int)((paintPara.MaxValueY - item.listWaveData[0].Y) / paintPara.VertScale * this.panel_Left.Height - this.ucChanLabel_CursorY1.Height / 2));
  205. uCChanLabel.MouseDown += UCChanLabel_MouseDown;
  206. uCChanLabel.MouseMove += UCChanLabel_MouseMove;
  207. uCChanLabel.MouseUp += UCChanLabel_MouseUp;
  208. }
  209. }
  210. private void RefreshControl(List<Data> listWaveDataSeries) {
  211. foreach (UCChanLabel item in this.panel_Left.Controls) {
  212. if (!item.m_strChanID.Contains("Y")) {
  213. int index = listWaveDataSeries.FindIndex(i => i.TagName == item.m_strChanID);
  214. if (index != -1) {
  215. item.Location = new Point(item.Location.X, (int)((paintPara.MaxValueY - listWaveDataSeries[index].listWaveData[paintPara.IndexXStart].Y) / paintPara.VertScale * this.panel_Left.Height - this.ucChanLabel_CursorY1.Height / 2));
  216. item.CurrentCursorLocation = item.Location.Y / (panel_Left.Height * 1.0);
  217. }
  218. }
  219. }
  220. this.panel_Left.Refresh();
  221. }
  222. //用for循环替代foreach中ControlCollection会变化的问题
  223. private void RemoveControl(List<Data> listWaveDataSeries) {
  224. int k = 0;
  225. for (int i = 0; i < (listWaveDataSeriesCopy.Count+2); i++) {
  226. var item =(UCChanLabel)panel_Left.Controls[k];
  227. if (!item.m_strChanID.Contains("Y")) {
  228. int index = listWaveDataSeries.FindIndex(j => j.TagName == item.m_strChanID);
  229. if (index != -1) {
  230. this.panel_Left.Controls.Remove(item);
  231. }
  232. else {
  233. k++;
  234. }
  235. }
  236. else {
  237. k++;
  238. }
  239. }
  240. this.panel_Left.Refresh();
  241. }
  242. #endregion
  243. #region 事件:Load事件
  244. private void Painting_Load(object sender, EventArgs e) {
  245. Init();
  246. listWaveDataSeriesCopy = dataManager.listWaveDataSeries;
  247. Drawing(listWaveDataSeriesCopy);
  248. // 设置光标显示的内容
  249. ucChanLabel_CursorY1.setLabel(" Y1", Color.GreenYellow);
  250. ucChanLabel_CursorY2.setLabel(" Y2", Color.GreenYellow);
  251. ucChanLabelVertical_CursorX1.setLabel("X1", Color.GreenYellow);
  252. ucChanLabelVertical_CursorX2.setLabel("X2", Color.GreenYellow);
  253. this.ucCursorInfo_XY.Parent = this.pictureBox_DrawRect;//父容器设置为顶层pictureBox
  254. this.pictureBox_DrawRect.Parent = this.pictureBox_Wave;//父容器设置为底层pictureBox
  255. }
  256. #endregion
  257. #region 事件:Tag移动
  258. private void UCChanLabel_MouseUp(object sender, MouseEventArgs e) {
  259. if (e.Button == MouseButtons.Left) {
  260. var uCChanLabel = (UCChanLabel)sender;
  261. uCChanLabel.IsChanLabelMouseDown = false;
  262. float ampPrePoint = paintPara.VertScale / this.panel_Left.Height;
  263. int index = listWaveDataSeriesCopy.FindIndex(item => item.TagName == uCChanLabel.m_strChanID);
  264. if (index != -1) {
  265. float offsetAmp = paintPara.MaxValueY - ampPrePoint * (uCChanLabel.Location.Y + uCChanLabel.Height / 2) - listWaveDataSeriesCopy[index].listWaveData[paintPara.IndexXStart].Y;
  266. /*更新显示的偏移值*/
  267. for (int i = 0; i < listWaveDataSeriesCopy[index].listWaveData.Count; i++) {
  268. listWaveDataSeriesCopy[index].listWaveData[i] = new System.Drawing.PointF(listWaveDataSeriesCopy[index].listWaveData[i].X,
  269. listWaveDataSeriesCopy[index].listWaveData[i].Y + offsetAmp);
  270. }
  271. }
  272. uCChanLabel.CurrentCursorLocation = ucChanLabel_CursorY2.Location.Y / (panel_Left.Height * 1.0);
  273. Drawing(listWaveDataSeriesCopy);
  274. }
  275. }
  276. private void UCChanLabel_MouseMove(object sender, MouseEventArgs e) {
  277. var uCChanLabel = (UCChanLabel)sender;
  278. if (uCChanLabel.IsChanLabelMouseDown) {
  279. uCChanLabel.Location = new Point(uCChanLabel.Location.X, uCChanLabel.Location.Y + (e.Y - uCChanLabel.AyChanLabel));
  280. if (uCChanLabel.Location.Y <= 0) {
  281. uCChanLabel.Location = new Point(uCChanLabel.Location.X, 0);
  282. }
  283. if (uCChanLabel.Location.Y >= this.panel_Left.Height - uCChanLabel.Height) {
  284. uCChanLabel.Location = new Point(uCChanLabel.Location.X, this.panel_Left.Height - uCChanLabel.Height);
  285. }
  286. }
  287. }
  288. private void UCChanLabel_MouseDown(object sender, MouseEventArgs e) {
  289. if (e.Button == MouseButtons.Left) {
  290. var ucChanLabel = (UCChanLabel)sender;
  291. ucChanLabel.IsChanLabelMouseDown = true;
  292. ucChanLabel.AxChanLable = e.X;
  293. ucChanLabel.AyChanLabel = e.Y;
  294. }
  295. }
  296. #endregion
  297. #region 事件:Mark显示
  298. /// <summary>
  299. /// 显示X轴光标
  300. /// </summary>
  301. /// <param name="sender"></param>
  302. /// <param name="e"></param>
  303. private void iconMenuItem_XCursor_Click(object sender, EventArgs e) {
  304. paintPara.bCursorXShow = !paintPara.bCursorXShow;
  305. this.ucChanLabelVertical_CursorX1.Visible = paintPara.bCursorXShow;
  306. this.ucChanLabelVertical_CursorX2.Visible = paintPara.bCursorXShow;
  307. this.pictureBox_DrawRect.Refresh();//触发pictureBox_DrawRect的Painting事件
  308. }
  309. /// <summary>
  310. /// 显示XY轴测量信息
  311. /// </summary>
  312. /// <param name="sender"></param>
  313. /// <param name="e"></param>
  314. private void iconMenuItem_MesInfoXY_Click(object sender, EventArgs e) {
  315. paintPara.bCursorXYMesInfo = !paintPara.bCursorXYMesInfo;
  316. this.ucCursorInfo_XY.Visible = paintPara.bCursorXYMesInfo;
  317. }
  318. /// <summary>
  319. /// 显示Y轴光标
  320. /// </summary>
  321. /// <param name="sender"></param>
  322. /// <param name="e"></param>
  323. private void iconMenuItem_YCursor_Click(object sender, EventArgs e) {
  324. paintPara.bCursorYShow = !paintPara.bCursorYShow;
  325. this.ucChanLabel_CursorY1.Visible = paintPara.bCursorYShow;
  326. this.ucChanLabel_CursorY2.Visible = paintPara.bCursorYShow;
  327. this.pictureBox_DrawRect.Refresh();//触发pictureBox_DrawRect的Painting事件
  328. }
  329. #endregion
  330. #region 事件:顶层PictureBox绘制
  331. /// <summary>
  332. /// 顶层pictureBox绘制事件
  333. /// </summary>
  334. /// <param name="sender"></param>
  335. /// <param name="e"></param>
  336. private void pictureBox_DrawRect_Paint(object sender, PaintEventArgs e) {
  337. if (paintPara.bDrawStart & paintPara.bEnlagerClick) {
  338. Pen pen = new Pen(Color.White, 1f);
  339. pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
  340. //实时的画矩形
  341. int w = paintPara.PointContinue.X - paintPara.PointStart.X;
  342. int h = paintPara.PointContinue.Y - paintPara.PointStart.Y;
  343. Rectangle rect = new Rectangle(paintPara.PointStart, new Size(w, h));
  344. e.Graphics.DrawRectangle(pen, rect);
  345. pen.Dispose();
  346. }
  347. Pen penCursor = new Pen(Color.GreenYellow, 1f);
  348. penCursor.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom; //虚线
  349. penCursor.DashPattern = new float[] { 2, 2 };
  350. if (paintPara.bCursorYShow) {
  351. e.Graphics.DrawLine(penCursor,
  352. 0,
  353. ucChanLabel_CursorY1.Location.Y + ucChanLabel_CursorY1.Height / 2,
  354. pictureBox_DrawRect.ClientRectangle.Width,
  355. ucChanLabel_CursorY1.Location.Y + ucChanLabel_CursorY1.Height / 2);
  356. e.Graphics.DrawLine(penCursor,
  357. 0,
  358. ucChanLabel_CursorY2.Location.Y + ucChanLabel_CursorY2.Height / 2,
  359. pictureBox_DrawRect.ClientRectangle.Width,
  360. ucChanLabel_CursorY2.Location.Y + ucChanLabel_CursorY2.Height / 2);
  361. }
  362. if (paintPara.bCursorXShow) {
  363. e.Graphics.DrawLine(penCursor,
  364. ucChanLabelVertical_CursorX1.Location.X + ucChanLabelVertical_CursorX1.Width / 2,
  365. 0,
  366. ucChanLabelVertical_CursorX1.Location.X + ucChanLabelVertical_CursorX1.Width / 2,
  367. pictureBox_DrawRect.ClientRectangle.Height);
  368. e.Graphics.DrawLine(penCursor,
  369. ucChanLabelVertical_CursorX2.Location.X + ucChanLabelVertical_CursorX2.Width / 2,
  370. 0,
  371. ucChanLabelVertical_CursorX2.Location.X + ucChanLabelVertical_CursorX2.Width / 2,
  372. pictureBox_DrawRect.ClientRectangle.Height);
  373. }
  374. penCursor.Dispose();
  375. }
  376. /// <summary>
  377. /// pictureBox_DrawRect鼠标点击事件
  378. /// </summary>
  379. /// <param name="sender"></param>
  380. /// <param name="e"></param>
  381. private void pictureBox_DrawRect_MouseDown(object sender, MouseEventArgs e) {
  382. if (paintPara.bEnlagerClick && e.Button == MouseButtons.Left) {
  383. paintPara.bDrawStart = true;
  384. paintPara.PointStart = e.Location;
  385. }
  386. }
  387. /// <summary>
  388. /// pictureBox_DrawRect鼠标移动事件
  389. /// </summary>
  390. /// <param name="sender"></param>
  391. /// <param name="e"></param>
  392. private void pictureBox_DrawRect_MouseMove(object sender, MouseEventArgs e) {
  393. if (paintPara.bDrawStart) {
  394. paintPara.PointContinue = e.Location;
  395. pictureBox_DrawRect.Invalidate();
  396. }
  397. }
  398. private void pictureBox_DrawRect_MouseUp(object sender, MouseEventArgs e) {
  399. paintPara.bDrawStart = false;
  400. this.pictureBox_DrawRect.Invalidate();
  401. /*重新构建显示的数据*/
  402. int width = pictureBox_Wave.Width;
  403. int height = pictureBox_Wave.Height;
  404. int w = paintPara.PointContinue.X - paintPara.PointStart.X;
  405. if ((w <= 1) || (width < w)) {
  406. paintPara.PointStart = Point.Empty;
  407. paintPara.PointContinue = Point.Empty;
  408. return;
  409. }
  410. int h = paintPara.PointContinue.Y - paintPara.PointStart.Y;
  411. if ((height < h) || (h <= 0)) {
  412. paintPara.PointStart = Point.Empty;
  413. paintPara.PointContinue = Point.Empty;
  414. return;
  415. }
  416. if (dataManager.listWaveDataSeries.Count == 0) {
  417. return;
  418. }
  419. float factorStart = (float)paintPara.PointStart.X / (float)width;
  420. float factorContinue = (float)paintPara.PointContinue.X / (float)width;
  421. paintPara.MinValueX = factorStart * (paintPara.MaxValueX - paintPara.MinValueX);
  422. paintPara.MaxValueX = factorContinue * (paintPara.MaxValueX - paintPara.MinValueX);
  423. int PaintingScreen = paintPara.IndexXFinish - paintPara.IndexXStart;
  424. paintPara.IndexXStart = (int)(factorStart * PaintingScreen);
  425. paintPara.IndexXFinish = (int)(factorContinue * PaintingScreen);
  426. if(paintPara.IndexXFinish>paintPara.IndexXStart) {
  427. Drawing(listWaveDataSeriesCopy);
  428. RefreshControl(listWaveDataSeriesCopy);
  429. }
  430. paintPara.PointStart = Point.Empty;
  431. paintPara.PointContinue = Point.Empty;
  432. }
  433. /// <summary>
  434. /// 点击放大框
  435. /// </summary>
  436. /// <param name="sender"></param>
  437. /// <param name="e"></param>
  438. private void iconToolStripButton_Enlager_Click(object sender, EventArgs e) {
  439. if (paintPara.bEnlagerClick == false) {
  440. paintPara.bEnlagerClick = true;
  441. iconToolStripButton_Enlager.IconColor = Color.Red;
  442. this.pictureBox_Wave.Cursor = Cursors.Hand;
  443. }
  444. else {
  445. paintPara.bEnlagerClick = false;
  446. iconToolStripButton_Enlager.IconColor = Color.White;
  447. this.pictureBox_Wave.Cursor = Cursors.Default;
  448. }
  449. }
  450. #region 事件:双击pictureBox还原波形
  451. private void pictureBox_DrawRect_MouseDoubleClick(object sender, MouseEventArgs e) {
  452. paintPara.IndexXStart = 0;
  453. paintPara.IndexXFinish = listWaveDataSeriesCopy[0].listWaveData.Count;
  454. paintPara.MinValueX = paintPara.MinValueXOrig;
  455. paintPara.MaxValueX = paintPara.MaxValueXOrig;
  456. if (paintPara.IndexXFinish > paintPara.IndexXStart) {
  457. Drawing(listWaveDataSeriesCopy);
  458. RefreshControl(listWaveDataSeriesCopy);
  459. }
  460. }
  461. #endregion
  462. #endregion
  463. #region 事件:XY光标移动事件
  464. /// <summary>
  465. /// 光标Y1移动操作
  466. /// </summary>
  467. /// <param name="sender"></param>
  468. /// <param name="e"></param>
  469. private void ucChanLabel_CursorY1_MouseDown(object sender, MouseEventArgs e) {
  470. if (e.Button == MouseButtons.Left) {
  471. this.ucChanLabel_CursorY1.IsChanLabelMouseDown = true;
  472. this.ucChanLabel_CursorY1.AxChanLable = e.X;
  473. this.ucChanLabel_CursorY1.AyChanLabel = e.Y;
  474. }
  475. }
  476. private void ucChanLabel_CursorY1_MouseMove(object sender, MouseEventArgs e) {
  477. if (this.ucChanLabel_CursorY1.IsChanLabelMouseDown) {
  478. ucChanLabel_CursorY1.Location = new Point(ucChanLabel_CursorY1.Location.X, ucChanLabel_CursorY1.Location.Y + (e.Y - this.ucChanLabel_CursorY1.AyChanLabel));
  479. if (ucChanLabel_CursorY1.Location.Y <= 0) {
  480. ucChanLabel_CursorY1.Location = new Point(ucChanLabel_CursorY1.Location.X, 0);
  481. }
  482. if (ucChanLabel_CursorY1.Location.Y >= this.panel_Left.Height - ucChanLabel_CursorY1.Height) {
  483. ucChanLabel_CursorY1.Location = new Point(ucChanLabel_CursorY1.Location.X, this.panel_Left.Height - ucChanLabel_CursorY1.Height);
  484. }
  485. pictureBox_DrawRect.Invalidate();
  486. // 更新光标显示
  487. double y1 = paintPara.VertScale - ((ucChanLabel_CursorY1.Location.Y + ucChanLabel_CursorY1.Height / 2) / (panel_Left.Height * 1.0)) * paintPara.VertScale + paintPara.MinValueY;
  488. double y2 = paintPara.VertScale - ((ucChanLabel_CursorY2.Location.Y + ucChanLabel_CursorY2.Height / 2) / (panel_Left.Height * 1.0)) * paintPara.VertScale + paintPara.MinValueY;
  489. double x1 = ((ucChanLabelVertical_CursorX1.Location.X + ucChanLabelVertical_CursorX1.Width / 2) / (this.panel_Bottom.Width * 1.0)) * paintPara.VertScale + paintPara.MinValueX;
  490. double x2 = ((ucChanLabelVertical_CursorX2.Location.X + ucChanLabelVertical_CursorX2.Width / 2) / (this.panel_Bottom.Width * 1.0)) * paintPara.VertScale + paintPara.MinValueX;
  491. ucCursorInfo_XY.update_CursorResult(x1, x2, y1, y2);
  492. }
  493. }
  494. private void ucChanLabel_CursorY1_MouseUp(object sender, MouseEventArgs e) {
  495. if (e.Button == MouseButtons.Left) {
  496. this.ucChanLabel_CursorY1.IsChanLabelMouseDown = false;
  497. this.ucChanLabel_CursorY1.CurrentCursorLocation = ucChanLabel_CursorY1.Location.Y / (panel_Left.Height * 1.0);
  498. }
  499. }
  500. private void ucChanLabel_CursorY2_MouseDown(object sender, MouseEventArgs e) {
  501. if (e.Button == MouseButtons.Left) {
  502. this.ucChanLabel_CursorY2.IsChanLabelMouseDown = true;
  503. this.ucChanLabel_CursorY2.AxChanLable = e.X;
  504. this.ucChanLabel_CursorY2.AyChanLabel = e.Y;
  505. }
  506. }
  507. private void ucChanLabel_CursorY2_MouseMove(object sender, MouseEventArgs e) {
  508. if (this.ucChanLabel_CursorY2.IsChanLabelMouseDown) {
  509. ucChanLabel_CursorY2.Location = new Point(ucChanLabel_CursorY2.Location.X, ucChanLabel_CursorY2.Location.Y + (e.Y - this.ucChanLabel_CursorY2.AyChanLabel));
  510. if (ucChanLabel_CursorY2.Location.Y <= 0) {
  511. ucChanLabel_CursorY2.Location = new Point(ucChanLabel_CursorY2.Location.X, 0);
  512. }
  513. if (ucChanLabel_CursorY2.Location.Y >= this.panel_Left.Height - ucChanLabel_CursorY2.Height) {
  514. ucChanLabel_CursorY2.Location = new Point(ucChanLabel_CursorY2.Location.X, this.panel_Left.Height - ucChanLabel_CursorY2.Height);
  515. }
  516. pictureBox_DrawRect.Invalidate();
  517. // 更新光标显示
  518. double y1 = paintPara.VertScale - ((ucChanLabel_CursorY1.Location.Y + ucChanLabel_CursorY1.Height / 2) / (panel_Left.Height * 1.0)) * paintPara.VertScale + paintPara.MinValueY;
  519. double y2 = paintPara.VertScale - ((ucChanLabel_CursorY2.Location.Y + ucChanLabel_CursorY2.Height / 2) / (panel_Left.Height * 1.0)) * paintPara.VertScale + paintPara.MinValueY;
  520. double x1 = ((ucChanLabelVertical_CursorX1.Location.X + ucChanLabelVertical_CursorX1.Width / 2) / (this.panel_Bottom.Width * 1.0)) * paintPara.HoriScale + paintPara.MinValueX;
  521. double x2 = ((ucChanLabelVertical_CursorX2.Location.X + ucChanLabelVertical_CursorX2.Width / 2) / (this.panel_Bottom.Width * 1.0)) * paintPara.HoriScale + paintPara.MinValueX;
  522. ucCursorInfo_XY.update_CursorResult(x1, x2, y1, y2);
  523. }
  524. }
  525. private void ucChanLabel_CursorY2_MouseUp(object sender, MouseEventArgs e) {
  526. if (e.Button == MouseButtons.Left) {
  527. this.ucChanLabel_CursorY2.IsChanLabelMouseDown = false;
  528. this.ucChanLabel_CursorY2.CurrentCursorLocation = ucChanLabel_CursorY2.Location.Y / (panel_Left.Height * 1.0);
  529. }
  530. }
  531. private void ucChanLabelVertical_CursorX1_MouseDown(object sender, MouseEventArgs e) {
  532. if (e.Button == MouseButtons.Left) {
  533. this.ucChanLabelVertical_CursorX1.IsChanLabelMouseDown = true;
  534. this.ucChanLabelVertical_CursorX1.AxChanLable = e.X;
  535. this.ucChanLabelVertical_CursorX1.AyChanLabel = e.Y;
  536. }
  537. }
  538. private void ucChanLabelVertical_CursorX1_MouseMove(object sender, MouseEventArgs e) {
  539. if (this.ucChanLabelVertical_CursorX1.IsChanLabelMouseDown) {
  540. ucChanLabelVertical_CursorX1.Location = new Point(ucChanLabelVertical_CursorX1.Location.X + (e.X - this.ucChanLabelVertical_CursorX1.AxChanLable), ucChanLabelVertical_CursorX1.Location.Y);
  541. if (ucChanLabelVertical_CursorX1.Location.X <= 0) {
  542. ucChanLabelVertical_CursorX1.Location = new Point(0, ucChanLabelVertical_CursorX1.Location.Y);
  543. }
  544. if (ucChanLabelVertical_CursorX1.Location.X >= this.panel_Bottom.Width - ucChanLabelVertical_CursorX1.Width) {
  545. ucChanLabelVertical_CursorX1.Location = new Point(this.panel_Bottom.Width - ucChanLabelVertical_CursorX1.Width, ucChanLabelVertical_CursorX1.Location.Y);
  546. }
  547. pictureBox_DrawRect.Invalidate();
  548. // 更新光标显示
  549. double y1 = paintPara.VertScale - ((ucChanLabel_CursorY1.Location.Y + ucChanLabel_CursorY1.Height / 2) / (panel_Left.Height * 1.0)) * paintPara.VertScale + paintPara.MinValueY;
  550. double y2 = paintPara.VertScale - ((ucChanLabel_CursorY2.Location.Y + ucChanLabel_CursorY2.Height / 2) / (panel_Left.Height * 1.0)) * paintPara.VertScale + paintPara.MinValueY;
  551. double x1 = ((ucChanLabelVertical_CursorX1.Location.X + ucChanLabelVertical_CursorX1.Width / 2) / (this.panel_Bottom.Width * 1.0)) * paintPara.HoriScale + paintPara.MinValueX;
  552. double x2 = ((ucChanLabelVertical_CursorX2.Location.X + ucChanLabelVertical_CursorX2.Width / 2) / (this.panel_Bottom.Width * 1.0)) * paintPara.HoriScale + paintPara.MinValueX;
  553. ucCursorInfo_XY.update_CursorResult(x1, x2, y1, y2);
  554. }
  555. }
  556. private void ucChanLabelVertical_CursorX1_MouseUp(object sender, MouseEventArgs e) {
  557. if (e.Button == MouseButtons.Left) {
  558. this.ucChanLabelVertical_CursorX1.IsChanLabelMouseDown = false;
  559. this.ucChanLabelVertical_CursorX1.CurrentCursorLocation = ucChanLabelVertical_CursorX1.Location.X / (panel_Bottom.Width * 1.0);
  560. }
  561. }
  562. private void ucChanLabelVertical_CursorX2_MouseDown(object sender, MouseEventArgs e) {
  563. if (e.Button == MouseButtons.Left) {
  564. this.ucChanLabelVertical_CursorX2.IsChanLabelMouseDown = true;
  565. this.ucChanLabelVertical_CursorX2.AxChanLable = e.X;
  566. this.ucChanLabelVertical_CursorX2.AyChanLabel = e.Y;
  567. }
  568. }
  569. private void ucChanLabelVertical_CursorX2_MouseMove(object sender, MouseEventArgs e) {
  570. if (this.ucChanLabelVertical_CursorX2.IsChanLabelMouseDown) {
  571. ucChanLabelVertical_CursorX2.Location = new Point(ucChanLabelVertical_CursorX2.Location.X + (e.X - this.ucChanLabelVertical_CursorX2.AxChanLable), ucChanLabelVertical_CursorX2.Location.Y);
  572. if (ucChanLabelVertical_CursorX2.Location.X <= 0) {
  573. ucChanLabelVertical_CursorX2.Location = new Point(0, ucChanLabelVertical_CursorX2.Location.Y);
  574. }
  575. if (ucChanLabelVertical_CursorX2.Location.X >= this.panel_Bottom.Width - ucChanLabelVertical_CursorX2.Width) {
  576. ucChanLabelVertical_CursorX2.Location = new Point(this.panel_Bottom.Width - ucChanLabelVertical_CursorX2.Width, ucChanLabelVertical_CursorX2.Location.Y);
  577. }
  578. pictureBox_DrawRect.Invalidate();
  579. // 更新光标显示
  580. double y1 = paintPara.VertScale - ((ucChanLabel_CursorY1.Location.Y + ucChanLabel_CursorY1.Height / 2) / (panel_Left.Height * 1.0)) * paintPara.VertScale + paintPara.MinValueY;
  581. double y2 = paintPara.VertScale - ((ucChanLabel_CursorY2.Location.Y + ucChanLabel_CursorY2.Height / 2) / (panel_Left.Height * 1.0)) * paintPara.VertScale + paintPara.MinValueY;
  582. double x1 = ((ucChanLabelVertical_CursorX1.Location.X + ucChanLabelVertical_CursorX1.Width / 2) / (this.panel_Bottom.Width * 1.0)) * paintPara.HoriScale + paintPara.MinValueX;
  583. double x2 = ((ucChanLabelVertical_CursorX2.Location.X + ucChanLabelVertical_CursorX2.Width / 2) / (this.panel_Bottom.Width * 1.0)) * paintPara.HoriScale + paintPara.MinValueX;
  584. ucCursorInfo_XY.update_CursorResult(x1, x2, y1, y2);
  585. }
  586. }
  587. private void ucChanLabelVertical_CursorX2_MouseUp(object sender, MouseEventArgs e) {
  588. if (e.Button == MouseButtons.Left) {
  589. this.ucChanLabelVertical_CursorX2.IsChanLabelMouseDown = false;
  590. this.ucChanLabelVertical_CursorX2.CurrentCursorLocation = ucChanLabelVertical_CursorX2.Location.X / (panel_Bottom.Width * 1.0);
  591. }
  592. }
  593. private void ucCursorInfo_XY_MouseDown(object sender, MouseEventArgs e) {
  594. if (e.Button == MouseButtons.Left) {
  595. this.ucCursorInfo_XY.IsCursorResultMouseDown = true;
  596. this.ucCursorInfo_XY.AxCursorResult = e.X;
  597. this.ucCursorInfo_XY.AyCursorResult = e.Y;
  598. }
  599. }
  600. private void ucCursorInfo_XY_MouseMove(object sender, MouseEventArgs e) {
  601. if (this.ucCursorInfo_XY.IsCursorResultMouseDown) {
  602. ucCursorInfo_XY.Location = new Point(ucCursorInfo_XY.Location.X + (e.X - this.ucCursorInfo_XY.AxCursorResult), ucCursorInfo_XY.Location.Y + (e.Y - this.ucCursorInfo_XY.AxCursorResult));
  603. if (ucCursorInfo_XY.Location.X <= 0) {
  604. ucCursorInfo_XY.Location = new Point(0, ucCursorInfo_XY.Location.Y);
  605. }
  606. if (ucCursorInfo_XY.Location.X >= this.pictureBox_DrawRect.Width - ucCursorInfo_XY.Width) {
  607. ucCursorInfo_XY.Location = new Point(this.pictureBox_DrawRect.Width - ucCursorInfo_XY.Width, ucCursorInfo_XY.Location.Y);
  608. }
  609. if (ucCursorInfo_XY.Location.Y <= 0) {
  610. ucCursorInfo_XY.Location = new Point(ucCursorInfo_XY.Location.X, 0);
  611. }
  612. if (ucCursorInfo_XY.Location.Y >= this.pictureBox_DrawRect.Height - ucCursorInfo_XY.Height) {
  613. ucCursorInfo_XY.Location = new Point(ucCursorInfo_XY.Location.X, this.pictureBox_DrawRect.Height - ucCursorInfo_XY.Height);
  614. }
  615. }
  616. }
  617. private void ucCursorInfo_XY_MouseUp(object sender, MouseEventArgs e) {
  618. if (e.Button == MouseButtons.Left) {
  619. this.ucCursorInfo_XY.IsCursorResultMouseDown = false;
  620. }
  621. }
  622. #endregion
  623. #region 事件:波形复原,根据偏移值算点
  624. private void iconMenuItem_All_Click(object sender, EventArgs e) {
  625. /*更新显示的偏移值*/
  626. foreach (var item in listWaveDataSeriesCopy) {
  627. int index = 0;
  628. if (item.listWaveData[0].Y != item.offSetOrig[0].Y) {
  629. float pos = item.listWaveData[0].Y - item.offSetOrig[0].Y;
  630. for (int i = 0; i < item.listWaveData.Count; i++) {
  631. item.listWaveData[i] = new System.Drawing.PointF(item.listWaveData[i].X,
  632. item.listWaveData[i].Y-pos);
  633. }
  634. }
  635. index++;
  636. }
  637. RefreshControl(listWaveDataSeriesCopy);
  638. Drawing(listWaveDataSeriesCopy);
  639. }
  640. //类可序列化[Serializable]
  641. public static T Clone<T>(T RealObject) {
  642. using (Stream objectStream = new MemoryStream()) {
  643. //利用 System.Runtime.Serialization序列化与反序列化完成引用对象的复制
  644. IFormatter formatter = new BinaryFormatter();
  645. formatter.Serialize(objectStream, RealObject);
  646. objectStream.Seek(0, SeekOrigin.Begin);
  647. return (T)formatter.Deserialize(objectStream);
  648. }
  649. }
  650. #endregion
  651. #region 事件:加载波形数据(需实现dataManager.ReadData()方法
  652. private void iconToolStripButton_Load_Click(object sender, EventArgs e) {
  653. //清空显示
  654. RemoveControl(listWaveDataSeriesCopy);
  655. //读取数据
  656. listWaveDataSeriesCopy.Clear();
  657. //初始化
  658. Init();
  659. dataManager.ReadData();
  660. listWaveDataSeriesCopy = dataManager.listWaveDataSeries;
  661. paintPara.IndexXStart = 0;
  662. paintPara.IndexXFinish = listWaveDataSeriesCopy[0].listWaveData.Count;
  663. Drawing(listWaveDataSeriesCopy);
  664. AddTagControl(listWaveDataSeriesCopy);
  665. }
  666. #endregion
  667. #region 事件:半峰高对齐
  668. private void iconToolStripButton_Align_Click(object sender, EventArgs e) {
  669. }
  670. #endregion
  671. #region 事件:归一化显示
  672. private void iconToolStripButton_Normalization_Click(object sender, EventArgs e) {
  673. }
  674. #endregion
  675. }
  676. }

波形参数

using CBB_Saker_Painting_1._0._0.Global;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

namespace CBB_Saker_Painting_1._0._0 {
    public class PaintPara {

        #region 绘图属性
        private float maxValueY;

        public float MaxValueY {
            get { return maxValueY; }
            set { maxValueY = value; }
        }

        private float minValueY;

        public float MinValueY {
            get { return minValueY; }
            set { minValueY = value; }
        }

        private double minValueX;

        public double MinValueX {
            get { return minValueX; }
            set { minValueX = value; }
        }

        private double maxValueX;

        public double MaxValueX {
            get { return maxValueX; }
            set { maxValueX = value; }
        }

        /// <summary>
        /// 垂直范围
        /// </summary>
        private float vertScale;

        public float VertScale {
            get { return (MaxValueY - MinValueY); }
            set { vertScale = value; }
        }

        /// <summary>
        /// 水平范围
        /// </summary>
        private double horiScale;

        public double HoriScale {
            get { return (MaxValueX - MinValueX); }
            set { horiScale = value; }
        }


        /// <summary>
        /// Y顶部
        /// </summary>
        private string strtopY;

        public string strTopY {
            get { return Voltage2String(MaxValueY); }
            set { strtopY = value; }
        }

        /// <summary>
        /// Y底部
        /// </summary>
        private string strbottomY;

        public string strBottomY {
            get { return Voltage2String(MinValueY); }
            set { strbottomY = value; }
        }

        /// <summary>
        /// X轴最右侧
        /// </summary>
        private string horizRight;

        public string HorizRight {
            get { return Time2String(MaxValueX); }
            set { horizRight = value; }
        }

        /// <summary>
        /// 线条颜色
        /// </summary>
        private Color lineColor;

        public Color LineColor {
            get { return lineColor; }
            set { lineColor = value; }
        }

        /// <summary>
        /// 纵轴等分数量
        /// </summary>
        private float bisectrixY;

        public float BisectrixY {
            get { return bisectrixY; }
            set { bisectrixY = value; }
        }

        /// <summary>
        /// 横轴等分数量
        /// </summary>
        private float bisectrixX;

        public float BisectrixX {
            get { return bisectrixX; }
            set { bisectrixX = value; }
        }


        /// <summary>
        /// X轴点的个数
        /// </summary>
        private int xScaleCount;

        public int XScaleCount {
            get { return xScaleCount; }
            set { xScaleCount = value; }
        }

        /// <summary>
        /// Y轴点的个数
        /// </summary>
        private int yScaleCount =256;

        public int YScaleCount {
            get { return yScaleCount; }
            set { yScaleCount = value; }
        }

        /// <summary>
        /// 垂直间距像素
        /// </summary>
        private float verticalBetween;

        public float VerticalBetween {
            get { return CharHeight/YScaleCount; }
            set { verticalBetween = value; }
        }

        /// <summary>
        /// 水平间距像素
        /// </summary>
        private float horizontalBetween;

        public float HorizontalBetween {
            get { return CharWidth / XScaleCount; }
            set { horizontalBetween = value; }
        }

        /// <summary>
        /// 图表区域宽度
        /// </summary>
        private float charWidth;

        public float CharWidth {
            get { return charWidth; }
            set { charWidth = value; }
        }

        /// <summary>
        /// 图表区域高度
        /// </summary>
        private float charHeight;

        public float CharHeight {
            get { return charHeight; }
            set { charHeight = value; }
        }

        /// <summary>
        /// Y轴每个间隔值
        /// </summary>
        private float intervalValueY;

        public float IntervalValueY {
            get { return VertScale/YScaleCount; }
            set { intervalValueY = value; }
        }

        /// <summary>
        /// 画图区域起点
        /// </summary>
        private PointF startPosition;

        public PointF StartPosition {
            get { return new PointF(0,0); }
            set { startPosition = value; }
        }

        /// <summary>
        /// 画图区域终点
        /// </summary>
        private PointF endPosition;

        public PointF EndPosition {
            get { return new PointF(CharWidth, CharHeight); }
            set { endPosition = value; }
        }
        public bool bYMarking { get; set; }//是否显示Y轴标志
        public bool bDrawGridLineY { get; set; }// 是否绘制Y轴的刻度线
        public bool bXMarking { get; set; }//是否显示X轴标志
        public bool bDrawGridLineX { get; set; }//是否绘制X轴的刻度线
        public List<Bitmap> listImages = new List<Bitmap>();//图层链表
        #endregion

        #region 波形放大相关参数
        /// <summary>
        /// 波形放大标志
        /// </summary>
        private bool benlagerClick;

        public bool bEnlagerClick {
            get { return benlagerClick; }
            set { benlagerClick = value; }
        }

        /// <summary>
        /// 开始绘制
        /// </summary>
        private bool bdrawStart;

        public bool bDrawStart {
            get { return bdrawStart; }
            set { bdrawStart = value; }
        }

        public Point PointStart { get; set; }
        public Point PointContinue { get; set; }

        #endregion

        #region XY光标参数
        public bool bCursorXShow { get; set; } //显示X轴光标
        public bool bCursorYShow { get; set; }//显示Y轴光标
        public bool bCursorXYMesInfo { get; set; }//XY轴光标测量信息
        #endregion



        #region 方法:处理横纵轴坐标
        public static string Voltage2String(double value) {
            string str = "";
            if (Math.Abs(value) >= 1.0) {
                if (Math.Abs(value) / 1000000.0 >= 1.0) {
                    str = Math.Round(value / 1000000.0, 2).ToString() + CGlobalString.STR_VOLTAGE_M_V;
                }
                else if (Math.Abs(value) / 1000.0 >= 1.0) {
                    str = Math.Round(value / 1000.0, 2).ToString() + CGlobalString.STR_VOLTAGE_KV;
                }
                else {
                    str = Math.Round(value, 2).ToString() + CGlobalString.STR_VOLTAGE_V;
                }
            }
            else if (Math.Abs(value) * 1000 >= 1.0) {
                if (Math.Abs(value) * 1000 >= 100) {
                    str = Math.Round(value * 1000, 0).ToString() + CGlobalString.STR_VOLTAGE_MV;
                }
                else if (Math.Abs(value) * 1000 >= 10) {
                    str = Math.Round(value * 1000, 1).ToString() + CGlobalString.STR_VOLTAGE_MV;
                }
                else {
                    str = Math.Round(value * 1000, 2).ToString() + CGlobalString.STR_VOLTAGE_MV;
                }
            }
            else if (Math.Abs(value) * 1000000 >= 1.0) {
                if (Math.Abs(value) * 1000000 >= 100) {
                    str = Math.Round(value * 1000, 0).ToString() + CGlobalString.STR_VOLTAGE_UV;
                }
                else if (Math.Abs(value) * 1000000 >= 10) {
                    str = Math.Round(value * 1000, 1).ToString() + CGlobalString.STR_VOLTAGE_UV;
                }
                else {
                    str = Math.Round(value * 1000, 2).ToString() + CGlobalString.STR_VOLTAGE_UV;
                }
            }
            else {
                str = "0.00" + CGlobalString.STR_VOLTAGE_V;
            }
            return str;
        }
        public static string Time2String(double value) {
            string strTime = "";
            if (Math.Abs(value) >= 1.0) {
                strTime = Math.Round(value, 2).ToString() + CGlobalString.STR_TIME_S;
            }
            else if (Math.Abs(value) * 1000 >= 1.0) {
                if (Math.Abs(value) * 1000 >= 100) {
                    strTime = Math.Round(value * 1000, 0).ToString() + CGlobalString.STR_TIME_MS;
                }
                else if (Math.Abs(value) * 1000 >= 10) {
                    strTime = Math.Round(value * 1000, 1).ToString() + CGlobalString.STR_TIME_MS;
                }
                else {
                    strTime = Math.Round(value * 1000, 2).ToString() + CGlobalString.STR_TIME_MS;
                }
            }
            else if (Math.Abs(value) * 1000000 >= 1.0) {
                if (Math.Abs(value) * 1000000 >= 100) {
                    strTime = Math.Round(value * 1000000, 6).ToString() + CGlobalString.STR_TIME_US;
                }
                else if (Math.Abs(value) * 1000000 >= 10) {
                    strTime = Math.Round(value * 1000000, 6).ToString() + CGlobalString.STR_TIME_US;
                }
                else {
                    strTime = Math.Round(value * 1000000, 6).ToString() + CGlobalString.STR_TIME_US;
                }
            }
            else if (Math.Abs(value) * 1000000000 >= 1.0) {
                if (Math.Abs(value) * 1000000000 >= 100) {
                    strTime = Math.Round(value * 1000000000, 3).ToString() + CGlobalString.STR_TIME_NS;
                }
                else if (Math.Abs(value) * 1000000000 >= 10) {
                    strTime = Math.Round(value * 1000000000, 3).ToString() + CGlobalString.STR_TIME_NS;
                }
                else {
                    strTime = Math.Round(value * 1000000000, 3).ToString() + CGlobalString.STR_TIME_NS;
                }
            }
            else if (Math.Abs(value) * 1000000000000 >= 1.0) {
                if (Math.Abs(value) * 1000000000000 >= 100) {
                    strTime = Math.Round(value * 1000000000000, 0).ToString() + CGlobalString.STR_TIME_PS;
                }
                else if (Math.Abs(value) * 1000000000000 >= 10) {
                    strTime = Math.Round(value * 1000000000000, 1).ToString() + CGlobalString.STR_TIME_PS;
                }
                else {
                    strTime = Math.Round(value * 1000000000000, 2).ToString() + CGlobalString.STR_TIME_PS;
                }
            }
            else {
                strTime = "0.00s";
            }
            return strTime;
        }
        public void Init(float pictureWidth, float pictureHeight) {
            this.MinValueY = -10;
            this.MaxValueY = 10;
            this.MinValueX = 0;
            this.MaxValueX = 10;
            this.BisectrixY = 8.0f;//分为8份
            this.bisectrixX = 10.0f;//分为10份
            this.bYMarking = true;//显示Y轴标志
            this.bXMarking = true;//显示X轴标志
            this.bDrawGridLineX = true;//绘制X轴的刻度线
            this.bDrawGridLineY = true;//绘制Y轴的刻度线
            this.bCursorXShow = true;//X光标默认显示
            this.bCursorYShow = true;//Y光标默认显示
            this.bCursorXYMesInfo = true;//XY轴测量信息
            this.CharHeight = pictureHeight;//绘图区域
            this.CharWidth = pictureWidth;//绘图区域
        }
        #endregion
    }
}

jsonTranexcel.gif