Shuxia Ning
2025-01-08 687a3dfd095bc8c099b7fa6e65f0dc699fdc8f1d
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
namespace Yw.WinFrmUI
{
    /// <summary>
    /// 
    /// </summary>
    public static class ButtonEditExtentions
    {
 
        /// <summary>
        /// 设置查询
        /// </summary>
        /// <param name="btn">ButtonEdit</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);
                        }
                    }
                };
 
 
        }
 
 
    }
}