| | |
| | | else { this.SetClickStatu(); }
|
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 是否是长按状态
|
| | | /// 圆角度
|
| | | /// </summary>
|
| | | private bool isLongClick = false;
|
| | | public int RadiusEx
|
| | | {
|
| | | set { this.Radius = (uint)Application.GetRealHeight(value); }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 控件的点击事件(自定义封装事件,此事件被认可为执行按钮按下事件,受CanClick属性控制)
|
| | | /// </summary>
|
| | | public Action<Button, MouseEventArgs> ButtonClickEvent = null;
|
| | | /// <summary>
|
| | | /// (★当前不要使用★)控件的长按事件,当事件为null时,代表长按结束(自定义封装事件,此事件被认可为执行按钮长按事件,受CanClick属性控制)
|
| | | /// </summary>
|
| | | public Action<Button, MouseEventArgs> ButtonLongClickEvent = null;
|
| | | /// <summary>
|
| | | /// 控件的按下事件(自定义封装事件,此事件被认可为执行按钮按下事件,受CanClick属性控制)
|
| | | /// </summary>
|
| | |
| | | this.MouseUpEventHandler += ButtonBase_MouseUpEventHandler;
|
| | | //按下事件
|
| | | this.MouseDownEventHandler += ButtonBase_MouseDownEventHandler;
|
| | | //长按事件
|
| | | this.MouseLongEventHandler += ButtonBase_MouseLongEventHandler;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | |
|
| | | try
|
| | | {
|
| | | if (this.isLongClick == false)
|
| | | {
|
| | | this.ButtonClickEvent(this, e);
|
| | | }
|
| | | else if (ButtonLongClickEvent != null)
|
| | | {
|
| | | //长按结束
|
| | | this.ButtonLongClickEvent(this, null);
|
| | | }
|
| | | this.ButtonClickEvent(this, e);
|
| | | }
|
| | | catch (Exception ex)
|
| | | {
|
| | |
| | | HdlLogLogic.Current.WriteLog(ex);
|
| | | }
|
| | | }
|
| | | //状态还原
|
| | | this.isLongClick = false;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | /// <param name="e"></param>
|
| | | private void ButtonBase_MouseDownEventHandler(object sender, MouseEventArgs e)
|
| | | {
|
| | | //还原状态
|
| | | this.isLongClick = false;
|
| | |
|
| | | 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_MouseLongEventHandler(object sender, MouseEventArgs e)
|
| | | {
|
| | | //长按状态
|
| | | this.isLongClick = true;
|
| | |
|
| | | if (ButtonLongClickEvent == null)
|
| | | {
|
| | | this.MouseLongEventHandler -= ButtonBase_MouseLongEventHandler;
|
| | | return;
|
| | | }
|
| | | if (CanClick == true)
|
| | | {
|
| | | //Log出力
|
| | | this.WriteLog(1);
|
| | |
|
| | | try
|
| | | {
|
| | | this.ButtonLongClickEvent(this, e);
|
| | | }
|
| | | catch (Exception ex)
|
| | | {
|
| | | //出现未知错误
|
| | | var alert = new ShowMsgControl(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uUnKnownError));
|
| | | alert.Show();
|
| | | //Log出力
|
| | | HdlLogLogic.Current.WriteLog(ex);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | {
|
| | | ButtonClickEvent = null;
|
| | | ButtonDownClickEvent = null;
|
| | | ButtonLongClickEvent = null;
|
| | |
|
| | | base.RemoveFromParent();
|
| | | }
|
| | |
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 根据文本,计算它实际的宽度(返回的是真实值)
|
| | | /// 根据文本,计算它实际的宽度
|
| | | /// </summary>
|
| | | /// <param name="textSize">字体大小,省略时使用当前控件的字体大小</param>
|
| | | /// <param name="i_text">需要计算的文本信息,省略时使用当前控件的文本</param>
|
| | | /// <returns></returns>
|
| | | public int GetRealWidthByText(float textSize, string i_text = null)
|
| | | public int GetRealWidthByText()
|
| | | {
|
| | | if (i_text == null)
|
| | | {
|
| | | i_text = this.Text;
|
| | | }
|
| | | if (textSize == -1)
|
| | | {
|
| | | textSize = this.TextSize;
|
| | | }
|
| | |
|
| | | int byteLength = 0;
|
| | | for (int i = 0; i < i_text.Length; i++)
|
| | | {
|
| | | byteLength += Encoding.UTF8.GetBytes(i_text[i].ToString()).Length;
|
| | | //int length = Encoding.UTF8.GetBytes(i_text[i].ToString()).Length;
|
| | | //if (length == 1)
|
| | | //{
|
| | | // //英文
|
| | | // byteLength += length;
|
| | | // continue;
|
| | | //}
|
| | | ////中文(暂时用中文对应)
|
| | | //byteLength += Encoding.GetEncoding("gb2312").GetBytes(i_text[i].ToString()).Length;
|
| | | }
|
| | | int realWidth = byteLength * (int)textSize;
|
| | | return Application.GetRealWidth(realWidth + 20);
|
| | | #if Android
|
| | | //需要增加一个误差值
|
| | | return this.GetTextWidth() + Application.GetRealWidth(12);
|
| | | #endif
|
| | | #if iOS
|
| | | //需要增加一个误差值
|
| | | return this.GetTextWidth() + Application.GetRealWidth(25);
|
| | | #endif
|
| | | }
|
| | |
|
| | | #endregion
|