/// <summary> /// 사용자 컨트롤 마우스 DOWN시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void UserControl_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { if (this.isClicked) { return; } this.isClicked = true; this.buttonState = ImageButtonState.Pressed; if (this.buttonStyle != ImageButtonStyle.Flat) { this.glowAlpha = 255; } this.fadeInTimer.Stop(); this.fadeOutTimer.Stop(); Invalidate(); } }
private void SetPressedContent() { State = ImageButtonState.Pressed; if (PressedContent != null) { content.Content = PressedContent; } }
/// <summary> /// 사용자 컨트롤 마우스 진입시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void UserControl_MouseEnter(object sender, EventArgs e) { this.buttonState = ImageButtonState.Hover; this.fadeOutTimer.Stop(); this.fadeInTimer.Start(); }
private void SetOverContent() { State = ImageButtonState.Over; if (OverContent != null) { content.Content = OverContent; } }
protected override void OnMouseDown(MouseEventArgs e) { if (!Enabled) return; state = ImageButtonState.Active; Invalidate(); base.OnMouseDown(e); }
protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); if (e.Button == System.Windows.Forms.MouseButtons.Left) { State = lastState; Invalidate(); } }
protected ImageButtonStateTest() { _button = new Button(); _enableImage = new Image(); _disableImage = new Image(); var genericType = typeof(T); _imageButtonState = (ImageButtonState)Activator.CreateInstance(genericType, _button, _enableImage, _disableImage); }
protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); if (e.Button == System.Windows.Forms.MouseButtons.Left) { lastState = State; State = ImageButtonState.Click; Invalidate(); } }
public ImageButton() { DefaultStyleKey = typeof(ImageButton); State = ImageButtonState.Normal; PointerPressed += OnPointerPressed; PointerReleased += OnPointerReleased; PointerExited += OnPointerExited; PointerEntered += OnPointerEntered; //Tapped += OnTapped; }
/// <summary> /// 사용자 컨트롤 마우스 이탈시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void UserControl_MouseLeave(object sender, EventArgs e) { this.buttonState = ImageButtonState.None; if (this.buttonStyle == ImageButtonStyle.Flat) { this.glowAlpha = 0; } this.fadeInTimer.Stop(); this.fadeOutTimer.Start(); this.isClicked = false; }
/// <summary> /// Reset the button state to its original value and /// update the graphical view of the button appropriately /// </summary> public void resetToOriginalState() { lock (this.mutexObj) { this.buttonState = this.originalButtonState; if (this.buttonState == ImageButtonState.DISABLED) { this.buttonControl.Enabled = false; } else { this.buttonControl.Enabled = true; if (this.buttonState == ImageButtonState.DEPRESSED) { this.buttonState = ImageButtonState.NORMAL; } } this.updateButton(); } }
/// <summary> /// 사용자 컨트롤 마우스 UP시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void UserControl_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { this.buttonState = ImageButtonState.Hover; this.fadeInTimer.Stop(); this.fadeOutTimer.Stop(); Invalidate(); if (this.calledByKey == true) { OnClick(EventArgs.Empty); this.calledByKey = false; } this.isClicked = false; } }
/// <summary> /// Constructor /// </summary> /// <param name="btnCtrl">Button control</param> /// <param name="btnName">Button name context contained within the resource</param> /// <param name="startDisabled">Whether or not the button should be disabled</param> public ImageButtonController(DesktopSession desktopSession, Button btnCtrl, string btnName, bool startDisabled) { this.DesktopSession = desktopSession; this.initialized = false; this.mutexObj = null; if (btnCtrl == null || string.IsNullOrEmpty(btnName)) { return; } this.mutexObj = new object(); lock (this.mutexObj) { this.buttonControl = btnCtrl; this.buttonName = btnName; this.buttonState = (startDisabled) ? ImageButtonState.DISABLED : ImageButtonState.NORMAL; if (this.buttonState == ImageButtonState.DISABLED) { this.buttonControl.Enabled = false; } this.initialized = true; this.originalButtonState = this.buttonState; this.updateButton(); } }
protected override void OnMouseLeave(EventArgs e) { State = ImageButtonState.Default; base.OnMouseLeave(e); Invalidate(); }
protected override void OnMouseEnter(EventArgs e) { State = ImageButtonState.Hover; base.OnMouseEnter(e); Invalidate(); }
public ImageButton() { State = ImageButtonState.Default; }
public StateImageButton() { State = ImageButtonState.Default; }
private object GetMemberValue(ImageButtonState imageButtonState, string name) { return(typeof(ImageButtonState).GetField(name, BindingFlags.NonPublic | BindingFlags.Instance).GetValue(imageButtonState)); }
protected override void OnMouseEnter(EventArgs e) { if (!Enabled) return; state = ImageButtonState.Hover; Invalidate(); base.OnMouseEnter(e); }
private void SetStandardContent() { State = ImageButtonState.Normal; content.Content = Content; }
private void SetOverContent() { State = ImageButtonState.Over; if (OverContent != null) content.Content = OverContent; }
private void SetPressedContent() { State = ImageButtonState.Pressed; if (PressedContent != null) content.Content = PressedContent; }
protected Button GetButton(ImageButtonState imageButtonState) { var member = GetMemberValue(imageButtonState, "_button") as Button; return(member); }
protected Image GetDisableImage(ImageButtonState imageButtonState) { var member = GetMemberValue(imageButtonState, "_disabledImage") as Image; return(member); }
/// <summary> /// Compute the new button state based on the input action and the /// current button state /// </summary> /// <param name="action">Action to perform against the current button state</param> public void performAction(ImageButtonAction action) { if (!this.initialized || this.buttonState == ImageButtonState.DISABLED) { return; } //Lock the class as the asynchronous nature of the UI could //and will cause data race conditions otherwise lock (this.mutexObj) { //Perform the button state change based on previous button state //and the input button action switch (this.buttonState) { //Apply the action against the NORMAL button state case ImageButtonState.NORMAL: if (action == ImageButtonAction.CLICK) { this.buttonState = ImageButtonState.DEPRESSED; } else if (action == ImageButtonAction.ENTER) { this.buttonState = ImageButtonState.HOVER; } else if (action == ImageButtonAction.HOVER) { this.buttonState = ImageButtonState.HOVER; } else if (action == ImageButtonAction.LEAVE) { this.buttonState = ImageButtonState.NORMAL; } break; //Apply the action against the HOVER button state case ImageButtonState.HOVER: if (action == ImageButtonAction.CLICK) { this.buttonState = ImageButtonState.DEPRESSED; } else if (action == ImageButtonAction.ENTER) { this.buttonState = ImageButtonState.HOVER; } else if (action == ImageButtonAction.HOVER) { this.buttonState = ImageButtonState.HOVER; } else if (action == ImageButtonAction.LEAVE) { this.buttonState = ImageButtonState.NORMAL; } break; //Apply the action against the DEPRESSED button state case ImageButtonState.DEPRESSED: if (action == ImageButtonAction.CLICK) { this.buttonState = ImageButtonState.HOVER; } else if (action == ImageButtonAction.ENTER) { this.buttonState = ImageButtonState.DEPRESSED; } else if (action == ImageButtonAction.HOVER) { this.buttonState = ImageButtonState.DEPRESSED; } else if (action == ImageButtonAction.LEAVE) { this.buttonState = ImageButtonState.DEPRESSED; } break; default: break; } //Update button this.updateButton(); }// End lock }
protected override void OnMouseLeave(EventArgs e) { if (!Enabled) return; state = ImageButtonState.Normal; Invalidate(); base.OnMouseLeave(e); }