From c7df85937f73fb347ee0b19e9c052d2d00a6df6c Mon Sep 17 00:00:00 2001 From: 黄学彪 <hxb@hdlchina.com.cn> Date: 星期五, 18 九月 2020 13:58:19 +0800 Subject: [PATCH] 新版本 --- ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Controls/BaseCommonControl/Base/ButtonBase.cs | 228 ++++++++++++++++++++++++++++++--------------------------- 1 files changed, 120 insertions(+), 108 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Controls/BaseCommonControl/Base/ButtonBase.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Controls/BaseCommonControl/Base/ButtonBase.cs index 42798c2..1cad842 100755 --- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Controls/BaseCommonControl/Base/ButtonBase.cs +++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Controls/BaseCommonControl/Base/ButtonBase.cs @@ -17,12 +17,14 @@ private bool m_CanClick = true; /// <summary> /// 璁剧疆鑳藉惁瑙︾偣鍑讳簨浠� - /// </summary> + /// </summary> public bool CanClick { get { return m_CanClick; } set { + if (m_CanClick == value) { return; } + m_CanClick = value; //鑳藉鐐瑰嚮,鍒欐樉绀烘病鏈夌偣鍑昏繃鐨勭姸鎬� if (m_CanClick == true) { this.SetNotClickStatu(); } @@ -30,24 +32,52 @@ else { this.SetClickStatu(); } } } + /// <summary> + /// 鍦嗚搴� + /// </summary> + public int RadiusEx + { + set { this.Radius = (uint)Application.GetRealHeight(value); } + } + /// <summary> + /// 澹版槑姝ゅ彉閲�,鏃ㄥ湪瀛愮嚎绋嬩篃鑳藉鍘昏幏鍙栦竴涓帶浠剁殑涓婚敭 + /// </summary> + public string MainKey = string.Empty; /// <summary> - /// 鏄惁鏄暱鎸夌姸鎬� + /// 鐐瑰嚮鐨勫潗鏍� /// </summary> - private bool isLongClick = false; + private System.Drawing.Point downPoint = new System.Drawing.Point(); /// <summary> /// 鎺т欢鐨勭偣鍑讳簨浠�(鑷畾涔夊皝瑁呬簨浠�,姝や簨浠惰璁ゅ彲涓烘墽琛屾寜閽寜涓嬩簨浠�,鍙桟anClick灞炴�ф帶鍒�) /// </summary> public Action<Button, MouseEventArgs> ButtonClickEvent = null; /// <summary> - /// (鈽呭綋鍓嶄笉瑕佷娇鐢ㄢ槄)鎺т欢鐨勯暱鎸変簨浠�,褰撲簨浠朵负null鏃�,浠h〃闀挎寜缁撴潫(鑷畾涔夊皝瑁呬簨浠�,姝や簨浠惰璁ゅ彲涓烘墽琛屾寜閽暱鎸変簨浠�,鍙桟anClick灞炴�ф帶鍒�) - /// </summary> - public Action<Button, MouseEventArgs> ButtonLongClickEvent = null; - /// <summary> /// 鎺т欢鐨勬寜涓嬩簨浠�(鑷畾涔夊皝瑁呬簨浠�,姝や簨浠惰璁ゅ彲涓烘墽琛屾寜閽寜涓嬩簨浠�,鍙桟anClick灞炴�ф帶鍒�) /// </summary> public Action<Button, MouseEventArgs> ButtonDownClickEvent = null; + /// <summary> + /// 鎺т欢瑙﹀彂绉诲姩鐨勪簨浠�(鑷韩鎷ユ湁绠楁硶,褰撶Щ鍔ㄥ灏戝儚绱犲悗,瑙﹀彂浜嬩欢,娉ㄦ剰,璇ヤ簨浠跺彲鑳戒細棰戠箒鐨勮Е鍙�) + /// </summary> + public Action ButtonHappenMoveEvent = null; + + #endregion + + #region 鈻� 閲嶅啓褰摜鐨勫睘鎬____________________ + + /// <summary> + /// 閲嶅啓Text灞炴�� + /// </summary> + public new string Text + { + //鍏堣繖涔堝紕鍏堝惂 + get { return base.Text == null ? string.Empty : base.Text; } + set + { + base.Text = value == null ? string.Empty : value; + } + } #endregion @@ -68,15 +98,15 @@ this.MouseUpEventHandler += ButtonBase_MouseUpEventHandler; //鎸変笅浜嬩欢 this.MouseDownEventHandler += ButtonBase_MouseDownEventHandler; - //闀挎寜浜嬩欢 - this.MouseLongEventHandler += ButtonBase_MouseLongEventHandler; + //绉诲姩浜嬩欢 + 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) { @@ -84,42 +114,60 @@ { 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; } @@ -139,22 +187,15 @@ this.MouseUpEventHandler -= ButtonBase_MouseUpEventHandler; return; } - if (CanClick == true) + //2020.05.14杩藉姞IsFormAdding:鐣岄潰杩樺湪鍔犺浇涓�,涓嶈兘鍐嶇偣鍑� + if (CanClick == true && ControlCommonResourse.IsFormAdding == false) { //Log鍑哄姏 this.WriteLog(0); try { - if (this.isLongClick == false) - { - this.ButtonClickEvent(this, e); - } - else if (ButtonLongClickEvent != null) - { - //闀挎寜缁撴潫 - this.ButtonLongClickEvent(this, null); - } + this.ButtonClickEvent(this, e); } catch (Exception ex) { @@ -165,8 +206,6 @@ HdlLogLogic.Current.WriteLog(ex); } } - //鐘舵�佽繕鍘� - this.isLongClick = false; } #endregion @@ -180,8 +219,9 @@ /// <param name="e"></param> private void ButtonBase_MouseDownEventHandler(object sender, MouseEventArgs e) { - //杩樺師鐘舵�� - this.isLongClick = false; + //璁板綍璧峰綋鍓嶇偣鍑荤殑鍧愭爣 + downPoint.X = (int)e.X; + downPoint.Y = (int)e.Y; if (CanClick == false || this.ButtonDownClickEvent == null) { @@ -205,40 +245,33 @@ #endregion - #region 鈻� 闀挎寜浜嬩欢___________________________ + #region 鈻� 绉诲姩浜嬩欢___________________________ /// <summary> - /// 闀挎寜浜嬩欢 + /// 绉诲姩浜嬩欢 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> - private void ButtonBase_MouseLongEventHandler(object sender, MouseEventArgs e) + private void ButtonBase_MouseMoveEventHandler(object sender, MouseEventArgs e) { - //闀挎寜鐘舵�� - this.isLongClick = true; - - if (ButtonLongClickEvent == null) + if (this.ButtonHappenMoveEvent == null) { - this.MouseLongEventHandler -= ButtonBase_MouseLongEventHandler; + this.MouseMoveEventHandler -= ButtonBase_MouseMoveEventHandler; return; } - if (CanClick == true) + int value = (int)e.X - this.downPoint.X; + if (value >= 30 || value <= -30) { - //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); - } + //瑙﹀彂绉诲姩浜嬩欢 + this.ButtonHappenMoveEvent(); + return; + } + value = (int)e.Y - this.downPoint.Y; + if (value >= 30 || value <= -30) + { + //瑙﹀彂绉诲姩浜嬩欢 + this.ButtonHappenMoveEvent(); + return; } } @@ -271,59 +304,38 @@ { ButtonClickEvent = null; ButtonDownClickEvent = null; - ButtonLongClickEvent = null; - base.RemoveFromParent(); - } - - /// <summary> - /// Y杞撮噸缃�(鐪熷疄鏁板��,娌℃湁鐖跺鍣ㄦ棤鏁�) - /// </summary> - /// <param name="alignment">涓婁笅瀵归綈鏂瑰紡</param> - /// <param name="Space">涓婁笅涓ら儴鍒嗙殑闂磋窛</param> - public void ReSetYaxis(UViewAlignment alignment, int Space = 0) - { - if (this.Parent == null) + if (this.Parent != null) { - return; + base.RemoveFromParent(); } - //Y杞撮噸缃� - this.Y = UserCenterLogic.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; - } + 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 + } - 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); + /// <summary> + /// 璁$畻鍥剧墖鐨勭湡瀹為珮瀹藉害 + /// </summary> + /// <param name="i_size"></param> + /// <returns></returns> + public int GetPictrueRealSize(int i_size) + { + return HdlControlLogic.Current.GetPictrueRealSize(i_size); } #endregion @@ -333,7 +345,7 @@ /// <summary> /// 璇ユ帶浠舵墍灞炵殑鐣岄潰鍚嶅瓧 /// </summary> - private string formName = null; + public string formName = null; /// <summary> /// 鎺т欢鍚嶅瓧 /// </summary> -- Gitblit v1.8.0