| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 | 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);        }        /// <summary>        /// Required method for Designer support - do not modify        /// the contents of this method with the code editor.        /// </summary>        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)        {        }    }}
 |