Exemplo n.º 1
0
        private Image DrawLines(List <DiModel> diModel)
        {
            int pboxHeight = (int)diModel.Count * 13;
            int pboxWidth  = diModel.Max(d => d.VesDown) + 10;

            //create a new image of the right size
            pbox2.Size = new Size()
            {
                Width = pboxWidth, Height = pboxHeight
            };
            pbox2.Top  = 5;
            pbox2.Left = 130;

            Image img = new Bitmap((int)pbox2.Width, pboxHeight);

            Graphics drawing = Graphics.FromImage(img);


            int i = 1;
            int gX1 = 0; int gY1 = 0;
            int gX2 = 0; int gY2 = 0;

            drawing.PageUnit  = GraphicsUnit.Point;
            drawing.PageScale = 0.7F;

            foreach (DiModel di in diModel)
            {
                int     y    = i * 12;
                DiModel next = diModel.Where(d => d.Dt > di.Dt).FirstOrDefault();

                if (next == null)
                {
                    next = new DiModel();
                    gX1  = di.VesDown; gY1 = 0;
                    gX2  = 20; gY2 = di.VesDown;
                }
                else
                {
                    gX1 = di.VesDown; gY1 = i * 2;
                    gX2 = next.VesDown; gY2 = i * 2 + 2;

                    var p      = new Pen(Color.Black, 0.5f);
                    var point1 = new Point(gX1, gY1);
                    var point2 = new Point(gX2, gY2);
                    drawing.DrawLine(p, point1, point2);
                }

                i++;
            }

            drawing.Save();


            drawing.Dispose();

            return(img);
        }
Exemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            DrawOnPBox();

            return;

            List <DiModel> diModel = new List <DiModel>();

            Form frm = Application.OpenForms[0];


            int i = 1;

            Random rd = new Random();

            for (DateTime dt = new DateTime(2019, 10, 1); dt <= new DateTime(2019, 10, 2); dt = dt.AddMinutes(5))
            {
                diModel.Add(new DiModel()
                {
                    Id       = i,
                    Date     = dt.ToString("H:m dd.MM.yyyy"),
                    Dt       = dt,
                    Davlenie = rd.Next(5000, 6000),
                    Deepth   = 100 + i * 5,
                    Moment   = rd.Next(90),
                    Nagruzka = rd.Next(245),
                    Oborot   = rd.Next(100),
                    Podacha  = rd.Next(100),
                    Speed    = rd.Next(20),
                    VesDown  = rd.Next(400),
                    VesUp    = rd.Next(300),
                });



                //panel1.Controls.Add(lbl);

                i++;
            }

            frm.Size = new Size()
            {
                Width = 1200, Height = 1200
            };

            panel1.Size = new Size()
            {
                Width = 150, Height = 1200
            };
            panel1.Top  = 5;
            panel1.Left = 10;
            //panel1.Width = 100;

            panel2.Height = frm.Height;
            panel2.Top    = 5;
            panel2.Left   = 150;
            panel2.Width  = 200;

            i = 1;

            panel2.Width = diModel.Max(d => d.VesDown) + 10;

            //panel1.Refresh();
            //panel2.Refresh();

            int gX1 = 0; int gY1 = 0;
            int gX2 = 0; int gY2 = 0;

            Graphics g  = panel1.CreateGraphics();
            Graphics g2 = panel2.CreateGraphics();

            g2.PageUnit  = GraphicsUnit.Pixel;
            g2.PageScale = 1F;

            g.Clear(Color.White);
            g2.Clear(Color.White);

            SolidBrush sbr = new SolidBrush(Color.Black);

            FontFamily fam  = new FontFamily("Tahoma");
            Font       font = new System.Drawing.Font(fam, 8, FontStyle.Regular);

            foreach (DiModel di in diModel)
            {
                int y = i * 13;

                DiModel next = diModel.Where(d => d.Dt > di.Dt).FirstOrDefault();

                g.DrawString(i + " - " + di.Date, font, sbr, new Point(10, y));


                if (next == null)
                {
                    next = new DiModel();
                    gX1  = di.VesDown; gY1 = 0;
                    gX2  = 20; gY2 = di.VesDown;
                }
                else
                {
                    gX1 = di.VesDown; gY1 = i * 2;
                    gX2 = next.VesDown; gY2 = i * 2 + 2;

                    var p      = new Pen(Color.Black, 0.5f);
                    var point1 = new Point(gX1, gY1);
                    var point2 = new Point(gX2, gY2);
                    g2.DrawLine(p, point1, point2);
                }



                //gX1 = gY2;
                //gY1 = next.VesDown;

                i++;
            }
        }
Exemplo n.º 3
0
        private void DrawOnPBox()
        {
            List <DiModel> diModel = new List <DiModel>();

            Form frm = Application.OpenForms[0];


            int i = 1;

            Random rd = new Random();

            for (DateTime dt = new DateTime(2019, 10, 1); dt <= new DateTime(2019, 10, 2); dt = dt.AddMinutes(5))
            {
                diModel.Add(new DiModel()
                {
                    Id       = i,
                    Date     = dt.ToString("H:m dd.MM.yyyy"),
                    Dt       = dt,
                    Davlenie = rd.Next(5000, 6000),
                    Deepth   = 100 + i * 5,
                    Moment   = rd.Next(90),
                    Nagruzka = rd.Next(245),
                    Oborot   = rd.Next(100),
                    Podacha  = rd.Next(100),
                    Speed    = rd.Next(20),
                    VesDown  = rd.Next(400),
                    VesUp    = rd.Next(300),
                });



                //panel1.Controls.Add(lbl);

                i++;
            }

            frm.Size = new Size()
            {
                Width = 1200, Height = 1200
            };

            pbox.Size = new Size()
            {
                Width = 150, Height = 1200
            };
            pbox.Top  = 5;
            pbox.Left = 10;


            i = 1;



            //panel1.Refresh();
            //panel2.Refresh();

            int gX1 = 0; int gY1 = 0;
            int gX2 = 0; int gY2 = 0;

            Graphics g = pbox.CreateGraphics();



            g.Clear(Color.White);


            SolidBrush sbr = new SolidBrush(Color.Black);

            FontFamily fam  = new FontFamily("Tahoma");
            Font       font = new System.Drawing.Font(fam, 8, FontStyle.Regular);



            foreach (DiModel di in diModel)
            {
                int y = i * 13;

                DiModel next = diModel.Where(d => d.Dt > di.Dt).FirstOrDefault();

                g.DrawString(i + " - " + di.Date, font, sbr, new Point(10, y));


                //gY1 = next.VesDown;

                i++;
            }
        }