using Shared;
|
using HDL_ON.UI.CSS;
|
using System;
|
using System.Collections.Generic;
|
using System.Text;
|
|
namespace HDL_ON.Stan
|
{
|
/// <summary>
|
/// Botton的最初原型(不建议修改和直接使用):标准字体和颜色,文字向左靠齐,14号字
|
/// </summary>
|
public class ButtonCtrBase : Button
|
{
|
#region ■ 变量声明___________________________
|
|
/// <summary>
|
/// 设置能否触点击事件
|
/// </summary>
|
private bool m_CanClick = true;
|
/// <summary>
|
/// 设置能否触点击事件
|
/// </summary>
|
public bool CanClick
|
{
|
get { return m_CanClick; }
|
set
|
{
|
if (m_CanClick == value) { return; }
|
|
m_CanClick = value;
|
//能够点击,则显示没有点击过的状态
|
if (m_CanClick == true) { this.SetNotClickStatu(); }
|
//不能点击,则显示已经点击了的状态
|
else { this.SetClickStatu(); }
|
}
|
}
|
/// <summary>
|
/// 声明此变量,旨在子线程也能够去获取一个控件的主键
|
/// </summary>
|
public string MainKey = string.Empty;
|
|
/// <summary>
|
/// 点击的坐标
|
/// </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
|
|
#region ■ 重写彪哥的属性_____________________
|
|
/// <summary>
|
/// 重写Text属性(文本中有{0}的话,会自动全部替换为换行符)
|
/// </summary>
|
public new string Text
|
{
|
//先这么弄先吧
|
get { return base.Text == null ? string.Empty : base.Text; }
|
set
|
{
|
base.Text = value == null ? string.Empty : value.Replace("{0}", "\r\n");
|
}
|
}
|
|
/// <summary>
|
/// 选中状态(重写底层属性)
|
/// </summary>
|
public new bool IsSelected
|
{
|
get { return base.IsSelected; }
|
set
|
{
|
//只有状态不一样,才变更
|
if (base.IsSelected != value)
|
{
|
base.IsSelected = value;
|
}
|
}
|
}
|
|
/// <summary>
|
/// 非选中状态的背景图路径(重写底层属性)
|
/// </summary>
|
public new string UnSelectedImagePath
|
{
|
get { return base.UnSelectedImagePath; }
|
set
|
{
|
//只有图片不一样,才变更
|
if (base.UnSelectedImagePath != value)
|
{
|
base.UnSelectedImagePath = value;
|
}
|
}
|
}
|
|
/// <summary>
|
/// 选中状态的背景图路径(重写底层属性)
|
/// </summary>
|
public new string SelectedImagePath
|
{
|
get { return base.SelectedImagePath; }
|
set
|
{
|
//只有图片不一样,才变更
|
if (base.SelectedImagePath != value)
|
{
|
base.SelectedImagePath = value;
|
}
|
}
|
}
|
|
/// <summary>
|
/// 背景色(重写底层属性)
|
/// </summary>
|
public new uint BackgroundColor
|
{
|
get { return base.BackgroundColor; }
|
set
|
{
|
//只有不一样,才变更
|
if (base.BackgroundColor != value)
|
{
|
base.BackgroundColor = value;
|
}
|
}
|
}
|
|
/// <summary>
|
/// 字体颜色(重写底层属性)
|
/// </summary>
|
public new uint TextColor
|
{
|
get { return base.TextColor; }
|
set
|
{
|
//只有不一样,才变更
|
if (base.TextColor != value)
|
{
|
base.TextColor = value;
|
}
|
}
|
}
|
|
#endregion
|
|
#region ■ 初始化_____________________________
|
|
/// <summary>
|
/// Botton的最初原型(不建议修改和直接使用):标准字体和颜色,文字向左靠齐,14号字
|
/// </summary>
|
public ButtonCtrBase()
|
{
|
#if __IOS__
|
//重写修改文本到边框的内边距为0
|
(this.uiView as MyButton).ContentEdgeInsets = new UIKit.UIEdgeInsets(0, 0, 0, 0);
|
#endif
|
//测试,全体按钮为14号字
|
this.TextSize = CSS_FontSize.TextFontSize;
|
|
this.TextColor = CSS_Color.TextualColor;
|
this.TextAlignment = TextAlignment.CenterLeft;
|
|
//点击事件
|
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="real">是否计算真实值</param>
|
public void InitSize(int i_Width, int i_Height, bool real = true)
|
{
|
if (real == true)
|
{
|
i_Width = Application.GetRealWidth(i_Width);
|
i_Height = Application.GetRealHeight(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 InitIconSize(int i_Width, int i_Height, bool real = true)
|
{
|
if (real == true)
|
{
|
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 = Application.GetRealWidth(i_Width);
|
i_Height = Application.GetRealWidth(i_Height);
|
}
|
|
this.Height = i_Height;
|
this.Width = i_Width;
|
}
|
|
#endregion
|
|
#region ■ 点击事件___________________________
|
|
/// <summary>
|
/// 点击事件
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void ButtonBase_MouseUpEventHandler(object sender, MouseEventArgs e)
|
{
|
if (ButtonClickEvent == null)
|
{
|
this.MouseUpEventHandler -= ButtonBase_MouseUpEventHandler;
|
return;
|
}
|
if (CanClick == true)
|
{
|
try
|
{
|
this.ButtonClickEvent(this, e);
|
}
|
catch (Exception ex)
|
{
|
//出现未知错误
|
HdlMessageLogic.Current.ShowAppProgramIsError(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)
|
{
|
//出现未知错误
|
HdlMessageLogic.Current.ShowAppProgramIsError(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;
|
}
|
}
|
|
#endregion
|
|
#region ■ 设置点击状态_______________________
|
|
/// <summary>
|
/// 设置点击后的状态(此方法由各自控件进行重载)
|
/// </summary>
|
public virtual void SetClickStatu()
|
{
|
}
|
|
/// <summary>
|
/// 设置非点击后的状态(此方法由各自控件进行重载)
|
/// </summary>
|
public virtual void SetNotClickStatu()
|
{
|
}
|
|
#endregion
|
|
#region ■ 一般方法___________________________
|
|
/// <summary>
|
/// 控件摧毁
|
/// </summary>
|
public override void RemoveFromParent()
|
{
|
ButtonClickEvent = null;
|
ButtonDownClickEvent = null;
|
|
if (this.Parent != null)
|
{
|
base.RemoveFromParent();
|
}
|
}
|
|
/// <summary>
|
/// 根据文本,计算它实际的宽度
|
/// </summary>
|
/// <returns></returns>
|
public int GetRealWidthByText()
|
{
|
if (string.IsNullOrEmpty(this.Text) == true) { return Application.GetRealWidth(4); }
|
|
return base.GetTextWidth();
|
}
|
|
/// <summary>
|
/// 计算图片的真实高宽度
|
/// </summary>
|
/// <param name="i_size"></param>
|
/// <returns></returns>
|
public int GetPictrueRealSize(int i_size)
|
{
|
return Application.GetRealWidth(i_size);
|
}
|
|
/// <summary>
|
/// 根据文本,计算它需要的总行数
|
/// </summary>
|
/// <param name="i_width">当值为-1时,需要父控件,真实值</param>
|
/// <returns></returns>
|
public int GetRealRowCountByText(int i_width = -1)
|
{
|
if (i_width == -1)
|
{
|
i_width = this.Width;
|
}
|
//先获取它的真实宽度
|
int realWidth = this.GetRealWidthByText();
|
int row = realWidth / i_width;
|
if (realWidth % i_width > 0)
|
{
|
row++;
|
}
|
return row;
|
}
|
|
#endregion
|
}
|
}
|