| | |
| | | private bool m_CanClick = true;
|
| | | /// <summary>
|
| | | /// 设置能否触点击事件
|
| | | /// </summary> |
| | | /// </summary>
|
| | | public bool CanClick
|
| | | {
|
| | | get { return m_CanClick; }
|
| | |
| | | else { this.SetClickStatu(); }
|
| | | }
|
| | | }
|
| | | /// <summary>
|
| | | /// 圆角度
|
| | | /// </summary>
|
| | | public int RadiusEx
|
| | | {
|
| | | set { this.Radius = (uint)Application.GetRealHeight(value); }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 控件的点击事件(此事件被认可为执行按钮按下事件,受CanClick属性控制)
|
| | | /// 点击的坐标
|
| | | /// </summary>
|
| | | private System.Drawing.Point downPoint = new System.Drawing.Point();
|
| | |
|
| | | /// <summary>
|
| | | /// 控件的点击事件(自定义封装事件,此事件被认可为执行按钮按下事件,受CanClick属性控制)
|
| | | /// </summary>
|
| | | public Action<Button, MouseEventArgs> ButtonClickEvent = null;
|
| | | /// <summary>
|
| | | /// 控件的按下事件(自定义封装事件,此事件被认可为执行按钮按下事件,受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>
|
| | | /// 初始化控件大小(不以平均值进行真实数值计算)
|
| | | /// </summary>
|
| | | /// <param name="i_Width">宽度</param> |
| | | /// <param name="i_Height">高度</param> |
| | | /// <param name="i_Width">宽度</param>
|
| | | /// <param name="i_Height">高度</param>
|
| | | /// <param name="real">是否计算真实值</param>
|
| | | public void InitSize(int i_Width, int i_Height, bool real = true)
|
| | | {
|
| | |
| | | {
|
| | | i_Width = Application.GetRealWidth(i_Width);
|
| | | i_Height = Application.GetRealHeight(i_Height);
|
| | | } |
| | | this.Height = i_Height; |
| | | }
|
| | | this.Height = i_Height;
|
| | | this.Width = i_Width;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 初始化控件大小(不以平均值进行真实数值计算)
|
| | | /// </summary>
|
| | | /// <param name="i_Width">宽度</param> |
| | | /// <param name="i_Width">宽度</param>
|
| | | /// <param name="real">是否计算真实值</param>
|
| | | public void InitSize(int i_Width, bool real = false)
|
| | | {
|
| | | if (real == true)
|
| | | {
|
| | | i_Width = Application.GetRealWidth(i_Width);
|
| | | } |
| | | |
| | | this.Height = ControlCommonResourse.NormalControlHeight; |
| | | }
|
| | |
|
| | | this.Height = ControlCommonResourse.NormalControlHeight;
|
| | | this.Width = i_Width;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 初始化控件大小(以平均值进行真实数值计算)
|
| | | /// 初始化图标控件大小(以平均值进行真实数值计算)
|
| | | /// </summary>
|
| | | /// <param name="i_Width">宽度</param> |
| | | /// <param name="i_Height">高度</param> |
| | | /// <param name="i_Width">宽度</param>
|
| | | /// <param name="i_Height">高度</param>
|
| | | /// <param name="real">是否计算真实值</param>
|
| | | public void InitAvgSize(int i_Width, int i_Height, bool real = true)
|
| | | public void InitIconSize(int i_Width, int i_Height, bool real = true)
|
| | | {
|
| | | if (real == true)
|
| | | {
|
| | | i_Width = Application.GetMinRealAverage(i_Width);
|
| | | i_Height = Application.GetMinRealAverage(i_Height);
|
| | | } |
| | | |
| | | this.Height = i_Height; |
| | | i_Width = this.GetPictrueRealSize(i_Width);
|
| | | i_Height = this.GetPictrueRealSize(i_Height);
|
| | | }
|
| | |
|
| | | this.Height = i_Height;
|
| | | this.Width = i_Width;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 初始化图片控件大小
|
| | | /// </summary>
|
| | | /// <param name="i_Width">宽度</param>
|
| | | /// <param name="i_Height">高度</param>
|
| | | /// <param name="real">是否计算真实值</param>
|
| | | public void InitPictrueSize(int i_Width, int i_Height, bool real = true)
|
| | | {
|
| | | if (real == true)
|
| | | {
|
| | | i_Width = HdlControlLogic.Current.GetPictrueRealSize(i_Width);
|
| | | i_Height = HdlControlLogic.Current.GetPictrueRealSize(i_Height);
|
| | | }
|
| | |
|
| | | this.Height = i_Height;
|
| | | this.Width = i_Width;
|
| | | }
|
| | |
|
| | |
| | | if (CanClick == true)
|
| | | {
|
| | | //Log出力
|
| | | this.WriteLog();
|
| | | this.WriteLog(0);
|
| | |
|
| | | try
|
| | | {
|
| | | this.ButtonClickEvent?.Invoke(this, e);
|
| | | this.ButtonClickEvent(this, e);
|
| | | }
|
| | | catch (Exception ex)
|
| | | {
|
| | | //出现未知错误,数据丢失
|
| | | var alert = new ShowMsgControl(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uUnknownErrorAndDataLost));
|
| | | //出现未知错误
|
| | | var alert = new ShowMsgControl(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uUnKnownError));
|
| | | alert.Show();
|
| | | //Log出力
|
| | | HdlLogLogic.Current.WriteLog(ex);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 按下事件___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 按下事件
|
| | | /// </summary>
|
| | | /// <param name="sender"></param>
|
| | | /// <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)
|
| | | {
|
| | | //不能点击
|
| | | return;
|
| | | }
|
| | |
|
| | | try
|
| | | {
|
| | | this.ButtonDownClickEvent(this, e);
|
| | | }
|
| | | catch (Exception ex)
|
| | | {
|
| | | //出现未知错误
|
| | | var alert = new ShowMsgControl(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uUnKnownError));
|
| | | 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;
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | #region ■ 一般方法___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 重置单击事件(此操作委托会变null)
|
| | | /// </summary>
|
| | | public void ResetClickEvent()
|
| | | {
|
| | | ButtonClickEvent = null;
|
| | | this.MouseUpEventHandler -= this.ButtonBase_MouseUpEventHandler;
|
| | | this.MouseUpEventHandler += this.ButtonBase_MouseUpEventHandler;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 控件摧毁
|
| | | /// </summary>
|
| | | public override void RemoveFromParent()
|
| | | {
|
| | | ButtonClickEvent = null;
|
| | | base.RemoveFromParent();
|
| | | ButtonDownClickEvent = null;
|
| | |
|
| | | if (this.Parent != null)
|
| | | {
|
| | | base.RemoveFromParent();
|
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | return;
|
| | | }
|
| | | //Y轴重置
|
| | | this.Y = UserCenterLogic.GetControlChidrenYaxis(this.Parent.Height, this.Height, alignment, Space);
|
| | | this.Y = HdlControlLogic.Current.GetControlChidrenYaxis(this.Parent.Height, this.Height, alignment, Space);
|
| | | }
|
| | |
|
| | | /// <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);
|
| | | if (string.IsNullOrEmpty(this.Text) == true) { return Application.GetRealWidth(25); }
|
| | | #if Android
|
| | | //需要增加一个误差值
|
| | | return this.GetTextWidth() + Application.GetRealWidth(12);
|
| | | #endif
|
| | | #if iOS
|
| | | //需要增加一个误差值
|
| | | return this.GetTextWidth() + Application.GetRealWidth(25);
|
| | | #endif
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 添加底部阴影特效(确保拥有父控件后才调用)
|
| | | /// 计算图片的真实高宽度
|
| | | /// </summary>
|
| | | public void AddBottomShadow()
|
| | | /// <param name="i_size"></param>
|
| | | /// <returns></returns>
|
| | | public int GetPictrueRealSize(int i_size)
|
| | | {
|
| | | var btnShadow = new PicViewControl(this.Width, Application.GetMinRealAverage(45), false);
|
| | | btnShadow.X = this.X;
|
| | | btnShadow.Y = this.Bottom - 1;
|
| | | btnShadow.UnSelectedImagePath = "Item/BottomShadow.png";
|
| | | this.Parent.AddChidren(btnShadow);
|
| | | return HdlControlLogic.Current.GetPictrueRealSize(i_size);
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | /// <summary>
|
| | | /// Log出力
|
| | | /// </summary>
|
| | | private void WriteLog()
|
| | | private void WriteLog(int div)
|
| | | {
|
| | | if (formName == null)
|
| | | {
|
| | |
| | | controlName = this.UnSelectedImagePath;
|
| | | }
|
| | | }
|
| | | HdlLogLogic.Current.WriteLog(1, formName + "的[" + controlName + "]按键被点击");
|
| | | if (div == 0)
|
| | | {
|
| | | HdlLogLogic.Current.WriteLog(1, formName + "的[" + controlName + "]按键被点击");
|
| | | }
|
| | | else
|
| | | {
|
| | | HdlLogLogic.Current.WriteLog(1, formName + "的[" + controlName + "]按键被长按");
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|