| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3158 人关注过本帖
标题:gdi+画图,画在winform里,添加控件后运行,一闪就消失怎么办
只看楼主 加入收藏
terrybo
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2012-3-21
结帖率:100%
收藏
 问题点数:0 回复次数:6 
gdi+画图,画在winform里,添加控件后运行,一闪就消失怎么办
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace gdi_1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            DrawImage();
        }
        private void Form1_Shown(object sender, EventArgs e)
        {
            DrawImage();
        }

        private void DrawImage()
        {
            DrawXLine();//绘X轴分值线
            DrawYLine();//绘Y轴分值线
            DrawXY();   //绘XY轴
            DrawAllData();//绘出所有产品的价格线
        }
        int n = 15;
        public int i;
        public int MinX = 60;
        public int MinY = 60;
        public int MaxX = 600;
        public int MaxY = 610;
        public int low1;
        public int high1;
        public double danwei1;
        public int low2;
        public int high2;
        public double danwei2;
        public int low3;
        public int high3;
        public double danwei3;

        //double[] Pa = new double[15]{23.92,27.74,30.05,32.82,36.04,37.79,39.97,41.80,41.86,43.81,45.71,48.37,50.79,53.06,55.43};
        //double[] Pax = new double[15] { 0.0, 11.17, 16.57, 22.23, 27.66, 31.76, 35.99,38.72,41.66,45.82,49.87,55.29,60.83,66.36,71.93 };
        double[] Pa = new double[15] { 157.85, 158.13, 162.36, 168.22, 182.17, 191.72, 197.29, 200.21, 202.73, 202.51, 202.20, 200.65, 198.32, 194.21, 190.11 };
        double[] Pax = new double[15] { 28.67,135.02,316.23,400.95,533.51,617.70,697.34,752.16,800.82,840.15,871.00,910.32,947.85,994.96,1036.74};
        int[] Paint = new int[15];
        int[] Paxint = new int[15];

        double[] H = new double[15]{74.33,67.40,67.02,66.82,66.39,65.92,65.32,64.84,64.64,63.76,63.18,61.88,60.55,58.93,56.30};
        //double[] Hx = new double[15] { 0.0, 11.17, 16.57, 22.23, 27.66, 31.76, 35.99, 38.72, 41.66, 45.82, 49.87, 55.29, 60.83, 66.36, 71.93 };
        double[] Hx = new double[15] { 28.67, 135.02, 316.23, 400.95, 533.51, 617.70, 697.34, 752.16, 800.82, 840.15, 871.00, 910.32, 947.85, 994.96, 1036.74 };
        int[] Hint = new int[15];
        int[] Hxint = new int[15];

        double[] Eff = new double[15]{0.00,26.61,36.23,44.37,49.95,54.32,57.66,58.88,63.07,65.38,67.58,69.35,71.10,72.26,71.63};
        //double[] Effx = new double[15] { 0.0, 11.17, 16.57, 22.23, 27.66, 31.76, 35.99, 38.72, 41.66, 45.82, 49.87, 55.29, 60.83, 66.36, 71.93 };
        double[] Effx = new double[15] { 28.67, 135.02, 316.23, 400.95, 533.51, 617.70, 697.34, 752.16, 800.82, 840.15, 871.00, 910.32, 947.85, 994.96, 1036.74 };
        int[] Effint = new int[15];
        int[] Effxint = new int[15];

    //画出X轴与Y轴
        private void DrawXY()
        {
            Graphics g = this.ImagePanel.CreateGraphics();

            Point px1 = new Point(MinX-4, MaxY);
            Point px2 = new Point(MaxX, MaxY);
            g.DrawLine(new Pen(Brushes.Black, 1), px1, px2);
            Point px11 = new Point(MinX, MaxY+4);
            Point px22 = new Point(MaxX, MaxY+4);
            g.DrawLine(new Pen(Brushes.Black, 1), px11, px22);

            Point py1 = new Point(MinX, MinY);
            Point py2 = new Point(MinX, MaxY+4);
            g.DrawLine(new Pen(Brushes.Black, 1), py1, py2);
            Point py11 = new Point(MinX-4, MinY);
            Point py22 = new Point(MinX-4, MaxY-(MaxY-MinY)*6/11);
            g.DrawLine(new Pen(Brushes.Black, 1), py11, py22);
            Point py111 = new Point(MinX - 4, MaxY - (MaxY - MinY) * 5 / 11);
            Point py222 = new Point(MinX - 4, MaxY);
            g.DrawLine(new Pen(Brushes.Black, 1), py111, py222);



            Point py3 = new Point(MaxX, MinY);//右边第一条
            Point py4 = new Point(MaxX, MaxY+4);
            g.DrawLine(new Pen(Brushes.Black, 1), py3, py4);
            Point py33 = new Point(MaxX+4, MinY);//右边第一条
            Point py44 = new Point(MaxX+4, MaxY-(MaxY-MinY)*1/11);
            g.DrawLine(new Pen(Brushes.Black, 1), py33, py44);



            Point py5 = new Point(MaxX+50, MinY+(MaxY-MinY)*5/11);//第二条
            Point py6 = new Point(MaxX + 50, MinY + (MaxY - MinY) * 10/11);
            g.DrawLine(new Pen(Brushes.Black, 1), py5, py6);
            Point py55 = new Point(MaxX + 50-4, MinY + (MaxY - MinY) * 5 / 11);//第二条
            Point py66 = new Point(MaxX + 50-4, MinY + (MaxY - MinY) * 10 / 11);
            g.DrawLine(new Pen(Brushes.Black, 1), py55, py66);

         
            Pen pen = new Pen(Color.Red, 1);
            g.FillRectangle(pen.Brush, 0, MaxY + 20 * (i + 1), 10, 5);
            g.DrawString("Q-Eff", new Font("宋体 ", 10f), Brushes.Black, new Point(Effxint[n-1]+2,Effint[n-1]-2));
            g.DrawString("Q-H", new Font("宋体 ", 10f), Brushes.Black, new Point(Hxint[n - 1] + 2, Hint[n - 1] -2));
            g.DrawString("Q-Pa", new Font("宋体 ", 10f), Brushes.Black, new Point(Paxint[n - 1] + 2, Paint[n - 1]-2));
            for (i = 0; i < 6;i++ )
                g.DrawString(Convert.ToString(low1+i*danwei1), new Font("宋体 ", 10f), Brushes.Black, new Point(MinX - 30, MinY - 8 + (MaxY - MinY) * (11-i) / 11));
            //g.DrawString("30", new Font("宋体 ", 10f), Brushes.Black, new Point(MinX - 22, MinY - 8 + (MaxY - MinY) * 10 / 11));
            //g.DrawString("40", new Font("宋体 ", 10f), Brushes.Black, new Point(MinX - 22, MinY-8+(MaxY-MinY)*9/11));
            //g.DrawString("50", new Font("宋体 ", 10f), Brushes.Black, new Point(MinX - 22, MinY-8+(MaxY-MinY)*8/11));
            //g.DrawString("60", new Font("宋体 ", 10f), Brushes.Black, new Point(MinX - 22, MinY-8+(MaxY-MinY)*7/11));
            //g.DrawString("70", new Font("宋体 ", 10f), Brushes.Black, new Point(MinX - 22, MinY-8+(MaxY-MinY)*6/11));
            g.DrawString("Pa(kW)", new Font("宋体 ",10f), Brushes.Black, new Point(MinX-52,MinY-25+(MaxY-MinY)*6/11));
            for (i = 0; i < 6;i++ )
                g.DrawString(Convert.ToString(low2+i*danwei2), new Font("宋体 ", 10f), Brushes.Black, new Point(MinX - 30, MinY - 8 + (MaxY - MinY) * (5 - i) / 11));
            //g.DrawString("60", new Font("宋体 ", 10f), Brushes.Black, new Point(MinX - 22, MinY-8+(MaxY-MinY)*4/11));
            //g.DrawString("65", new Font("宋体 ", 10f), Brushes.Black, new Point(MinX - 22, MinY-8+(MaxY-MinY)*3/11));
            //g.DrawString("70", new Font("宋体 ", 10f), Brushes.Black, new Point(MinX - 22, MinY-8+(MaxY-MinY)*2/11));
            //g.DrawString("75", new Font("宋体 ", 10f), Brushes.Black, new Point(MinX - 22, MinY-8+(MaxY-MinY)*1/11));
            //g.DrawString("80", new Font("宋体 ", 10f), Brushes.Black, new Point(MinX - 22, MinY-8+(MaxY-MinY)*0/11));
            g.DrawString("H(m)", new Font("宋体 ", 10f), Brushes.Black, new Point(MinX - 37, MinY-25+(MaxY-MinY)*0/11));
            for (i = 0; i < 11; i++)
            g.DrawString(Convert.ToString(low3+i*danwei3), new Font("宋体 ", 10f), Brushes.Black, new Point(MinX -8+ (MaxX - MinX) * i / 10, MaxY+5));
            //g.DrawString("10", new Font("宋体 ", 10f), Brushes.Black, new Point(MinX -8+ (MaxX - MinX) * 1 / 10, MaxY+5));
           // g.DrawString("20", new Font("宋体 ", 10f), Brushes.Black, new Point(MinX -8+ (MaxX - MinX) * 2 / 10, MaxY+5));
            //g.DrawString("30", new Font("宋体 ", 10f), Brushes.Black, new Point(MinX -8+ (MaxX - MinX) * 3 / 10, MaxY+5));
            //g.DrawString("40", new Font("宋体 ", 10f), Brushes.Black, new Point(MinX -8+ (MaxX - MinX) * 4 / 10, MaxY+5));
            //g.DrawString("50", new Font("宋体 ", 10f), Brushes.Black, new Point(MinX -8+ (MaxX - MinX) * 5 / 10, MaxY+5));
            //g.DrawString("60", new Font("宋体 ", 10f), Brushes.Black, new Point(MinX -8+ (MaxX - MinX) * 6 / 10, MaxY+5));
            //g.DrawString("70", new Font("宋体 ", 10f), Brushes.Black, new Point(MinX -8+ (MaxX - MinX) * 7 / 10, MaxY+5));
            //g.DrawString("80", new Font("宋体 ", 10f), Brushes.Black, new Point(MinX -8+ (MaxX - MinX) * 8 / 10, MaxY+5));
            //g.DrawString("90", new Font("宋体 ", 10f), Brushes.Black, new Point(MinX -8+ (MaxX - MinX) * 9 / 10, MaxY+5));
            //g.DrawString("100", new Font("宋体 ", 10f), Brushes.Black, new Point(MinX-8+ (MaxX - MinX) *10 / 10, MaxY+5));
            //g.DrawString("Q(l/s)", new Font("宋体 ", 10f), Brushes.Black, new Point(MinX+20+(MaxX-MinX)*10/ 10, MaxY+5));

            g.DrawString("0", new Font("宋体 ", 10f),  Brushes.Black, new Point(MaxX + 5, MaxY-8-(MaxY-MinY)*1/11));
            g.DrawString("10", new Font("宋体 ", 10f), Brushes.Black, new Point(MaxX + 5, MaxY-8-(MaxY-MinY)*2/11));
            g.DrawString("20", new Font("宋体 ", 10f), Brushes.Black, new Point(MaxX + 5, MaxY-8-(MaxY-MinY)*3/11));
            g.DrawString("30", new Font("宋体 ", 10f), Brushes.Black, new Point(MaxX + 5, MaxY-8-(MaxY-MinY)*4/11));
            g.DrawString("40", new Font("宋体 ", 10f), Brushes.Black, new Point(MaxX + 5, MaxY-8-(MaxY-MinY)*5/11));
            g.DrawString("50", new Font("宋体 ", 10f), Brushes.Black, new Point(MaxX + 5, MaxY-8-(MaxY-MinY)*6/11));
            g.DrawString("60", new Font("宋体 ", 10f), Brushes.Black, new Point(MaxX + 5, MaxY-8-(MaxY-MinY)*7/11));
            g.DrawString("70", new Font("宋体 ", 10f), Brushes.Black, new Point(MaxX + 5, MaxY-8-(MaxY-MinY)*8/11));
            g.DrawString("80", new Font("宋体 ", 10f), Brushes.Black, new Point(MaxX + 5, MaxY-8-(MaxY-MinY)*9/11));
            g.DrawString("90", new Font("宋体 ", 10f), Brushes.Black, new Point(MaxX + 5, MaxY-8-(MaxY-MinY)*10/11));
            g.DrawString("100", new Font("宋体 ", 10f), Brushes.Black, new Point(MaxX +5, MaxY-8-(MaxY-MinY)*11/11));
            g.DrawString("Eff(%)",new Font("宋体 ", 10f), Brushes.Black,new Point(MaxX+5,MaxY-25-(MaxY-MinY)*11/11));

            g.DrawString("2", new Font("宋体 ", 10f), Brushes.Black,  new Point(MaxX +52, MaxY - 8 -(MaxY - MinX) * 1 / 11));
            g.DrawString("3", new Font("宋体 ", 10f), Brushes.Black, new Point(MaxX +52, MaxY - 8 - (MaxY - MinX) * 2 / 11));
            g.DrawString("4", new Font("宋体 ", 10f), Brushes.Black, new Point(MaxX +52, MaxY - 8 - (MaxY - MinX) * 3 / 11));
            g.DrawString("5", new Font("宋体 ", 10f), Brushes.Black, new Point(MaxX +52, MaxY - 8 - (MaxY - MinX) * 4 / 11));
            g.DrawString("6", new Font("宋体 ", 10f), Brushes.Black, new Point(MaxX +52, MaxY - 8 - (MaxY - MinX) * 5 / 11));
            g.DrawString("7", new Font("宋体 ", 10f), Brushes.Black, new Point(MaxX +52, MaxY - 8 - (MaxY - MinX) * 6 / 11));
            g.DrawString("NPSH", new Font("宋体 ", 10f), Brushes.Black, new Point(MaxX + 52, MaxY -28 - (MaxY - MinX) * 6 / 11));
      }


    // 画出Y轴上的分值线
        private void DrawXLine()
        {
            Graphics g = this.CreateGraphics();
            for (i = 54; i+1 > 0; i--)
            {
                Point px1 = new Point(MinX, MinY + (MaxY - MinY) * i / 55);
                Point px2 = new Point(MaxX, MinY + (MaxY - MinY) * i / 55);
                if (i % 5 == 0)
                {
                    
                    g.DrawLine(new Pen(Brushes.Gray, 1), px1, px2);
                    Point px11 = new Point(MinX-4, MinY + (MaxY - MinY) * i / 55);
                    Point px22 = new Point(MinX, MinY + (MaxY - MinY) * i / 55);
                    Point px111 = new Point(MaxX, MinY + (MaxY - MinY) * i / 55);
                    Point px222 = new Point(MaxX+4, MinY + (MaxY - MinY) * i / 55);
                    g.DrawLine(new Pen(Brushes.Black, 1), px11, px22);
                    g.DrawLine(new Pen(Brushes.Black, 1), px111, px222);
                    if (i / 5 >= 5 && i / 5 <= 10)
                    {
                        Point px1111 = new Point(MaxX+50, MinY + (MaxY - MinY) * i / 55);
                        Point px2222 = new Point(MaxX+50-4, MinY + (MaxY - MinY) * i / 55);
                        g.DrawLine(new Pen(Brushes.Black, 1), px1111, px2222);
                    }
                }
                else
                {
                    g.DrawLine(new Pen(Brushes.Silver, 1), px1, px2);
                }
            }
            

        }


    //画出X轴上的分值线
        private void DrawYLine()
        {
            Graphics g = this.CreateGraphics();
            for (i = 1; i-1< 49; i++)
            {
                Point py1 = new Point(MinX + (MaxX - MinX) * i / 50, MinY);
                Point py2 = new Point(MinX + (MaxX - MinX) * i / 50, MaxY);
                if (i % 5 == 0)
                {
                    g.DrawLine(new Pen(Brushes.Gray, 1), py1, py2);
                    Point py11 = new Point(MinX + (MaxX - MinX) * i / 50, MinY);
                    Point py22 = new Point(MinX + (MaxX - MinX) * i / 50, MaxY+4);
                    g.DrawLine(new Pen(Brushes.Black, 1), py11, py22);
                }
                else
                    g.DrawLine(new Pen(Brushes.Silver, 1), py1, py2);
            }
            
        }


        private void DrawAllData()
        {
            //左边Y
            Graphics g = this.CreateGraphics();
            // Create solid brush.
            SolidBrush BlackBrush = new SolidBrush(Color.Black);
            // Create rectangle for region.
            Rectangle fillRect = new Rectangle(MinX-4,MinY+(MaxY-MinY)/11*9,4,(MaxY-MinY)/11);
            // Create region for fill.
            Region fillRegion = new Region(fillRect);
            // Fill region to screen.
            g.FillRegion(BlackBrush, fillRegion);
            fillRect = new Rectangle(MinX-4, MinY+(MaxY - MinY)/11 * 7, 4, (MaxY - MinY) / 11);
            fillRegion = new Region(fillRect);
            g.FillRegion(BlackBrush, fillRegion);
            fillRect = new Rectangle(MinX - 4, MinY +(MaxY - MinY) / 11 * 3, 4, (MaxY - MinY) / 11);
            fillRegion = new Region(fillRect);
            g.FillRegion(BlackBrush, fillRegion);
            fillRect = new Rectangle(MinX - 4, MinY + (MaxY - MinY) / 11 * 1, 4, (MaxY - MinY) / 11);
            fillRegion = new Region(fillRect);
            g.FillRegion(BlackBrush, fillRegion);
            //X
            fillRect = new Rectangle(MinX+(MaxX-MinX)*1 /10,MaxY,(MaxX-MinX)/10,4);
            fillRegion = new Region(fillRect);
            g.FillRegion(BlackBrush, fillRegion);
            fillRect = new Rectangle(MinX + (MaxX - MinX) * 3 / 10, MaxY, (MaxX - MinX) / 10, 4);
            fillRegion = new Region(fillRect);
            g.FillRegion(BlackBrush, fillRegion);
            fillRect = new Rectangle(MinX + (MaxX - MinX) * 5 / 10, MaxY, (MaxX - MinX) / 10, 4);
            fillRegion = new Region(fillRect);
            g.FillRegion(BlackBrush, fillRegion);
            fillRect = new Rectangle(MinX + (MaxX - MinX) * 7 / 10, MaxY, (MaxX - MinX) / 10, 4);
            fillRegion = new Region(fillRect);
            g.FillRegion(BlackBrush, fillRegion);
            fillRect = new Rectangle(MinX + (MaxX - MinX) * 9 / 10, MaxY, (MaxX - MinX) / 10, 4);
            fillRegion = new Region(fillRect);
            g.FillRegion(BlackBrush, fillRegion);
            //Y轴右1
            fillRect = new Rectangle(MaxX, MinY + (MaxY-MinY)*0/11,4,(MaxY-MinY)/11);
            fillRegion = new Region(fillRect);
            g.FillRegion(BlackBrush, fillRegion);
            fillRect = new Rectangle(MaxX, MinY + (MaxY - MinY) * 2 / 11, 4, (MaxY - MinY) / 11);
            fillRegion = new Region(fillRect);
            g.FillRegion(BlackBrush, fillRegion);
            fillRect = new Rectangle(MaxX, MinY + (MaxY - MinY) * 4 / 11, 4, (MaxY - MinY) / 11);
            fillRegion = new Region(fillRect);
            g.FillRegion(BlackBrush, fillRegion);
            fillRect = new Rectangle(MaxX, MinY + (MaxY - MinY) * 6 / 11, 4, (MaxY - MinY) / 11);
            fillRegion = new Region(fillRect);
            g.FillRegion(BlackBrush, fillRegion);
            fillRect = new Rectangle(MaxX, MinY + (MaxY - MinY) * 8 / 11, 4, (MaxY - MinY) / 11);
            fillRegion = new Region(fillRect);
            g.FillRegion(BlackBrush, fillRegion);
            //Y轴右2
            fillRect = new Rectangle(MaxX+50-4, MinY + (MaxY - MinY) * 6 / 11, 4, (MaxY - MinY) / 11);
            fillRegion = new Region(fillRect);
            g.FillRegion(BlackBrush, fillRegion);
            fillRect = new Rectangle(MaxX+50-4, MinY + (MaxY - MinY) * 8 / 11, 4, (MaxY - MinY) / 11);
            fillRegion = new Region(fillRect);
            g.FillRegion(BlackBrush, fillRegion);
      
            
            
            
            
            //Y轴功率
            
            if (Pa.Min() < 100)
            {
                low1 = (int)Pa.Min() / 10 * 10;
            }
            if (Pa.Min() < 1000 && Pa.Min() > 100)
            {
                low1 = (int)Pa.Min() / 100 * 100;
            }
            if (Pa.Min() < 10000 && Pa.Min() > 1000)
            {
                low1 = (int)Pa.Min() / 1000 * 1000;
            }

            if (Pa.Max() < 100)
            {
                high1 = (int)Pa.Max() / 10 * 10+10;
            }
            if (Pa.Max() < 1000 && Pa.Max() > 100)
            {
                high1 = (int)Pa.Max() / 100 * 100 + 100;
            }
            if (Pa.Max() < 10000 && Pa.Max() > 1000)
            {
                high1 = (int)Pa.Max() / 1000 * 1000 + 1000;
            }
            danwei1 = (high1 - low1) / 4;


            if (H.Min() > 55 && H.Max()<100)
            {
                low2 = 55;
                high2 =80;
                danwei2 = 5;

            }
            else
            {
                if (H.Min() < 100)
                {
                    low2 = (int)H.Min() / 10 * 10;
                }
                if (H.Min() < 1000 && H.Min() > 100)
                {
                    low2 = (int)H.Min() / 100 * 100;
                }
                if (H.Min() < 10000 && H.Min() > 1000)
                {
                    low2 = (int)H.Min() / 1000 * 1000;
                }

                if (H.Max() < 100)
                {
                    high2 = (int)H.Max() / 10 * 10 + 10;
                }
                if (H.Max() < 1000 && H.Max() > 100)
                {
                    high2 = (int)H.Max() / 100 * 100 + 100;
                    int yushu = (int)Pax.Max() % 1000;
                    if (yushu > 50)
                    {
                        high3 = high3 + 100;
                    }
                    else
                    {
                        high3 = high3 + 50;
                    }
                }
                if (H.Max() < 10000 && H.Max() > 1000)
                {
                    high2 = (int)H.Max() / 1000 * 1000;
                    int yushu = (int)Pax.Max() % 1000;
                    if (yushu > 500)
                    {
                        high3 = high3 + 1000;
                    }
                    else
                    {
                        high3 = high3 + 500;
                    }
                }
                danwei2 = (high1 - low1) / 4;
            }



            low3 = 0;
           

            if (Pax.Max() < 100)
            {
                high3 = (int)Pax.Max() / 10 * 10 + 10;
            }
            if (Pax.Max() < 1000 && Pax.Max() > 100)
            {
                high3 = (int)Pax.Max() / 100 * 100;
                int yushu = (int)Pax.Max() % 1000;
                if (yushu > 500)
                {
                    high3 = high3 + 1000;
                }
                else
                {
                    high3 = high3 + 500;
                }
            }
            if (Pax.Max() < 10000 && Pax.Max() > 1000)
            {
                high3 = (int)Pax.Max() / 1000 * 1000;
                int yushu = (int)Pax.Max() % 1000;
                if (yushu > 500)
                {
                    high3 = high3 + 1000;
                }
                else
                {
                    high3 = high3 + 500;
                }
            }
            danwei3 = (high3 - low3) / 10;


           
           for(int i=0;i<n;i++)
           {
               Paxint[i] = Convert.ToInt32((Pax[i]-low3) / (high3 - low3) * (MaxX - MinX) + MinX);
            Paint[i] = Convert.ToInt32(MaxY - (Pa[i] - low1) / (high1 - low1) * (MaxY - MinY) * 5 / 11);
           }
           for (int i = 0; i < n; i++)
           {
               Rectangle rect = new Rectangle(Paxint[i] - 2, Paint[i] - 2, 4, 4);
               g.DrawRectangle(new Pen(Brushes.Black, 1), rect);
           }



           GLS.fittingOfAPolynomial(3,Pax,Pa);
           double[] m = new double[4];
           m = GLS.MatrixAk;
           double[] a = new double[101];
           double[] ax = new double[100];

           for (int i = 0; i < 100; i++)
           {
               ax[i] = Pax.Min() + (Pax.Max() - Pax.Min()) / 100 * i;
           }

           if (m.Length == 4)
           {
               int i = 0;
               double k = Math.Round((Pax.Max() - Pax.Min()) / 100.00,2);
               double pMin = Math.Round(Pax.Min(),2);
               double pMax = Math.Round(Pax.Max(), 2);

               for (double j = pMin; j <= pMax; j = j + k)
               {
                   a[i] = Math.Round(m[0] + m[1] * j + m[2] * Math.Pow(j, 2.0) + m[3] * Math.Pow(j, 3.0), 2);
                   i++;
               }
           }
        
           PointF[] Paxypoint=new PointF[100];
           for (int i = 0; i < 100; i++)
           {
               Paxypoint[i] = new PointF(Convert.ToInt32((ax[i] - low3) / (high3 - low3) * (MaxX - MinX) + MinX),
                   Convert.ToInt32(MaxY - (a[i] - low1) / (high1 - low1) * (MaxY - MinY)*5/11));
           }
           
           g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
           g.DrawCurve(new Pen(Color.Blue, 1), Paxypoint);

           //Y轴扬程
            
           for (int i = 0; i < n; i++)
           {
               Hxint[i] = Convert.ToInt32(Hx[i] / (high3 - low3) * (MaxX - MinX) + MinX);
               Hint[i] = Convert.ToInt32(MinY+(high2-H[i])/(high2-low2)*(MaxY-MinY)*5/11);
           }
           for (int i = 0; i < n; i++)
           {

               Rectangle rect = new Rectangle(Hxint[i] - 2, Hint[i] - 2, 4, 4);
               g.DrawEllipse(new Pen(Brushes.Black, 1), rect);
               //g.DrawRectangle(new Pen(Brushes.Black, 1), rect);
           }

         
           GLS.fittingOfAPolynomial(3, Hx,H);
           m = new double[4];
           m = GLS.MatrixAk;
           a = new double[101];
           ax = new double[100];
           for (int i = 0; i < 100; i++)
           {
               ax[i] = Hx.Min() + (Hx.Max() - Hx.Min()) / 100 * i;
           }
           
           if (m.Length == 4)
           {
               double k = (Hx.Max() - Hx.Min()) / 100;
               i = 0;
               
               for (double j = Hx.Min(); j < Hx.Max(); j = j + k)
               {
                   a[i] = Math.Round(m[0] + m[1] * j + m[2] * Math.Pow(j, 2.0) + m[3] * Math.Pow(j, 3.0), 2);
                   i++;
               }
           }
           PointF[] Hxypoint = new PointF[100];
           for (int i = 0; i < 100; i++)
           {
               Hxypoint[i] = new PointF(Convert.ToInt32(ax[i] / (high3 - low3) * (MaxX - MinX) + MinX),
                   Convert.ToInt32(MinY + (high2 - a[i]) / (high2 - low2) * (MaxY - MinY) * 5 / 11));
           }
               g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
               g.DrawCurve(new Pen(Color.Yellow, 1), Hxypoint);
           
            //Y轴效率
            for (int i = 0; i < n; i++)
           {
               Effxint[i] = Convert.ToInt32( Effx[i] / (high3 - low3) * (MaxX - MinX) + MinX);
               Effint[i] = Convert.ToInt32(MaxY - (Eff[i]+10) / 110 * (MaxY - MinY));
           }
           for (int i = 0; i < n; i++)
           {
               Point point1 = new Point(Effxint[i]-2,  Effint[i]+1);
               Point point2 = new Point(Effxint[i]+2, Effint[i]+1);
               Point point3 = new Point(Effxint[i], Effint[i]-2  );
               Point[] curvePoints =
             {
                 point1,
                 point2,
                 point3,
             };

               g.DrawPolygon(new Pen(Brushes.Black, 1), curvePoints);
               //Rectangle rect = new Rectangle(Effxint[i] - 2, Effint[i] - 2, 4, 4);
               //g.DrawRectangle(new Pen(Brushes.Black, 1), rect);
           }

           GLS.fittingOfAPolynomial(3, Effx, Eff);
           m = new double[4];
           m = GLS.MatrixAk;
           a = new double[101];
           ax = new double[100];
           for (int i = 0; i < 100; i++)
           {
               ax[i] = Pax.Min() + (Effx.Max() - Effx.Min()) / 100 * i;
           }

           if (m.Length == 4)
           {
               int i = 0;
               double k = (Effx.Max() - Effx.Min()) / 100;
               double j = Effx.Min();
               for (; j < Effx.Max(); j = j + k)
               {
                   a[i] = Math.Round(m[0] + m[1] * j + m[2] * Math.Pow(j, 2.0) + m[3] * Math.Pow(j, 3.0), 2);
                   i++;
               }
           }

           PointF[] Effxypoint = new PointF[100];
           for (int i= 0; i < 100; i++)
           {
               Effxypoint[i] = new PointF(Convert.ToInt32(ax[i] / (high3 - low3) * (MaxX - MinX) + MinX), Convert.ToInt32(MaxY - (a[i] + 10) / 110 * (MaxY - MinY)));
           }
           g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
           g.DrawCurve(new Pen(Color.Red, 1), Effxypoint);
            
         
            //Y轴NPSH*/

        }

    }
}
搜索更多相关主题的帖子: void 怎么办 private public 
2012-03-26 13:01
terrybo
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2012-3-21
收藏
得分:0 
namespace gdi_1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            DrawImage();
            this.Paint += new PaintEventHandler(Paint1);

        }

        private void Form1_Shown(object sender, EventArgs e)
        {
           
        }

        private void DrawImage()
        {
            DrawXLine();//绘X轴分值线
            DrawYLine();//绘Y轴分值线
            DrawXY();   //绘XY轴
            DrawAllData();//绘出所有值曲线
        }
        private void Paint1(object sender, PaintEventArgs e)
        {
            DrawImage();
        }
