ProgressControl.cs :  » Testing » xUnit.net » Xunit » Gui » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Testing » xUnit.net 
xUnit.net » Xunit » Gui » ProgressControl.cs
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace Xunit.Gui{
    public partial class ProgressControl : UserControl, IDisposable
    {
        int barValue = 50;
        int minimum = 0;
        int maximum = 100;
        ProgressStatus status = ProgressStatus.Unknown;

        public ProgressControl()
        {
            InitializeComponent();

            DoubleBuffered = true;
        }

        Color DarkBackColor
        {
            get { return Color.FromArgb(160, 160, 160); }
        }

        Color DarkFillColor
        {
            get
            {
                if (status == ProgressStatus.Passing)
                    return Color.FromArgb(0, 128, 0);
                if (status == ProgressStatus.Failing)
                    return Color.FromArgb(128, 0, 0);
                if (status == ProgressStatus.Skipping)
                    return Color.FromArgb(128, 128, 0);
                if (status == ProgressStatus.Cancelled)
                    return Color.FromArgb(0, 0, 128);

                return Color.FromArgb(192, 96, 0);
            }
        }

        protected override Size DefaultSize
        {
            get { return new Size(200, 23); }
        }

        Color LightBackColor
        {
            get { return Color.FromArgb(252, 252, 252); }
        }

        Color LightFillColor
        {
            get
            {
                if (status == ProgressStatus.Passing)
                    return Color.FromArgb(205, 255, 205);
                if (status == ProgressStatus.Failing)
                    return Color.FromArgb(255, 205, 205);
                if (status == ProgressStatus.Skipping)
                    return Color.FromArgb(255, 255, 205);
                if (status == ProgressStatus.Cancelled)
                    return Color.FromArgb(205, 205, 255);

                return Color.FromArgb(255, 230, 205);
            }
        }

        [Category("Behavior")]
        [DefaultValue(0)]
        public int Minimum
        {
            get { return minimum; }
            set
            {
                if (value >= Maximum)
                    throw new ArgumentException("Minimum must be less than Maximum");

                minimum = value;
                Invalidate();
            }
        }

        [Category("Behavior")]
        [DefaultValue(100)]
        public int Maximum
        {
            get { return maximum; }
            set
            {
                if (value <= Minimum)
                    throw new ArgumentException("Maximum must be greater than Minimum");

                maximum = value;
                Invalidate();
            }
        }

        double Offset
        {
            get { return Math.Min(Value - Minimum, Range); }
        }

        double Range
        {
            get { return Math.Abs(Maximum - Minimum); }
        }

        [Category("Behavior")]
        [DefaultValue(ProgressStatus.Passing)]
        public ProgressStatus Status
        {
            get { return status; }
            set { status = value; Invalidate(); }
        }

        [Category("Behavior")]
        [DefaultValue(50)]
        public int Value
        {
            get { return barValue; }
            set
            {
                if (value < Minimum || value > Maximum)
                    throw new ArgumentException("Value must be between Minimum and Maximum");

                barValue = value;
                Invalidate();
            }
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            Rectangle rect = new Rectangle(0, 0, Width, Height);

            using (Brush borderBrush = new SolidBrush(Color.FromName("ActiveBorder")))
                e.Graphics.FillRectangle(borderBrush, rect);

            rect.Offset(1, 1);
            rect.Width -= 2;
            rect.Height -= 2;

            using (Brush backBrush = new LinearGradientBrush(rect,
                                                             LightBackColor,
                                                             DarkBackColor,
                                                             LinearGradientMode.Vertical))
                e.Graphics.FillRectangle(backBrush, rect);

            if (Range > 0.0)
            {
                rect.Width = (int)((double)rect.Width * Offset / Range);

                if (rect.Width > 0)
                    using (Brush fillBrush = new LinearGradientBrush(rect,
                                                                     LightFillColor,
                                                                     DarkFillColor,
                                                                     LinearGradientMode.Vertical))
                        e.Graphics.FillRectangle(fillBrush, rect);
            }
        }

        public void Increment()
        {
            if (Value < Maximum)
                Value++;
        }

        protected override void OnSizeChanged(EventArgs e)
        {
            base.OnSizeChanged(e);

            Invalidate();
        }

        public enum ProgressStatus
        {
            Passing,
            Skipping,
            Failing,
            Cancelled,
            Unknown,
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.