黄学彪
2020-12-16 0d9f64668fd7350d6a21fd157e32009a96d98134
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
using System;
using System.Collections.Generic;
using System.Text;
 
namespace Shared.Phone
{
    /// <summary>
    /// FrameLayout的最初原型
    /// </summary>
    public class FrameLayoutBase : FrameLayout
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 设置能否触点击事件
        /// </summary>
        public bool CanClick = true;
        /// <summary>
        /// 声明此变量,旨在子线程也能够去获取一个控件的主键
        /// </summary>
        public string MainKey = string.Empty;
        /// <summary>
        /// 控件的点击事件(自定义封装事件,此事件被认可为执行按钮按下事件,受CanClick属性控制)
        /// </summary>
        public Action<object, MouseEventArgs> ButtonClickEvent = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// FrameLayout的最初原型
        /// </summary>
        public FrameLayoutBase()
        {
            //点击事件
            this.MouseUpEventHandler += ButtonBase_MouseUpEventHandler;
        }
 
        #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;
            }
            //2020.05.14追加IsFormAdding:界面还在加载中,不能再点击
            if (CanClick == true && HdlControlResourse.IsFormAdding == false)
            {
                //Log出力
                this.WriteLog();
 
                try
                {
                    this.ButtonClickEvent(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="i_size"></param>
        /// <returns></returns>
        public int GetPictrueRealSize(int i_size)
        {
            return HdlControlLogic.Current.GetPictrueRealSize(i_size);
        }
 
        /// <summary>
        /// 控件摧毁
        /// </summary>
        public override void RemoveFromParent()
        {
            ButtonClickEvent = null;
 
            if (this.Parent != null)
            {
                base.RemoveFromParent();
            }
        }
 
        /// <summary>
        /// ☆☆移除全部控件☆☆
        /// </summary>
        public override void RemoveAll()
        {
            if (this.Parent != null)
            {
                base.RemoveAll();
            }
        }
 
        #endregion
 
        #region ■ Log出力____________________________
 
        /// <summary>
        /// 该控件所属的界面名字
        /// </summary>
        public string formName = null;
        /// <summary>
        /// Log出力
        /// </summary>
        private void WriteLog()
        {
            if (formName == null)
            {
                formName = string.Empty;
                View myView = this.Parent;
                for (; ; )
                {
                    if (myView == null)
                    {
                        break;
                    }
                    else if (myView is CommonFormBase)
                    {
                        //这个控件所属的界面
                        formName = ((CommonFormBase)myView).FormID;
                        break;
                    }
                    myView = myView.Parent;
                }
            }
            HdlLogLogic.Current.WriteLog(1, formName + "的[Y" + this.Y + "]被点击");
        }
 
        #endregion
 
    }
}