| | |
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 点击的坐标
|
| | | /// </summary>
|
| | | private System.Drawing.Point downPoint = new System.Drawing.Point();
|
| | |
|
| | | /// <summary>
|
| | | /// 控件的点击事件(自定义封装事件,此事件被认可为执行按钮按下事件,受CanClick属性控制)
|
| | | /// </summary>
|
| | | public Action<Button, MouseEventArgs> ButtonClickEvent = null;
|
| | |
| | | /// 控件的按下事件(自定义封装事件,此事件被认可为执行按钮按下事件,受CanClick属性控制)
|
| | | /// </summary>
|
| | | public Action<Button, MouseEventArgs> ButtonDownClickEvent = null;
|
| | | /// <summary>
|
| | | /// 控件触发移动的事件(自身拥有算法,当移动多少像素后,触发事件,注意,该事件可能会频繁的触发)
|
| | | /// </summary>
|
| | | public Action ButtonHappenMoveEvent = null;
|
| | |
|
| | | #endregion
|
| | |
|
| | |
| | | this.MouseUpEventHandler += ButtonBase_MouseUpEventHandler;
|
| | | //按下事件
|
| | | this.MouseDownEventHandler += ButtonBase_MouseDownEventHandler;
|
| | | //移动事件
|
| | | this.MouseMoveEventHandler += ButtonBase_MouseMoveEventHandler;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | /// <param name="e"></param>
|
| | | private void ButtonBase_MouseDownEventHandler(object sender, MouseEventArgs e)
|
| | | {
|
| | | //记录起当前点击的坐标
|
| | | downPoint.X = (int)e.X;
|
| | | downPoint.Y = (int)e.Y;
|
| | |
|
| | | if (CanClick == false || this.ButtonDownClickEvent == null)
|
| | | {
|
| | | //不能点击
|
| | |
| | | alert.Show();
|
| | | //Log出力
|
| | | HdlLogLogic.Current.WriteLog(ex);
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 移动事件___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 移动事件
|
| | | /// </summary>
|
| | | /// <param name="sender"></param>
|
| | | /// <param name="e"></param>
|
| | | private void ButtonBase_MouseMoveEventHandler(object sender, MouseEventArgs e)
|
| | | {
|
| | | if (this.ButtonHappenMoveEvent == null)
|
| | | {
|
| | | this.MouseMoveEventHandler -= ButtonBase_MouseMoveEventHandler;
|
| | | return;
|
| | | }
|
| | | int value = (int)e.X - this.downPoint.X;
|
| | | if (value >= 30 || value <= -30)
|
| | | {
|
| | | //触发移动事件
|
| | | this.ButtonHappenMoveEvent();
|
| | | return;
|
| | | }
|
| | | value = (int)e.Y - this.downPoint.Y;
|
| | | if (value >= 30 || value <= -30)
|
| | | {
|
| | | //触发移动事件
|
| | | this.ButtonHappenMoveEvent();
|
| | | return;
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | ButtonClickEvent = null;
|
| | | ButtonDownClickEvent = null;
|
| | |
|
| | | base.RemoveFromParent();
|
| | | if (this.Parent != null)
|
| | | {
|
| | | base.RemoveFromParent();
|
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | /// <returns></returns>
|
| | | public int GetRealWidthByText()
|
| | | {
|
| | | if (string.IsNullOrEmpty(this.Text) == true) { return Application.GetRealWidth(25); }
|
| | | #if Android
|
| | | //需要增加一个误差值
|
| | | return this.GetTextWidth() + Application.GetRealWidth(12);
|