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 == Button.ControlState.Pressed ||
         butStateR == Button.ControlState.Pressed ||
         butStateM == Button.ControlState.Pressed)
     {
         OnScrollComplete();
     }
     butStateL = Button.ControlState.Normal;
     butStateR = Button.ControlState.Normal;
     butStateM = Button.ControlState.Normal;
     if (GetPathLeft().IsVisible(e.Location))
     {
         butStateL = Button.ControlState.Hover;
     }
     else if (GetPathRight().IsVisible(e.Location))
     {
         butStateR = Button.ControlState.Hover;
     }
     else if (GetRectMiddle().Contains(e.Location))
     {
         butStateM = Button.ControlState.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   = Button.ControlState.Normal;
     butStateR   = Button.ControlState.Normal;
     butStateM   = Button.ControlState.Normal;
     if (GetPathLeft().IsVisible(e.Location))            //if mouse pressed within the left button
     {
         butStateL    = Button.ControlState.Pressed;
         originalPixL = (float)MinVal * tick + endW / 2f;
     }
     else if (GetPathRight().IsVisible(e.Location))
     {
         butStateR    = Button.ControlState.Pressed;
         originalPixR = (float)MaxVal * tick + endW / 2f;
     }
     else if (GetRectMiddle().Contains(e.Location))
     {
         butStateM    = Button.ControlState.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, Button.ControlState state)
        {
            Color clrMain = Color.FromArgb(200, 202, 220);

            if (state == Button.ControlState.Hover)
            {
                clrMain = Color.FromArgb(240, 240, 255);
            }
            else if (state == Button.ControlState.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>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 = Button.ControlState.Normal;
         butStateR = Button.ControlState.Normal;
         butStateM = Button.ControlState.Normal;
         Invalidate();
     }
 }
Esempio n. 5
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==Button.ControlState.Pressed
				|| butStateR==Button.ControlState.Pressed
				|| butStateM==Button.ControlState.Pressed)
			{
				OnScrollComplete();
			}
			butStateL=Button.ControlState.Normal;
			butStateR=Button.ControlState.Normal;
			butStateM=Button.ControlState.Normal;
			if(GetPathLeft().IsVisible(e.Location)) {
				butStateL=Button.ControlState.Hover;
			}
			else if(GetPathRight().IsVisible(e.Location)) {
				butStateR=Button.ControlState.Hover;
			}
			else if(GetRectMiddle().Contains(e.Location)) {
				butStateM=Button.ControlState.Hover;
			}
			Invalidate();
		}
Esempio n. 6
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=Button.ControlState.Normal;
			butStateR=Button.ControlState.Normal;
			butStateM=Button.ControlState.Normal;
			if(GetPathLeft().IsVisible(e.Location)){//if mouse pressed within the left button
				butStateL=Button.ControlState.Pressed;
				originalPixL=(float)MinVal*tick+endW/2f;
			}
			else if(GetPathRight().IsVisible(e.Location)) {
				butStateR=Button.ControlState.Pressed;
				originalPixR=(float)MaxVal*tick+endW/2f;
			}
			else if(GetRectMiddle().Contains(e.Location)) {
				butStateM=Button.ControlState.Pressed;
				originalPixL=(float)MinVal*tick+endW/2f;
				originalPixR=(float)MaxVal*tick+endW/2f;
			}
			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=Button.ControlState.Normal;
				butStateR=Button.ControlState.Normal;
				butStateM=Button.ControlState.Normal;
				Invalidate();
			}
		}
Esempio n. 8
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==Button.ControlState.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==Button.ControlState.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==Button.ControlState.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=Button.ControlState.Normal;
				butStateR=Button.ControlState.Normal;
				butStateM=Button.ControlState.Normal;
				if(GetPathLeft().IsVisible(e.Location)){
					butStateL=Button.ControlState.Hover;
				}
				else if(GetPathRight().IsVisible(e.Location)) {
					butStateR=Button.ControlState.Hover;
				}
				else if(GetRectMiddle().Contains(e.Location)){
					butStateM=Button.ControlState.Hover;
				}
			}
			Invalidate();
		}
Esempio n. 9
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 == Button.ControlState.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 == Button.ControlState.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 == Button.ControlState.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 = Button.ControlState.Normal;
         butStateR = Button.ControlState.Normal;
         butStateM = Button.ControlState.Normal;
         if (GetPathLeft().IsVisible(e.Location))
         {
             butStateL = Button.ControlState.Hover;
         }
         else if (GetPathRight().IsVisible(e.Location))
         {
             butStateR = Button.ControlState.Hover;
         }
         else if (GetRectMiddle().Contains(e.Location))
         {
             butStateM = Button.ControlState.Hover;
         }
     }
     Invalidate();
 }