Esempio n. 1
0
 ///<summary>Change button to hover state and repaint if needed.</summary>
 protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e)
 {
     if (!Enabled)
     {
         return;
     }
     base.OnMouseUp(e);
     if ((e.Button & MouseButtons.Left) != MouseButtons.Left)
     {
         return;
     }
     mouseIsDown = false;
     if (butStateL == ODButtonState.Pressed ||
         butStateR == ODButtonState.Pressed ||
         butStateM == ODButtonState.Pressed)
     {
         OnScrollComplete();
     }
     butStateL = ODButtonState.Normal;
     butStateR = ODButtonState.Normal;
     butStateM = ODButtonState.Normal;
     if (GetPathLeft().IsVisible(e.Location))
     {
         butStateL = ODButtonState.Hover;
     }
     else if (GetPathRight().IsVisible(e.Location))
     {
         butStateR = ODButtonState.Hover;
     }
     else if (GetRectMiddle().Contains(e.Location))
     {
         butStateM = ODButtonState.Hover;
     }
     Invalidate();
 }
Esempio n. 2
0
 ///<summary>Change the button to a pressed state.</summary>
 protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
 {
     if (!Enabled)
     {
         return;
     }
     base.OnMouseDown(e);
     if ((e.Button & MouseButtons.Left) != MouseButtons.Left)
     {
         return;
     }
     mouseIsDown = true;
     mouseDownX  = e.X;
     butStateL   = ODButtonState.Normal;
     butStateR   = ODButtonState.Normal;
     butStateM   = ODButtonState.Normal;
     if (GetPathLeft().IsVisible(e.Location))            //if mouse pressed within the left button
     {
         butStateL    = ODButtonState.Pressed;
         originalPixL = (float)MinVal * tick + endW / 2f;
     }
     else if (GetPathRight().IsVisible(e.Location))
     {
         butStateR    = ODButtonState.Pressed;
         originalPixR = (float)MaxVal * tick + endW / 2f;
     }
     else if (GetRectMiddle().Contains(e.Location))
     {
         butStateM    = ODButtonState.Pressed;
         originalPixL = (float)MinVal * tick + endW / 2f;
         originalPixR = (float)MaxVal * tick + endW / 2f;
     }
     Invalidate();
 }
Esempio n. 3
0
        private void DrawButton(Graphics g, GraphicsPath pathmain, ODButtonState state)
        {
            Color clrMain = Color.FromArgb(200, 202, 220);

            if (state == ODButtonState.Hover)
            {
                clrMain = Color.FromArgb(240, 240, 255);
            }
            else if (state == ODButtonState.Pressed)
            {
                clrMain = Color.FromArgb(150, 150, 160);
            }
            GraphicsPath pathsub = new GraphicsPath();
            RectangleF   rect    = pathmain.GetBounds();

            pathsub.AddEllipse(rect.Left - rect.Width / 8f, rect.Top - rect.Height / 2f, rect.Width, rect.Height * 3f / 2f);
            PathGradientBrush pathBrush = new PathGradientBrush(pathsub);

            pathBrush.CenterColor    = Color.FromArgb(255, 255, 255, 255);
            pathBrush.SurroundColors = new Color[] { Color.FromArgb(0, 255, 255, 255) };
            g.FillPath(new SolidBrush(clrMain), pathmain);
            g.FillPath(pathBrush, pathmain);
            Color clrDarkOverlay      = Color.FromArgb(50, 125, 125, 125);
            LinearGradientBrush brush = new LinearGradientBrush(new PointF(rect.Left, rect.Bottom),
                                                                new PointF(rect.Left, rect.Top + rect.Height / 2), Color.FromArgb(0, 0, 0, 0),
                                                                Color.FromArgb(50, 0, 0, 0));

            g.FillPath(brush, pathmain);
            Pen outline = new Pen(Color.FromArgb(28, 81, 128));

            g.DrawPath(outline, pathmain);
        }
Esempio n. 4
0
 ///<summary></summary>
 protected override void OnMouseDown(MouseEventArgs mea)
 {
     base.OnMouseDown(mea);
     if (mea.Button == MouseButtons.Left)
     {
         _bCanClick   = true;
         _buttonState = ODButtonState.Pressed;
         this.Invalidate();
     }
 }
Esempio n. 5
0
 ///<summary></summary>
 protected override void OnClick(EventArgs ea)
 {
     this.Capture = false;
     _bCanClick   = false;
     if (this.ClientRectangle.Contains(this.PointToClient(Control.MousePosition)))
     {
         _buttonState = ODButtonState.Hover;
     }
     else
     {
         _buttonState = ODButtonState.Normal;
     }
     this.Invalidate();
     base.OnClick(ea);
 }
