yangyin
2025-02-28 baa80d650adebcce70f1113cc1020c6039c159a0
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 System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace DPumpHydr.WinFrmUI.WenSkin.Controls
{
    public class WenDialogLableTextBox : WenLableTextBox
    {
        public WenDialogLableTextBox()
        {
            Image = Properties.Resources.选择;
 
            this.ButtonClick += WenChoiceLableTextBox_ButtonClick;
        }
 
        private void WenChoiceLableTextBox_ButtonClick(object sender, WenLableTextBoxButtonEventArgs e)
        {
            e.ShowTextBox = false;
 
            if (Dialog == DialogStyle.File)
            {
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.Filter = this.Filter;
                var dia = ofd.ShowDialog();
                if(dia != DialogResult.OK)
                {
                    return;
                }
                this.Text = ofd.FileName;
            }
            else
            {
                FolderBrowserDialog fol = new FolderBrowserDialog();
                var dia = fol.ShowDialog();
                if(dia != DialogResult.OK)
                {
                    return;
                }
                this.Text = fol.SelectedPath;
            }
 
        }
 
        #region 公有属性
        [Category("Wen"), Description("选择类型"), DefaultValue(false)]
        public DialogStyle Dialog { get; set; } = DialogStyle.File;
 
 
        [Category("Wen"), Description("选择类型"), DefaultValue(false)]
        public string Filter { get; set; } = "所有文件(*.*)|*.*";
        #endregion
 
 
        public enum DialogStyle
        {
            Folder,
            File
        }
    }
}