示例#1
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);
        }
示例#2
0
        protected override void OnPaint(PaintEventArgs pevent)
        {
            base.OnPaint(pevent);

            if (!showSplit)
            {
                return;
            }

            Graphics  g      = pevent.Graphics;
            Rectangle bounds = ClientRectangle;

            // calculate the current dropdown rectangle.
            dropDownRectangle = new Rectangle(bounds.Right - PushButtonWidth - 1, BorderSize, PushButtonWidth, bounds.Height - BorderSize * 2);

            int       internalBorder = BorderSize;
            Rectangle focusRect      =
                new Rectangle(internalBorder,
                              internalBorder,
                              bounds.Width - dropDownRectangle.Width - internalBorder,
                              bounds.Height - (internalBorder * 2));

            Pen shadow = SystemPens.ButtonShadow;
            Pen face   = SystemPens.ButtonFace;


            shadow = new Pen(MetroPaint.BorderColor.Button.Disabled(Theme));
            face   = new Pen(MetroPaint.BorderColor.Button.Normal(Theme));

            // if (palette != null)
            // {
            //     shadow = new Pen(palette.ColorTable.GripDark);
            //     face = new Pen(palette.ColorTable.GripLight);
            // }

            if (RightToLeft == RightToLeft.Yes)
            {
                dropDownRectangle.X = bounds.Left + 1;
                focusRect.X         = dropDownRectangle.Right;

                // TODO: Fix Lines here?
                // draw two lines at the edge of the dropdown button
                g.DrawLine(shadow, bounds.Left + PushButtonWidth, BorderSize, bounds.Left + PushButtonWidth, bounds.Bottom - BorderSize);
                g.DrawLine(face, bounds.Left + PushButtonWidth + 1, BorderSize, bounds.Left + PushButtonWidth + 1, bounds.Bottom - BorderSize);
            }
            else
            {
                // draw two lines at the edge of the dropdown button
                g.DrawLine(shadow, bounds.Right - PushButtonWidth, BorderSize, bounds.Right - PushButtonWidth, bounds.Bottom - BorderSize);
                g.DrawLine(face, bounds.Right - PushButtonWidth - 1, BorderSize, bounds.Right - PushButtonWidth - 1, bounds.Bottom - BorderSize);
            }

            // Draw an arrow in the correct location
            MetroDrawingMethods.PaintDownArrow(g, dropDownRectangle, MetroPaint.BorderColor.Button.Disabled(Theme), 0, 0);
        }
示例#3
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);
            }
        }
示例#4
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();
        }
示例#5
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            //Set Colors
            Color nudTextColor = !useStyleColors?MetroPaint.ForeColor.NumericUpDown.Normal(Theme) : MetroPaint.GetStyleColor(Style);

            if (!this.Enabled)
            {
                nudTextColor = MetroPaint.ForeColor.NumericUpDown.Disabled(Theme);
            }

            Color nudTextBackColor = !useAlternateColors?MetroPaint.BackColor.NumericUpDown.Normal(Theme) : MetroPaint.BackColor.NumericUpDown.Alternate(Theme);

            Color nudControlsBorderColor = MetroPaint.BorderColor.NumericUpDown.Normal(Theme);
            Color nudControlsBackColor   = MetroPaint.BackColor.NumericUpDown.Normal(Theme);
            Color nudControlsForeColor   = MetroPaint.BorderColor.NumericUpDown.Normal(Theme);

            bool Debug = false; //for check consistency of the Rectangles

            var       gr      = e.Graphics;
            Rectangle nudRect = this.ClientRectangle;

            nudRect.Height -= 1;
            nudRect.Width  -= 1;


            gr.FillRectangle(new SolidBrush(nudControlsBackColor), nudRect);
            gr.DrawRectangle(new Pen(nudControlsBorderColor), nudRect);

            if (Debug)
            {
                gr.DrawRectangle(new Pen(Color.Red), nudRect);
            }

            foreach (Control c in this.Controls)
            {
                if (!(c is TextBox)) // -->Up Down Buttons
                {
                    //override inner's control paintevent (Button UP & Down)
                    typeof(Control).InvokeMember("DoubleBuffered", BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic, null, c, new object[] { true });
                    c.Paint += (sender, pev) =>
                    {
                        var g = pev.Graphics;
                        int h = c.Height;
                        int w = c.Width;

                        Rectangle buttonsUpDownRect = c.ClientRectangle;
                        buttonsUpDownRect.Height -= 1;
                        buttonsUpDownRect.Width  -= 1;

                        //control rectnagles
                        Rectangle UpArrowRect   = new Rectangle(1, 1, w - 3, h / 2 - 2);
                        Rectangle DownArrowRect = new Rectangle(1, h / 2, w - 3, h / 2 - 2);

                        //Draw Controls Rectangle
                        g.DrawRectangle(new Pen(nudControlsBackColor), buttonsUpDownRect);
                        if (Debug)
                        {
                            g.DrawRectangle(new Pen(Color.Green), buttonsUpDownRect);
                        }

                        //Cutom Draw Buttons
                        if (customDrawButtons)
                        {
                            //ClearBackGround
                            g.FillRectangle(new SolidBrush(nudControlsBackColor), buttonsUpDownRect);

                            //draw BackGround
                            g.FillRectangle(new SolidBrush(nudControlsBackColor), UpArrowRect);
                            g.FillRectangle(new SolidBrush(nudControlsBackColor), DownArrowRect);
                            g.DrawRectangle(new Pen(nudControlsBorderColor), UpArrowRect);
                            g.DrawRectangle(new Pen(nudControlsBorderColor), DownArrowRect);
                            if (Debug)
                            {
                                g.DrawRectangle(new Pen(Color.Violet), UpArrowRect);
                            }
                            if (Debug)
                            {
                                g.DrawRectangle(new Pen(Color.Blue), DownArrowRect);
                            }

                            //draw Arrows
                            MetroDrawingMethods.PaintUpArrow(g, UpArrowRect, nudControlsForeColor, 0, -1);
                            MetroDrawingMethods.PaintDownArrow(g, DownArrowRect, nudControlsForeColor, 0, 0);
                        }
                    };
                }
                else if ((c is TextBox))
                {
                    //Set Textbox fore Color
                    c.ForeColor = nudTextColor;
                    if (Debug)
                    {
                        c.ForeColor = Color.Red;
                    }

                    //Set Textbox back Color
                    c.BackColor = nudTextBackColor;
                    if (Debug)
                    {
                        c.BackColor = Color.Yellow;
                    }

                    c.Font = MetroFonts.Label(metroLabelSize, metroLabelWeight);
                }
            }
        }
