using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.IO; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; namespace PaintDotNet.Instrument { public partial class SRLinesForm : Form { private System.Windows.Forms.PictureBox pictureBox1; public SRLinesForm() { InitializeComponent(); this.Load += new EventHandler(SRLinesForm_Load); } /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.pictureBox1 = new System.Windows.Forms.PictureBox(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); this.SuspendLayout(); // // pictureBox1 // this.pictureBox1.Location = new System.Drawing.Point(1, 2); this.pictureBox1.Name = "pictureBox1"; this.pictureBox1.Size = new System.Drawing.Size(1101, 351); this.pictureBox1.TabIndex = 0; this.pictureBox1.TabStop = false; this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click); // // SRLinesForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1105, 355); this.Controls.Add(this.pictureBox1); this.Name = "SRLinesForm"; this.Text = "剖面线"; this.Load += new System.EventHandler(this.SRLinesForm_Load_1); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); this.ResumeLayout(false); } //string resultFile; //private Point mouseOffset; //bool flag = false; ToolTip tooltip = new ToolTip(); int[] bufx = new int[1024]; int[] bufy = new int[1024]; //int drawflag = 0; //int readlen = 0; //zzz public const int LINE_PNTS = 100; public int m_iYVCount = 10; public double m_dYVMax = 51; public double m_dYVMin = -51; public double[] m_adValue = new double[LINE_PNTS]; public int m_iYPixelMax = 350; public int m_iYPixelMin = 40; public int m_iXPixelMax = 1100; public int m_iXPixelMin = 60; // x1,y1为鼠标移动的坐标,画十字线用,xbuf,ybuf绘制点坐标数组 void draw(int x1, int y1, int[] xbuf, int[] ybuf) { //定义画布大小 int height = m_iYPixelMax, width = m_iXPixelMax; //创建位图 System.Drawing.Bitmap image = new System.Drawing.Bitmap(width, height); //创建Graphics类对象 Graphics g = Graphics.FromImage(image); //清空图片背景色 g.Clear(Color.White); Font font = new System.Drawing.Font("Arial", 9, FontStyle.Regular); Font font1 = new System.Drawing.Font("宋体", 20, FontStyle.Regular); Font font2 = new System.Drawing.Font("Arial", 8, FontStyle.Regular); 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); g.FillRectangle(Brushes.SeaGreen, 0, 0, width, height); Brush brush1 = new SolidBrush(Color.Blue); Brush brush2 = new SolidBrush(Color.SaddleBrown); //画图片的边框线 g.DrawRectangle(new Pen(Color.Black), m_iXPixelMin, m_iYPixelMin, (LINE_PNTS - 1) * 10, 270); g.DrawRectangle(new Pen(Color.Black), m_iXPixelMin, m_iYPixelMin - 5, (LINE_PNTS - 1) * 10, 275); System.Drawing.Pen mypen = new Pen(brush, 1); System.Drawing.Pen mypen2 = new Pen(Color.Red, 2); System.Drawing.Pen mypen3 = new Pen(Color.Yellow, 1); //绘制线条 //绘制纵向线条 int x = m_iXPixelMin; for (int i = 0; i < 9; i++) { x = x + 100; g.DrawLine(mypen, x, 40, x, m_iYPixelMax-40); } //Pen mypen1 = new Pen(Color.Blue, 2); //g.DrawLine(mypen1, x - 480, 80, x - 480, 340); //绘制横向线条 int y = m_iYPixelMin + 30; for (int i = 0; i < 8; i++) { g.DrawLine(mypen, m_iXPixelMin, y, m_iXPixelMin+(LINE_PNTS - 1) * 10, y); y = y + 30; } //x轴上对应的标记 /* String[] n = { " 10", " 20", " 30", " 40", " 50", " 60", " 70", " 80", " 90", " 100", "110", "120", "130", "140", "150", "160", "170"}; */ x = m_iXPixelMin-5; g.DrawString("A", font, Brushes.Red, x, m_iYPixelMax - 35); x += 10; for (int i = 1; i < LINE_PNTS - 1; i++) { g.DrawString(".", font, Brushes.Red, x, m_iYPixelMax-35); //设置文字内容及输出位置 x = x + 10; } g.DrawString("B", font, Brushes.Red, x, m_iYPixelMax - 35); //y轴上对应的标记 /* String[] m = {"40", "35", "30", "25", "20", "15", "10", " 5"}; */ double dYStep = (m_dYVMax - m_dYVMin) / 9.0; y = m_iYPixelMin - 5; for (int i = 0; i < 10; i++) { double dTemp = m_dYVMax - i * dYStep; string str = dTemp.ToString("f1"); g.DrawString(str, font, Brushes.Red, 1, y); //设置文字内容及输出位置 y = y + 30; } x = m_iXPixelMin; y = (int)(m_iYPixelMin + 270.0 * ((m_dYVMax - m_adValue[0]) / (m_dYVMax - m_dYVMin)) + 0.5); for (int i = 1; i < LINE_PNTS; i++) { int yNext = (int)(m_iYPixelMin + 270.0 * ((m_dYVMax - m_adValue[i]) / (m_dYVMax - m_dYVMin)) + 0.5); g.DrawLine(mypen3, x, y, x + 10, yNext); x += 10; y = yNext; } /* if (drawflag == 1) { for (int i = 0; i < readlen / 2; i++) { g.DrawEllipse(mypen2, xbuf[i] - 2, ybuf[i] - 2, 4, 4); if (i < readlen / 2 - 1) g.DrawLine(mypen3, xbuf[i], ybuf[i], xbuf[i + 1], ybuf[i + 1]); } } if (flag == true) { g.DrawLine(mypen2, x1, 41, x1, 310); g.DrawLine(mypen2, 41, y1, 760, y1); } g.Dispose(); */ this.pictureBox1.Image = image; } private void SRLinesForm_Load(object sender, EventArgs e) { draw(1, 1, bufx, bufy); } private void SRLinesForm_FormClosed(object sender, FormClosedEventArgs e) { } private void 关于ToolStripMenuItem_Click(object sender, EventArgs e) { //Form2 f = new Form2(); //f.Show(); } private void pictureBox1_MouseMove(object sender, MouseEventArgs e) { } private void buttonFile_Click(object sender, EventArgs e) { } private void buttonDraw_Click(object sender, EventArgs e) { } private void buttonClear_Click(object sender, EventArgs e) { } private void SRLinesForm_Load_1(object sender, EventArgs e) { } private void pictureBox1_Click(object sender, EventArgs e) { } } }