Ejemplo n.º 1
0
        public void DrawInsetCircle(ref Graphics g, ref Rectangle r, Pen p)
        {
            int i;
            Pen p1 = new Pen(MetroDrawingMethods.GetDarkColor(p.Color, 50));
            Pen p2 = new Pen(MetroDrawingMethods.GetLightColor(p.Color, 50));

            for (i = 0; i <= p.Width; i++)
            {
                Rectangle r1 = new Rectangle(r.X + i, r.Y + i, r.Width - i * 2, r.Height - i * 2);
                g.DrawArc(p2, r1, -45, 180);
                g.DrawArc(p1, r1, 135, 180);
            }
        }
Ejemplo n.º 2
0
        public MetroKnobControl()
        {
            this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            this.SetStyle(ControlStyles.ResizeRedraw, true);
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            this.SetStyle(ControlStyles.UserPaint, true);
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);

            //This call is required by the Windows Form Designer.
            InitializeComponent();

            this.ImeMode = ImeMode.On;
            this.Name    = "Knob";
            this.Resize += new EventHandler(this.Knob_Resize);
            //this.ValueChanged += new ValueChangedEventHandler(this.ValueChanged);

            DottedPen           = new Pen(MetroDrawingMethods.GetDarkColor(_KnobBorderColor, 40));
            DottedPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
            DottedPen.DashCap   = System.Drawing.Drawing2D.DashCap.Round;
            setDimensions();

            InitColors();
        }
Ejemplo n.º 3
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            // create LinearGradientBrush for creating knob
            bKnob = new System.Drawing.Drawing2D.LinearGradientBrush(rKnob, MetroDrawingMethods.GetLightColor(KnobColor, 55), MetroDrawingMethods.GetDarkColor(KnobColor, 55), LinearGradientMode.ForwardDiagonal);
            // create LinearGradientBrush for knobPoint
            bKnobPoint = new System.Drawing.Drawing2D.LinearGradientBrush(rKnob, MetroDrawingMethods.GetLightColor(_KnobBorderColor, 55), MetroDrawingMethods.GetDarkColor(_KnobBorderColor, 55), LinearGradientMode.ForwardDiagonal);

            // Set background color of Image...
            e.Graphics.FillRectangle(new SolidBrush(_KnobBackColor), new Rectangle(0, 0, Width, Height));
            //gOffScreen.Clear(this.BackColor);
            // Fill knob Background to give knob effect....
            gOffScreen.FillEllipse(bKnob, rKnob);
            // Set antialias effect on
            gOffScreen.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            // Draw border of knob
            gOffScreen.DrawEllipse(new Pen(_KnobBorderColor), rKnob);

            //if control is focused
            if ((this._isFocused))
            {
                gOffScreen.DrawEllipse(DottedPen, rKnob);
            }
            // get current position of pointer
            Point Arrow = this.getKnobPosition();
            // Draw pointer arrow that shows knob position

            Rectangle rect = new Rectangle(Arrow.X - 3, Arrow.Y - 3, 6, 6);

            DrawInsetCircle(ref gOffScreen, ref rect, new Pen(_KnobBorderColor));

            // Draw small and large scale
            int i = Minimum;

            if ((this._ShowSmallScale))
            {
                for (i = Minimum; i <= Maximum; i = i + this._SmallChange)
                {
                    gOffScreen.DrawLine(new Pen(this.ForeColor), getMarkerPoint(0, i), getMarkerPoint(_SizeSmallScaleMarker, i));
                }
            }

            if ((this._ShowLargeScale))
            {
                for (i = Minimum; i <= Maximum; i = i + this._LargeChange)
                {
                    gOffScreen.DrawLine(new Pen(this.ForeColor), getMarkerPoint(0, i), getMarkerPoint(_SizeLargeScaleMarker, i));
                }
            }

            // Drawimage on screen
            g.DrawImage(OffScreenImage, 0, 0);
        }