Esempio n. 6
0
 ///<summary></summary>
 protected override void OnMouseMove(MouseEventArgs mea)
 {
     base.OnMouseMove(mea);
     if (ClientRectangle.Contains(mea.X, mea.Y))
     {
         if (_buttonState == ODButtonState.Hover && this.Capture && !_bCanClick)
         {
             _bCanClick   = true;
             _buttonState = ODButtonState.Pressed;
             this.Invalidate();
         }
     }
     else
     {
         if (_buttonState == ODButtonState.Pressed)
         {
             _bCanClick   = false;
             _buttonState = ODButtonState.Hover;
             this.Invalidate();
         }
     }
 }
Esempio n. 7
0
 ///<summary>Resets button appearance.  Repaints only if necessary.</summary>
 protected override void OnMouseLeave(System.EventArgs e)
 {
     if (!Enabled)
     {
         return;
     }
     base.OnMouseLeave(e);
     if (mouseIsDown)             //mouse is down
     //if a button is pressed, it will remain so, even if leave.  As long as mouse is down.
     //,so do nothing.
     //Also, if a button is not pressed, nothing will happen when leave
     //,so do nothing.
     {
     }
     else              //mouse is not down
     {
         butStateL = ODButtonState.Normal;
         butStateR = ODButtonState.Normal;
         butStateM = ODButtonState.Normal;
         Invalidate();
     }
 }
Esempio n. 8
0
 ///<summary></summary>
 protected override void OnMouseEnter(EventArgs ea)
 {
     base.OnMouseEnter(ea);
     _buttonState = ODButtonState.Hover;
     this.Invalidate();
 }
Esempio n. 9
0
 ///<summary></summary>
 protected override void OnEnabledChanged(EventArgs ea)
 {
     base.OnEnabledChanged(ea);
     _buttonState = ODButtonState.Normal;
     this.Invalidate();
 }
Esempio n. 10
0
 ///<summary></summary>
 protected override void OnMouseLeave(EventArgs ea)
 {
     base.OnMouseLeave(ea);
     _buttonState = ODButtonState.Normal;
     this.Invalidate();
 }
Esempio n. 11
0
 ///<summary></summary>
 protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e)
 {
     if (!Enabled)
     {
         return;
     }
     base.OnMouseMove(e);
     tick = (float)(Width - endW - 1) / 255f;
     if (mouseIsDown)
     {
         int   minAllowedL = 0;
         int   maxAllowedL;
         int   minAllowedR;
         int   maxAllowedR = 255;
         float deltaPix    = mouseDownX - e.X;
         if (butStateL == ODButtonState.Pressed)
         {
             MinVal      = (int)((originalPixL - deltaPix - endW / 2f) / tick);
             maxAllowedL = MaxVal - (int)(endW / tick);
             if (MinVal < minAllowedL)
             {
                 MinVal = minAllowedL;
             }
             else if (MinVal > maxAllowedL)
             {
                 MinVal = maxAllowedL;
             }
             OnScroll();
         }
         else if (butStateR == ODButtonState.Pressed)
         {
             MaxVal      = (int)((originalPixR - deltaPix - endW / 2f) / tick);
             minAllowedR = MinVal + (int)(endW / tick);
             if (MaxVal < minAllowedR)
             {
                 MaxVal = minAllowedR;
             }
             else if (MaxVal > maxAllowedR)
             {
                 MaxVal = maxAllowedR;
             }
             OnScroll();
         }
         else if (butStateM == ODButtonState.Pressed)
         {
             MinVal = (int)((originalPixL - deltaPix - endW / 2f) / tick);
             MaxVal = (int)((originalPixR - deltaPix - endW / 2f) / tick);
             int originalValSpan = (int)((originalPixR - originalPixL) / tick);
             maxAllowedL = maxAllowedR - originalValSpan;
             minAllowedR = minAllowedL + originalValSpan;
             if (MinVal < minAllowedL)
             {
                 MinVal = minAllowedL;
             }
             else if (MinVal > maxAllowedL)
             {
                 MinVal = maxAllowedL;
             }
             if (MaxVal < minAllowedR)
             {
                 MaxVal = minAllowedR;
             }
             else if (MaxVal > maxAllowedR)
             {
                 MaxVal = maxAllowedR;
             }
             OnScroll();
         }
     }
     else              //mouse is not down
     {
         butStateL = ODButtonState.Normal;
         butStateR = ODButtonState.Normal;
         butStateM = ODButtonState.Normal;
         if (GetPathLeft().IsVisible(e.Location))
         {
             butStateL = ODButtonState.Hover;
         }
         else if (GetPathRight().IsVisible(e.Location))
         {
             butStateR = ODButtonState.Hover;
         }
         else if (GetRectMiddle().Contains(e.Location))
         {
             butStateM = ODButtonState.Hover;
         }
     }
     Invalidate();
 }