Shuxia Ning
2024-07-17 fd681339c81201ed6fb3303647ecab89e3e6c0c1
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
using DevExpress.XtraEditors;
 
namespace IStation.Win
{
    public static class ButtonEditExtend
    {
 
        /// <summary>
        /// 设置查询
        /// </summary>
        /// <param name="btn"></param>
        /// <param name="SearchData"></param>
        /// <param name="RecoverData"></param>
        public static void SetSearchSettings(this ButtonEdit btn, EventHandler SearchData, EventHandler RecoverData)
        {
            btn.Properties.Buttons.Clear();
            btn.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
            new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Clear),
            new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Search)});
            btn.Properties.Buttons[0].Visible = false;
            btn.EditValueChanged += delegate
            {
                if (btn.EditValue == null || string.IsNullOrEmpty(btn.EditValue.ToString()))
                {
                    btn.Properties.Buttons[0].Visible = false;
                    if (RecoverData != null)
                        RecoverData(null, null);
                }
                else
                    btn.Properties.Buttons[0].Visible = true;
 
            };
            btn.ButtonClick += (sender, e) =>
                {
                    if (e.Button == btn.Properties.Buttons[0])
                    {
                        btn.EditValue = null;
                        if (RecoverData != null)
                            RecoverData(sender, e);
                    }
                    else if (SearchData != null)
                    {
                        if (RecoverData != null)
                            RecoverData(sender, e);
                        SearchData(sender, e);
                    }
                };
            btn.KeyPress += (sender, e) =>
                {
                    if (e.KeyChar == 13)
                    {
                        if (RecoverData != null)
                            RecoverData(sender, e);
                        if (SearchData != null)
                            SearchData(sender, e);
                    }
                };
 
 
        }
 
 
    }
}