private Bitmap PaintData(int width, int height)
        {
            if (width < 200)
            {
                width = 200;
            }
            if (height < 100)
            {
                height = 100;
            }

            Bitmap   bitmap = new Bitmap(width, height);
            Graphics g      = Graphics.FromImage(bitmap);

            Font         font12 = new Font("宋体", 12f);
            StringFormat sf     = new StringFormat
            {
                Alignment     = StringAlignment.Far,
                LineAlignment = StringAlignment.Center,
            };
            Pen dash = new Pen(Color.LightGray, 1f);

            dash.DashStyle   = System.Drawing.Drawing2D.DashStyle.Custom;
            dash.DashPattern = new float[] { 5, 5 };


            g.Clear(Color.White);

            if (listPaint.Count <= 5)
            {
                g.DrawString("数据太少了", font12, Brushes.DeepSkyBlue, new Rectangle(0, 0, width, height), sf);
                goto P1;
            }


            int count = (width - 60) / 6;

            TimeSpan sp           = listPaint.Max() - listPaint.Min();
            DateTime datetime_min = listPaint.Min();
            double   sep          = sp.TotalSeconds / count;

            int[] counts = new int[count];

            for (int i = 0; i < listPaint.Count; i++)
            {
                TimeSpan timeSpan = listPaint[i] - datetime_min;

                int index = (int)(timeSpan.TotalSeconds / sep);
                if (index < 0)
                {
                    index = 0;
                }
                if (index == count)
                {
                    index--;
                }
                counts[index]++;
            }

            int Max = counts.Max();
            int Min = 0;

            PaintItem[] list = new PaintItem[count];
            for (int i = 0; i < counts.Length; i++)
            {
                PaintItem item = new PaintItem();
                item.Count = counts[i];
                item.Start = listPaint[0].AddSeconds(i * sep);
                if (i == counts.Length - 1)
                {
                    item.End = listPaint[listPaint.Count - 1];
                }
                else
                {
                    item.End = listPaint[0].AddSeconds((i + 1) * sep);
                }

                list[i] = item;
            }

            listRender = new List <PaintItem>(list);


            // 左边空50,右边空10,上面20,下面30
            int left  = 50;
            int right = 10;
            int up    = 20;
            int down  = 30;

            g.DrawLine(Pens.DimGray, left, up - 10, left, height - down);
            g.DrawLine(Pens.DimGray, left, height - down + 1, width - right, height - down + 1);


            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            // 绘制箭头
            BasicFramework.SoftPainting.PaintTriangle(g, Brushes.DimGray, new Point(left, up - 10), 5, BasicFramework.GraphDirection.Upward);
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;

            int degree = 8;

            if (height < 500)
            {
                if (Max < 15 && Max > 1)
                {
                    degree = Max;
                }
            }
            else if (height < 700)
            {
                if (Max < 25 && Max > 1)
                {
                    degree = Max;
                }
                else
                {
                    degree = 16;
                }
            }
            else
            {
                if (Max < 40 && Max > 1)
                {
                    degree = Max;
                }
                else
                {
                    degree = 24;
                }
            }

            // 绘制刻度
            BasicFramework.SoftPainting.PaintCoordinateDivide(g, Pens.DimGray, dash, font12, Brushes.DimGray,
                                                              sf, degree, Max, Min, width, height, left, right, up, down);

            sf.Alignment = StringAlignment.Center;
            // 绘制总数
            g.DrawString("Totle: " + listPaint.Count, font12, Brushes.DodgerBlue,
                         new RectangleF(left, 0, width - left - right, up), sf);


            int paint_x = left + 2;

            for (int i = 0; i < list.Length; i++)
            {
                // 计算绘制位置
                float      location   = BasicFramework.SoftPainting.ComputePaintLocationY(Max, Min, height - up - down, list[i].Count) + up;
                RectangleF rectangleF = new RectangleF(paint_x, location, 5, height - down - location);
                if (rectangleF.Height <= 0 && list[i].Count > 0)
                {
                    rectangleF = new RectangleF(paint_x, height - down - 1, 5, 1);
                }
                g.FillRectangle(Brushes.Tomato, rectangleF);
                paint_x += 6;
            }

            g.DrawLine(Pens.DimGray, paint_x, up - 10, paint_x, height - down);
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            BasicFramework.SoftPainting.PaintTriangle(g, Brushes.DimGray, new Point(paint_x, up - 10), 5, BasicFramework.GraphDirection.Upward);
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;

P1:
            sf.Dispose();
            font12.Dispose();
            dash.Dispose();
            g.Dispose();
            return(bitmap);
        }
