Exemplo n.º 1
0
 protected override void OnResize(EventArgs e)
 {
     Width    = (Height - 2) * 2;
     diameter = Width / 2;
     artis    = 4 * diameter / 30;
     rect     = new RoundedRectangleF(2 * diameter, diameter + 2, diameter / 2, 1, 1);
     circle   = new RectangleF(!isOn ? 1 : Width - diameter - 1, 1, diameter, diameter);
     base.OnResize(e);
 }
Exemplo n.º 2
0
        public SlideButton()
        {
            Cursor         = Cursors.Hand;
            DoubleBuffered = true;

            artis       = 4; //increment for sliding animation
            diameter    = 30;
            textEnabled = true;
            rect        = new RoundedRectangleF(2 * diameter, diameter + 2, diameter / 2, 1, 1);
            circle      = new RectangleF(1, 1, diameter, diameter);
            isOn        = true;
            borderColor = Color.LightGray;

            paintTicker.Tick    += paintTicker_Tick;
            paintTicker.Interval = 1;
        }
Exemplo n.º 3
0
        public AltoButton()
        {
            Width       = 65;
            Height      = 30;
            stroke      = false;
            strokeColor = Color.Gray;
            inactive1   = Color.FromArgb(44, 188, 210);
            inactive2   = Color.FromArgb(33, 167, 188);
            active1     = Color.FromArgb(64, 168, 183);
            active2     = Color.FromArgb(36, 164, 183);

            radius      = 10;
            roundedRect = new RoundedRectangleF(Width, Height, radius);

            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer |
                     ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor |
                     ControlStyles.UserPaint, true);
            BackColor    = Color.Transparent;
            ForeColor    = Color.Black;
            Font         = new System.Drawing.Font("Comic Sans MS", 10, FontStyle.Bold);
            state        = MouseState.Leave;
            transparency = false;
        }
Exemplo n.º 4
0
        protected override void OnPaint(PaintEventArgs e)
        {
            #region Transparency
            if (transparency)
            {
                Transparenter.MakeTransparent(this, e.Graphics);
            }
            #endregion

            #region Drawing
            e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
            roundedRect = new RoundedRectangleF(Width, Height, radius);
            e.Graphics.FillRectangle(Brushes.Transparent, this.ClientRectangle);

            int R1 = (active1.R + inactive1.R) / 2;
            int G1 = (active1.G + inactive1.G) / 2;
            int B1 = (active1.B + inactive1.B) / 2;

            int R2 = (active2.R + inactive2.R) / 2;
            int G2 = (active2.G + inactive2.G) / 2;
            int B2 = (active2.B + inactive2.B) / 2;

            Rectangle rect = new Rectangle(0, 0, Width, Height);

            if (this.Enabled)
            {
                if (state == MouseState.Leave)
                {
                    using (LinearGradientBrush inactiveGB = new LinearGradientBrush(rect, inactive1, inactive2, 90f))
                        e.Graphics.FillPath(inactiveGB, roundedRect.Path);
                }
                else if (state == MouseState.Enter)
                {
                    using (LinearGradientBrush activeGB = new LinearGradientBrush(rect, active1, active2, 90f))
                        e.Graphics.FillPath(activeGB, roundedRect.Path);
                }
                else if (state == MouseState.Down)
                {
                    using (LinearGradientBrush downGB = new LinearGradientBrush(rect, Color.FromArgb(R1, G1, B1), Color.FromArgb(R2, G2, B2), 90f))
                        e.Graphics.FillPath(downGB, roundedRect.Path);
                }
                if (stroke)
                {
                    using (Pen pen = new Pen(strokeColor, 1))
                        using (GraphicsPath path = new RoundedRectangleF(Width - (radius > 0 ? 0 : 1), Height - (radius > 0 ? 0 : 1), radius).Path)
                            e.Graphics.DrawPath(pen, path);
                }
            }
            else
            {
                Color linear1 = Color.FromArgb(190, 190, 190);
                Color linear2 = Color.FromArgb(210, 210, 210);
                using (LinearGradientBrush inactiveGB = new LinearGradientBrush(rect, linear1, linear2, 90f))
                {
                    e.Graphics.FillPath(inactiveGB, roundedRect.Path);
                    e.Graphics.DrawPath(new Pen(inactiveGB), roundedRect.Path);
                }
            }


            #endregion

            #region Text Drawing
            using (StringFormat sf = new StringFormat()
            {
                LineAlignment = StringAlignment.Center,
                Alignment = StringAlignment.Center
            })
                using (Brush brush = new SolidBrush(ForeColor))
                    e.Graphics.DrawString(Text, Font, brush, this.ClientRectangle, sf);
            #endregion
            base.OnPaint(e);
        }