-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileDialogButton.cs
44 lines (40 loc) · 1.5 KB
/
FileDialogButton.cs
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
// This is an independent project of an individual developer. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++, C#, and Java: http://www.viva64.com
using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
namespace RunAsRenamer
{
public sealed class FileDialogButton : Button
{
private readonly TextBox linkedTextBox;
private readonly OpenFileDialog openFileDialog = new OpenFileDialog(){
Multiselect = false,
Filter = @"icon | *.ico",
InitialDirectory = Directory.GetCurrentDirectory(),
Title = @"Selecting icon"
};
public FileDialogButton(ref TextBox button)
{
linkedTextBox = button;
Text = @"...";
TextAlign = ContentAlignment.MiddleCenter;
linkedTextBox.TextChanged += (sender, args) =>
openFileDialog.InitialDirectory = Directory.Exists(linkedTextBox.Text)
? linkedTextBox.Text
: Directory.GetCurrentDirectory();
}
protected override void OnClick(EventArgs e)
{
base.OnClick(e);
openFileDialog.InitialDirectory = Directory.Exists(linkedTextBox.Text)
? linkedTextBox.Text
: Directory.GetCurrentDirectory();
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
linkedTextBox.Text = openFileDialog.FileName;
}
}
}
}