Ejemplo n.º 2
0
        private static void ShowForm(IWin32Window owner, Uri webpage, string productText, string applicationText, string copyrightText, string applicationPath)
        {
            Font productFont = null;

            PaintItem fullName        = null;
            PaintItem dotNetFramework = null;
            PaintItem osVersion       = null;
            PaintItem copyright       = null;

            Button buttonReadme  = null;
            Button buttonClose   = null;
            Button buttonWebPage = null;

            using (Form form = new Form()) {
                try {
                    form.FormBorderStyle = FormBorderStyle.FixedDialog;
                    form.ShowIcon        = false;
                    form.ShowInTaskbar   = false;
                    form.MinimizeBox     = false;
                    form.MaximizeBox     = false;
                    form.AutoSize        = false;
                    form.AutoScaleMode   = AutoScaleMode.None;
                    form.Text            = Resources.Caption;


                    int imageHeight = 32;
                    int maxRight    = 320;
                    int maxBottom   = 80;
                    using (Graphics graphics = form.CreateGraphics()) {
                        //icon
                        Bitmap bitmap = GetAppIcon(applicationPath);
                        if (bitmap != null)
                        {
                            _paintImage = new PaintItem(bitmap, new Point(7, 7));
                        }

                        //title
                        int imageRight = 7;
                        if (_paintImage != null)
                        {
                            imageRight = _paintImage.Rectangle.Right + 7;
                        }
                        if (_paintImage != null)
                        {
                            imageHeight = _paintImage.Rectangle.Height;
                        }
                        productFont   = new Font(SystemFonts.MessageBoxFont.Name, imageHeight, System.Drawing.SystemFonts.MessageBoxFont.Style, System.Drawing.GraphicsUnit.Pixel, System.Drawing.SystemFonts.MessageBoxFont.GdiCharSet);
                        _paintProduct = new PaintItem(productText, productFont, imageRight, 7, imageHeight, VerticalAlignment.Center, graphics);

                        _titleHeight = 7 + imageHeight + 7;
                        maxRight     = System.Math.Max(maxRight, _paintProduct.Rectangle.Right);
                        maxBottom    = System.Math.Max(maxBottom, _titleHeight);


                        //other stuff
                        _infoLines = new List <PaintItem>();

                        fullName  = new PaintItem(applicationText, SystemFonts.MessageBoxFont, 7, _titleHeight + 2 + 7, 0, VerticalAlignment.Top, graphics);
                        maxRight  = System.Math.Max(maxRight, fullName.Rectangle.Right);
                        maxBottom = System.Math.Max(maxBottom, fullName.Rectangle.Bottom);
                        _infoLines.Add(fullName);

                        dotNetFramework = new PaintItem(".NET framework " + Environment.Version.ToString(), SystemFonts.MessageBoxFont, 7, fullName.Rectangle.Bottom, 0, VerticalAlignment.Top, graphics);
                        maxRight        = System.Math.Max(maxRight, dotNetFramework.Rectangle.Right);
                        maxBottom       = System.Math.Max(maxBottom, dotNetFramework.Rectangle.Bottom);
                        _infoLines.Add(dotNetFramework);

                        osVersion = new PaintItem(System.Environment.OSVersion.VersionString, SystemFonts.MessageBoxFont, 7, dotNetFramework.Rectangle.Bottom, 0, VerticalAlignment.Top, graphics);
                        maxRight  = System.Math.Max(maxRight, osVersion.Rectangle.Right);
                        maxBottom = System.Math.Max(maxBottom, osVersion.Rectangle.Bottom);
                        _infoLines.Add(osVersion);

                        if (copyrightText != null)
                        {
                            copyright = new PaintItem(copyrightText, SystemFonts.MessageBoxFont, 7, osVersion.Rectangle.Bottom + 7, 0, VerticalAlignment.Top, graphics);
                            maxRight  = System.Math.Max(maxRight, copyright.Rectangle.Right);
                            maxBottom = System.Math.Max(maxBottom, copyright.Rectangle.Bottom);
                            _infoLines.Add(copyright);
                        }
                    }

                    int buttonMinRight = 7;

                    //Close button
                    buttonClose = new Button()
                    {
                        Padding = new Padding(3, 1, 3, 1)
                    };
                    buttonClose.Anchor       = AnchorStyles.Right | AnchorStyles.Bottom;
                    buttonClose.AutoSize     = true;
                    buttonClose.DialogResult = DialogResult.OK;
                    buttonClose.Text         = Resources.Close;
                    form.Controls.Add(buttonClose);
                    buttonMinRight += buttonClose.Width + 11;

                    //Readme button
                    string readMePath = System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath, "readme.txt");
                    if (System.IO.File.Exists(readMePath))
                    {
                        buttonReadme = new Button()
                        {
                            Padding = new Padding(3, 1, 3, 1)
                        };
                        buttonReadme.Anchor   = AnchorStyles.Left | AnchorStyles.Bottom;
                        buttonReadme.AutoSize = true;
                        buttonReadme.Text     = Resources.ReadMe;
                        buttonReadme.Tag      = readMePath;
                        buttonReadme.Click   += new System.EventHandler(buttonReadme_Click);
                        form.Controls.Add(buttonReadme);
                        buttonMinRight += buttonReadme.Width + 7;
                    }

                    //WebPage button
                    if (webpage != null)
                    {
                        buttonWebPage = new Button()
                        {
                            Padding = new Padding(3, 1, 3, 1)
                        };
                        buttonWebPage.Anchor   = AnchorStyles.Left | AnchorStyles.Bottom;
                        buttonWebPage.AutoSize = true;
                        buttonWebPage.Text     = Resources.WebPage;
                        buttonWebPage.Tag      = webpage.ToString();
                        buttonWebPage.Click   += new System.EventHandler(buttonWebPage_Click);
                        form.Controls.Add(buttonWebPage);
                        buttonMinRight += buttonWebPage.Width + 7;
                    }

                    maxRight = System.Math.Max(maxRight, buttonMinRight);


                    int borderX = (form.Width - form.ClientRectangle.Width);
                    int borderY = (form.Height - form.ClientRectangle.Height);
                    form.Width  = borderX + maxRight + 7;
                    form.Height = borderY + maxBottom + 11 + 11 + buttonClose.Size.Height + 7;
                    if (owner == null)
                    {
                        form.StartPosition = FormStartPosition.CenterScreen;
                    }
                    else
                    {
                        form.StartPosition = FormStartPosition.CenterParent;
                    }


                    int buttonLeft = form.ClientRectangle.Left + 7;

                    if (buttonReadme != null)
                    {
                        buttonReadme.Location = new Point(buttonLeft, form.ClientRectangle.Bottom - buttonClose.Height - 7);
                        buttonLeft           += buttonReadme.Width + 7;
                    }

                    if (buttonWebPage != null)
                    {
                        buttonWebPage.Location = new Point(buttonLeft, form.ClientRectangle.Bottom - buttonClose.Height - 7);
                        buttonLeft            += buttonWebPage.Width + 7;
                    }

                    buttonClose.Location = new Point(form.ClientRectangle.Right - buttonClose.Width - 7, form.ClientRectangle.Bottom - buttonClose.Height - 7);



                    form.AcceptButton = buttonClose;
                    form.CancelButton = buttonClose;

                    form.Paint += Form_Paint;

                    if (owner != null)
                    {
                        Form formOwner = owner as Form;
                        if ((formOwner != null) && (formOwner.TopMost == true))
                        {
                            form.TopMost = false;
                            form.TopMost = true;
                        }
                        form.ShowDialog(owner);
                    }
                    else
                    {
                        form.ShowDialog();
                    }
                } finally {
                    if (buttonClose != null)
                    {
                        buttonClose.Dispose();
                    }
                    if (buttonReadme != null)
                    {
                        buttonReadme.Dispose();
                    }
                    if (buttonWebPage != null)
                    {
                        buttonWebPage.Dispose();
                    }

                    if (fullName != null)
                    {
                        fullName.Dispose();
                    }
                    if (dotNetFramework != null)
                    {
                        dotNetFramework.Dispose();
                    }
                    if (osVersion != null)
                    {
                        osVersion.Dispose();
                    }
                    if (copyright != null)
                    {
                        copyright.Dispose();
                    }

                    if (_paintImage != null)
                    {
                        _paintImage.Dispose();
                    }
                    if (_paintProduct != null)
                    {
                        _paintProduct.Dispose();
                    }

                    if (productFont != null)
                    {
                        productFont.Dispose();
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private static void ShowForm(IWin32Window owner, Uri webpage, string productText, string applicationText, string copyrightText, string applicationPath)
        {
            Font productFont = null;

            PaintItem fullName = null;
            PaintItem dotNetFramework = null;
            PaintItem osVersion = null;
            PaintItem copyright = null;

            Button buttonReadme = null;
            Button buttonClose = null;
            Button buttonWebPage = null;

            using (var form = new Form()) {
                try {
                    form.FormBorderStyle = FormBorderStyle.FixedDialog;
                    form.ShowIcon = false;
                    form.ShowInTaskbar = false;
                    form.MinimizeBox = false;
                    form.MaximizeBox = false;
                    form.AutoSize = false;
                    form.AutoScaleMode = AutoScaleMode.None;
                    form.Text = Resources.Caption;

                    int imageHeight = 32;
                    int maxRight = 320;
                    int maxBottom = 80;
                    using (Graphics graphics = form.CreateGraphics()) {
                        //icon
                        Bitmap bitmap = NativeMethods.GetIconBitmap(applicationPath);
                        if (bitmap != null) {
                            _paintImage = new PaintItem(bitmap, new Point(7, 7));
                        }

                        //title
                        int imageRight = 7;
                        if (_paintImage != null) {
                            imageRight = _paintImage.Rectangle.Right + 7;
                        }
                        if (_paintImage != null) {
                            imageHeight = _paintImage.Rectangle.Height;
                        }
                        productFont = new Font(SystemFonts.MessageBoxFont.Name, imageHeight, SystemFonts.MessageBoxFont.Style, GraphicsUnit.Pixel, SystemFonts.MessageBoxFont.GdiCharSet);
                        _paintProduct = new PaintItem(productText, productFont, imageRight, 7, imageHeight, VerticalAlignment.Center, graphics);

                        _titleHeight = 7 + imageHeight + 7;
                        maxRight = System.Math.Max(maxRight, _paintProduct.Rectangle.Right);
                        maxBottom = System.Math.Max(maxBottom, _titleHeight);

                        //other stuff
                        _infoLines = new List<PaintItem>();

                        fullName = new PaintItem(applicationText, SystemFonts.MessageBoxFont, 7, _titleHeight + 2 + 7, 0, VerticalAlignment.Top, graphics);
                        maxRight = System.Math.Max(maxRight, fullName.Rectangle.Right);
                        maxBottom = System.Math.Max(maxBottom, fullName.Rectangle.Bottom);
                        _infoLines.Add(fullName);

                        dotNetFramework = new PaintItem(".NET framework " + Environment.Version.ToString(), SystemFonts.MessageBoxFont, 7, fullName.Rectangle.Bottom, 0, VerticalAlignment.Top, graphics);
                        maxRight = System.Math.Max(maxRight, dotNetFramework.Rectangle.Right);
                        maxBottom = System.Math.Max(maxBottom, dotNetFramework.Rectangle.Bottom);
                        _infoLines.Add(dotNetFramework);

                        osVersion = new PaintItem(Environment.OSVersion.VersionString, SystemFonts.MessageBoxFont, 7, dotNetFramework.Rectangle.Bottom, 0, VerticalAlignment.Top, graphics);
                        maxRight = System.Math.Max(maxRight, osVersion.Rectangle.Right);
                        maxBottom = System.Math.Max(maxBottom, osVersion.Rectangle.Bottom);
                        _infoLines.Add(osVersion);

                        if (copyrightText != null) {
                            copyright = new PaintItem(copyrightText, SystemFonts.MessageBoxFont, 7, osVersion.Rectangle.Bottom + 7, 0, VerticalAlignment.Top, graphics);
                            maxRight = System.Math.Max(maxRight, copyright.Rectangle.Right);
                            maxBottom = System.Math.Max(maxBottom, copyright.Rectangle.Bottom);
                            _infoLines.Add(copyright);
                        }
                    }

                    int buttonMinRight = 7;

                    //Close button
                    buttonClose = new Button() { Padding = new Padding(3, 1, 3, 1) };
                    buttonClose.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
                    buttonClose.AutoSize = true;
                    buttonClose.DialogResult = DialogResult.OK;
                    buttonClose.Text = Resources.Close;
                    form.Controls.Add(buttonClose);
                    buttonMinRight += buttonClose.Width + 11;

                    //Readme button
                    var readMePath = GetReadMePath();
                    if (readMePath != null) {
                        buttonReadme = new Button() { Padding = new Padding(3, 1, 3, 1) };
                        buttonReadme.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
                        buttonReadme.AutoSize = true;
                        buttonReadme.Text = Resources.ReadMe;
                        buttonReadme.Tag = readMePath;
                        buttonReadme.Click += new EventHandler(buttonReadme_Click);
                        form.Controls.Add(buttonReadme);
                        buttonMinRight += buttonReadme.Width + 7;
                    }

                    //WebPage button
                    if (webpage != null) {
                        buttonWebPage = new Button() { Padding = new Padding(3, 1, 3, 1) };
                        buttonWebPage.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
                        buttonWebPage.AutoSize = true;
                        buttonWebPage.Text = Resources.WebPage;
                        buttonWebPage.Tag = webpage.ToString();
                        buttonWebPage.Click += new EventHandler(buttonWebPage_Click);
                        form.Controls.Add(buttonWebPage);
                        buttonMinRight += buttonWebPage.Width + 7;
                    }

                    maxRight = System.Math.Max(maxRight, buttonMinRight);

                    int borderX = (form.Width - form.ClientRectangle.Width);
                    int borderY = (form.Height - form.ClientRectangle.Height);
                    form.Width = borderX + maxRight + 7;
                    form.Height = borderY + maxBottom + 11 + 11 + buttonClose.Size.Height + 7;
                    if (owner == null) {
                        form.StartPosition = FormStartPosition.CenterScreen;
                    } else {
                        form.StartPosition = FormStartPosition.CenterParent;
                    }

                    int buttonLeft = form.ClientRectangle.Left + 7;

                    if (buttonReadme != null) {
                        buttonReadme.Location = new Point(buttonLeft, form.ClientRectangle.Bottom - buttonClose.Height - 7);
                        buttonLeft += buttonReadme.Width + 7;
                    }

                    if (buttonWebPage != null) {
                        buttonWebPage.Location = new Point(buttonLeft, form.ClientRectangle.Bottom - buttonClose.Height - 7);
                        buttonLeft += buttonWebPage.Width + 7;
                    }

                    buttonClose.Location = new Point(form.ClientRectangle.Right - buttonClose.Width - 7, form.ClientRectangle.Bottom - buttonClose.Height - 7);

                    form.AcceptButton = buttonClose;
                    form.CancelButton = buttonClose;

                    form.Paint += Form_Paint;

                    if (owner != null) {
                        Form formOwner = owner as Form;
                        if ((formOwner != null) && (formOwner.TopMost == true)) {
                            form.TopMost = false;
                            form.TopMost = true;
                        }
                        form.ShowDialog(owner);
                    } else {
                        form.ShowDialog();
                    }
                } finally {
                    if (buttonClose != null) { buttonClose.Dispose(); }
                    if (buttonReadme != null) { buttonReadme.Dispose(); }
                    if (buttonWebPage != null) { buttonWebPage.Dispose(); }

                    if (fullName != null) { fullName.Dispose(); }
                    if (dotNetFramework != null) { dotNetFramework.Dispose(); }
                    if (osVersion != null) { osVersion.Dispose(); }
                    if (copyright != null) { copyright.Dispose(); }

                    if (_paintImage != null) { _paintImage.Dispose(); }
                    if (_paintProduct != null) { _paintProduct.Dispose(); }

                    if (productFont != null) { productFont.Dispose(); }
                }
            }
        }