示例#6
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Color backColor = MetroPaint.BackColor.Form(Theme);
            Color foreColor = MetroPaint.ForeColor.Title(Theme);

            e.Graphics.Clear(backColor);

            using (SolidBrush b = MetroPaint.GetStyleBrush(Style))
            {
                Rectangle topRect = new Rectangle(0, 0, Width, 5);
                e.Graphics.FillRectangle(b, topRect);
            }

            //Border Style
            if (BorderStyle != MetroFormBorderStyle.None)
            {
                Color c = MetroPaint.BorderColor.Form(Theme);

                using (Pen pen = new Pen(c))
                {
                    e.Graphics.DrawLines(pen, new[]
                    {
                        new Point(0, borderWidth),
                        new Point(0, Height - 1),
                        new Point(Width - 1, Height - 1),
                        new Point(Width - 1, borderWidth)
                    });
                }
            }

            //drwa Image
            if (backImage != null && backImageMaxSize != 0)
            {
                Image img = MetroDrawingMethods.ResizeImage(backImage, new Rectangle(0, 0, backImageMaxSize, backImageMaxSize));
                //if (_imageinvert)
                //{
                //    img = MetroImage.ResizeImage((Theme == MetroThemeStyle.Dark) ? _image : backImage, new Rectangle(0, 0, backImageMaxSize, backImageMaxSize));
                //}

                switch (backImageLocation)
                {
                case BackImgLocation.TopLeft:
                    e.Graphics.DrawImage(img, 0 + backImagePadding.Left, 0 + backImagePadding.Top);
                    break;

                case BackImgLocation.TopRight:
                    e.Graphics.DrawImage(img, ClientRectangle.Right - (backImagePadding.Right + img.Width), 0 + backImagePadding.Top);
                    break;

                case BackImgLocation.BottomLeft:
                    e.Graphics.DrawImage(img, 0 + backImagePadding.Left, ClientRectangle.Bottom - (img.Height + backImagePadding.Bottom));
                    break;

                case BackImgLocation.BottomRight:
                    e.Graphics.DrawImage(img, ClientRectangle.Right - (backImagePadding.Right + img.Width),
                                         ClientRectangle.Bottom - (img.Height + backImagePadding.Bottom));
                    break;
                }
            }

            //draw Text
            TextRenderer.DrawText(e.Graphics, Text, MetroFonts.Title, new Point(20, 20), foreColor);

            //design Grip
            if (Resizable && (SizeGripStyle == SizeGripStyle.Auto || SizeGripStyle == SizeGripStyle.Show))
            {
                using (SolidBrush b = new SolidBrush(MetroPaint.ForeColor.FormGrip(Theme)))
                {
                    Size resizeHandleSize = new Size(2, 2);
                    e.Graphics.FillRectangles(b, new Rectangle[] {
                        new Rectangle(new Point(ClientRectangle.Width - 6, ClientRectangle.Height - 6), resizeHandleSize),
                        new Rectangle(new Point(ClientRectangle.Width - 10, ClientRectangle.Height - 10), resizeHandleSize),
                        new Rectangle(new Point(ClientRectangle.Width - 10, ClientRectangle.Height - 6), resizeHandleSize),
                        new Rectangle(new Point(ClientRectangle.Width - 6, ClientRectangle.Height - 10), resizeHandleSize),
                        new Rectangle(new Point(ClientRectangle.Width - 14, ClientRectangle.Height - 6), resizeHandleSize),
                        new Rectangle(new Point(ClientRectangle.Width - 6, ClientRectangle.Height - 14), resizeHandleSize)
                    });
                }
            }
        }