SRLinesForm.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.IO;
  7. using System.Drawing;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Windows.Forms;
  11. using System.Runtime.InteropServices;
  12. namespace PaintDotNet.Instrument
  13. {
  14. public partial class SRLinesForm : Form
  15. {
  16. private System.Windows.Forms.PictureBox pictureBox1;
  17. public SRLinesForm()
  18. {
  19. InitializeComponent();
  20. this.Load += new EventHandler(SRLinesForm_Load);
  21. }
  22. /// <summary>
  23. /// Required method for Designer support - do not modify
  24. /// the contents of this method with the code editor.
  25. /// </summary>
  26. private void InitializeComponent()
  27. {
  28. this.pictureBox1 = new System.Windows.Forms.PictureBox();
  29. ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
  30. this.SuspendLayout();
  31. //
  32. // pictureBox1
  33. //
  34. this.pictureBox1.Location = new System.Drawing.Point(1, 2);
  35. this.pictureBox1.Name = "pictureBox1";
  36. this.pictureBox1.Size = new System.Drawing.Size(1101, 351);
  37. this.pictureBox1.TabIndex = 0;
  38. this.pictureBox1.TabStop = false;
  39. this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click);
  40. //
  41. // SRLinesForm
  42. //
  43. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
  44. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  45. this.ClientSize = new System.Drawing.Size(1105, 355);
  46. this.Controls.Add(this.pictureBox1);
  47. this.Name = "SRLinesForm";
  48. this.Text = "剖面线";
  49. this.Load += new System.EventHandler(this.SRLinesForm_Load_1);
  50. ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
  51. this.ResumeLayout(false);
  52. }
  53. //string resultFile;
  54. //private Point mouseOffset;
  55. //bool flag = false;
  56. ToolTip tooltip = new ToolTip();
  57. int[] bufx = new int[1024];
  58. int[] bufy = new int[1024];
  59. //int drawflag = 0;
  60. //int readlen = 0;
  61. //zzz
  62. public const int LINE_PNTS = 100;
  63. public int m_iYVCount = 10;
  64. public double m_dYVMax = 51;
  65. public double m_dYVMin = -51;
  66. public double[] m_adValue = new double[LINE_PNTS];
  67. public int m_iYPixelMax = 350;
  68. public int m_iYPixelMin = 40;
  69. public int m_iXPixelMax = 1100;
  70. public int m_iXPixelMin = 60;
  71. // x1,y1为鼠标移动的坐标,画十字线用,xbuf,ybuf绘制点坐标数组
  72. void draw(int x1, int y1, int[] xbuf, int[] ybuf)
  73. {
  74. //定义画布大小
  75. int height = m_iYPixelMax, width = m_iXPixelMax;
  76. //创建位图
  77. System.Drawing.Bitmap image = new System.Drawing.Bitmap(width, height);
  78. //创建Graphics类对象
  79. Graphics g = Graphics.FromImage(image);
  80. //清空图片背景色
  81. g.Clear(Color.White);
  82. Font font = new System.Drawing.Font("Arial", 9, FontStyle.Regular);
  83. Font font1 = new System.Drawing.Font("宋体", 20, FontStyle.Regular);
  84. Font font2 = new System.Drawing.Font("Arial", 8, FontStyle.Regular);
  85. System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Blue, Color.Blue, 1.2f, true);
  86. g.FillRectangle(Brushes.SeaGreen, 0, 0, width, height);
  87. Brush brush1 = new SolidBrush(Color.Blue);
  88. Brush brush2 = new SolidBrush(Color.SaddleBrown);
  89. //画图片的边框线
  90. g.DrawRectangle(new Pen(Color.Black), m_iXPixelMin, m_iYPixelMin, (LINE_PNTS - 1) * 10, 270);
  91. g.DrawRectangle(new Pen(Color.Black), m_iXPixelMin, m_iYPixelMin - 5, (LINE_PNTS - 1) * 10, 275);
  92. System.Drawing.Pen mypen = new Pen(brush, 1);
  93. System.Drawing.Pen mypen2 = new Pen(Color.Red, 2);
  94. System.Drawing.Pen mypen3 = new Pen(Color.Yellow, 1);
  95. //绘制线条
  96. //绘制纵向线条
  97. int x = m_iXPixelMin;
  98. for (int i = 0; i < 9; i++)
  99. {
  100. x = x + 100;
  101. g.DrawLine(mypen, x, 40, x, m_iYPixelMax-40);
  102. }
  103. //Pen mypen1 = new Pen(Color.Blue, 2);
  104. //g.DrawLine(mypen1, x - 480, 80, x - 480, 340);
  105. //绘制横向线条
  106. int y = m_iYPixelMin + 30;
  107. for (int i = 0; i < 8; i++)
  108. {
  109. g.DrawLine(mypen, m_iXPixelMin, y, m_iXPixelMin+(LINE_PNTS - 1) * 10, y);
  110. y = y + 30;
  111. }
  112. //x轴上对应的标记
  113. /*
  114. String[] n = { " 10", " 20", " 30", " 40", " 50", " 60", " 70",
  115. " 80", " 90", " 100", "110", "120", "130", "140", "150", "160", "170"};
  116. */
  117. x = m_iXPixelMin-5;
  118. g.DrawString("A", font, Brushes.Red, x, m_iYPixelMax - 35);
  119. x += 10;
  120. for (int i = 1; i < LINE_PNTS - 1; i++)
  121. {
  122. g.DrawString(".", font, Brushes.Red, x, m_iYPixelMax-35); //设置文字内容及输出位置
  123. x = x + 10;
  124. }
  125. g.DrawString("B", font, Brushes.Red, x, m_iYPixelMax - 35);
  126. //y轴上对应的标记
  127. /*
  128. String[] m = {"40", "35", "30", "25", "20", "15", "10",
  129. " 5"};
  130. */
  131. double dYStep = (m_dYVMax - m_dYVMin) / 9.0;
  132. y = m_iYPixelMin - 5;
  133. for (int i = 0; i < 10; i++)
  134. {
  135. double dTemp = m_dYVMax - i * dYStep;
  136. string str = dTemp.ToString("f1");
  137. g.DrawString(str, font, Brushes.Red, 1, y); //设置文字内容及输出位置
  138. y = y + 30;
  139. }
  140. x = m_iXPixelMin;
  141. y = (int)(m_iYPixelMin + 270.0 * ((m_dYVMax - m_adValue[0]) / (m_dYVMax - m_dYVMin)) + 0.5);
  142. for (int i = 1; i < LINE_PNTS; i++)
  143. {
  144. int yNext = (int)(m_iYPixelMin + 270.0 * ((m_dYVMax - m_adValue[i]) / (m_dYVMax - m_dYVMin)) + 0.5);
  145. g.DrawLine(mypen3, x, y, x + 10, yNext);
  146. x += 10;
  147. y = yNext;
  148. }
  149. /*
  150. if (drawflag == 1)
  151. {
  152. for (int i = 0; i < readlen / 2; i++)
  153. {
  154. g.DrawEllipse(mypen2, xbuf[i] - 2, ybuf[i] - 2, 4, 4);
  155. if (i < readlen / 2 - 1)
  156. g.DrawLine(mypen3, xbuf[i], ybuf[i], xbuf[i + 1], ybuf[i + 1]);
  157. }
  158. }
  159. if (flag == true)
  160. {
  161. g.DrawLine(mypen2, x1, 41, x1, 310);
  162. g.DrawLine(mypen2, 41, y1, 760, y1);
  163. }
  164. g.Dispose();
  165. */
  166. this.pictureBox1.Image = image;
  167. }
  168. private void SRLinesForm_Load(object sender, EventArgs e)
  169. {
  170. draw(1, 1, bufx, bufy);
  171. }
  172. private void SRLinesForm_FormClosed(object sender, FormClosedEventArgs e)
  173. {
  174. }
  175. private void 关于ToolStripMenuItem_Click(object sender, EventArgs e)
  176. {
  177. //Form2 f = new Form2();
  178. //f.Show();
  179. }
  180. private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
  181. {
  182. }
  183. private void buttonFile_Click(object sender, EventArgs e)
  184. {
  185. }
  186. private void buttonDraw_Click(object sender, EventArgs e)
  187. {
  188. }
  189. private void buttonClear_Click(object sender, EventArgs e)
  190. {
  191. }
  192. private void SRLinesForm_Load_1(object sender, EventArgs e)
  193. {
  194. }
  195. private void pictureBox1_Click(object sender, EventArgs e)
  196. {
  197. }
  198. }
  199. }