Пример #1
0
        private void pictureBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            string    name = this.Name;
            int       middle = (pictureBox1.Right + pictureBox1.Left) / 2;
            int       fs, bl, pb;
            NeedleEnd ne    = new NeedleEnd(adc, middle - 5, engineering, eunits, gmin, gmax);
            NeedleEnd nemin = new NeedleEnd(cntmin, middle - 5, engineering, emin, gmin, gmax);
            NeedleEnd nemax = new NeedleEnd(cntmax, middle - 5, engineering, emax, gmin, gmax);
            // Create a local version of the graphics object for the PictureBox.
            Graphics g       = e.Graphics;
            Pen      gagepen = new Pen(Brushes.Black);

            gagepen.Width = 4;
            Pen gagepenmin = new Pen(Brushes.Blue);

            gagepenmin.Width = 2;
            Pen gagepenmax = new Pen(Brushes.Red);

            gagepenmax.Width = 2;
            Pen gageback = new Pen(Brushes.DarkSlateBlue);

            gageback.Width = 1;
            Pen majortick = new Pen(Brushes.DarkBlue);

            majortick.Width = 3;

            int tickmax = 20; // read the number of ticks from the input box

            try
            {
                tickmax = Convert.ToInt16(ticksBox.Text);
            }
            catch //(Exception ex)
            {
                //MessageBox.Show("Tick max: " + ex.Message);
                tickmax = 20;
            }

            if (size <= 0) // scale things for the gauge size
            {
                fs = 20;
                bl = 50;
                pb = 40;
            }
            else
            {
                fs = 10;
                bl = 25;
                pb = 42;
            }

            // draw gauge background
            g.DrawPie(gageback, 15, pb, middle * 2 - 30, middle * 2 - 30, -180.0F, 180.0F);
            //draw the gauge ticks
            for (int i = 0; i <= tickmax; i++)
            {
                NeedleTicks nt = new NeedleTicks(middle - 5, i, tickmax);
                if (tickmax / 2 == i || tickmax / 4 == i || 3 * tickmax / 4 == i)
                {
                    g.DrawLine(majortick, middle + nt.x1, (pictureBox1.Bottom - bl) - nt.y1,
                               middle + nt.x2, (pictureBox1.Bottom - bl) - nt.y2);
                }
                else
                {
                    g.DrawLine(gageback, middle + nt.x1, (pictureBox1.Bottom - bl) - nt.y1,
                               middle + nt.x2, (pictureBox1.Bottom - bl) - nt.y2);
                }
            }
            // Draw a gauge name on the PictureBox.
            g.DrawString(name,
                         new Font("Arial", fs), System.Drawing.Brushes.Blue,
                         new Point(middle - name.Length * fs / 2, pictureBox1.Bottom - (bl - 5)));

            // Draw a gauge needles in the PictureBox.
            g.DrawLine(gagepen, middle + ne.x, (pictureBox1.Bottom - bl) - ne.y,
                       middle, pictureBox1.Bottom - bl);
            g.DrawLine(gagepenmin, middle + nemin.x, (pictureBox1.Bottom - bl) - nemin.y,
                       middle, pictureBox1.Bottom - bl);
            g.DrawLine(gagepenmax, middle + nemax.x, (pictureBox1.Bottom - bl) - nemax.y,
                       middle, pictureBox1.Bottom - bl);
        }
Пример #2
0
        private void pictureBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            string name = this.Name ;
            int middle = (pictureBox1.Right + pictureBox1.Left) / 2 ;
            int fs, bl, pb;
            NeedleEnd ne = new NeedleEnd(adc, middle - 5, engineering, eunits, gmin,gmax);
            NeedleEnd nemin = new NeedleEnd(cntmin, middle - 5, engineering, emin, gmin, gmax);
            NeedleEnd nemax = new NeedleEnd(cntmax, middle - 5, engineering, emax, gmin, gmax);
            // Create a local version of the graphics object for the PictureBox.
            Graphics g = e.Graphics;
            Pen gagepen = new Pen(Brushes.Black);
            gagepen.Width = 4;
            Pen gagepenmin = new Pen(Brushes.Blue);
            gagepenmin.Width = 2;
            Pen gagepenmax = new Pen(Brushes.Red);
            gagepenmax.Width = 2;
            Pen gageback = new Pen(Brushes.DarkSlateBlue);
            gageback.Width = 1;
            Pen majortick = new Pen(Brushes.DarkBlue);
            majortick.Width = 3;

            int tickmax = 20; // read the number of ticks from the input box
            try
            {
                tickmax = Convert.ToInt16(ticksBox.Text);
            }
            catch //(Exception ex)
            {
                //MessageBox.Show("Tick max: " + ex.Message);
                tickmax = 20;
            }

            if (size <= 0) // scale things for the gauge size
            {
                fs = 20;
                bl = 50;
                pb = 40;
            }
            else
            {
                fs = 10;
                bl = 25;
                pb = 42;
            }

            // draw gauge background 
            g.DrawPie(gageback, 15, pb, middle*2-30, middle*2-30, -180.0F, 180.0F);
            //draw the gauge ticks
            for (int i = 0; i <= tickmax; i++)
            {
                NeedleTicks nt = new NeedleTicks(middle-5, i, tickmax);
                if (tickmax / 2 == i || tickmax / 4 == i || 3*tickmax / 4 == i)
                {
                    g.DrawLine(majortick, middle + nt.x1, (pictureBox1.Bottom - bl) - nt.y1,
                        middle + nt.x2, (pictureBox1.Bottom - bl) - nt.y2);
                }
                else
                {
                    g.DrawLine(gageback, middle + nt.x1, (pictureBox1.Bottom - bl) - nt.y1,
                        middle + nt.x2, (pictureBox1.Bottom - bl) - nt.y2);
                }
            }
            // Draw a gauge name on the PictureBox.
            g.DrawString(name,
                new Font("Arial", fs), System.Drawing.Brushes.Blue,
                new Point(middle - name.Length * fs/2, pictureBox1.Bottom - (bl-5)));
            
            // Draw a gauge needles in the PictureBox.
            g.DrawLine(gagepen, middle + ne.x, (pictureBox1.Bottom - bl) - ne.y,
                middle, pictureBox1.Bottom -bl);
            g.DrawLine(gagepenmin, middle + nemin.x, (pictureBox1.Bottom - bl) - nemin.y,
                middle, pictureBox1.Bottom - bl);
            g.DrawLine(gagepenmax, middle + nemax.x, (pictureBox1.Bottom - bl) - nemax.y,
                middle, pictureBox1.Bottom - bl);
        }