2012-03-26 13:37
vanochan
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-3-26
收藏
得分:0 
看到眼都花了
2012-03-26 16:01
月光雪山
Rank: 2
等 级:论坛游民
威 望:4
帖 子:36
专家分:97
注 册:2012-1-10
收藏
得分:0 
放在一个句柄里绘制试试
2012-03-26 17:25
xydddaxia
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:33
帖 子:466
专家分:2307
注 册:2009-3-20
收藏
得分:0 
写在Paint事件里面,重写控件的Paint方法,再把你的绘图代码加进去。

站在春哥的肩膀上
2012-03-27 12:12
zhoufeng1988
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:北京
等 级:贵宾
威 望:27
帖 子:1432
专家分:6329
注 册:2009-5-31
收藏
得分:0 
不理解GDI绘图撒~
窗口重绘时会清除你画的所有,所以你应该在窗口发成重绘时重新绘制。
参照5楼~
2012-03-31 00:01
jedypjd
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:9
帖 子:1096
专家分:4969
注 册:2009-7-27
收藏
得分:0 
程序代码:
 protected override void OnPaint(PaintEventArgs e)
        {
            DrawImage();

            base.OnPaint(e);
        }
这样每次需要刷新的时候都会DrawImage

天涯无岁月,歧路有风尘,百年浑似醉,是非一片云
2012-04-01 15:45
快速回复:gdi+画图,画在winform里,添加控件后运行,一闪就消失怎么办
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.050425 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved