random-file-runner/RyzStudio/Windows/ThemedForms/TextBox/TFolderTextBox.cs

63 lines
2.0 KiB
C#
Raw Normal View History

2021-10-24 15:49:48 +00:00
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using UIResources = RandomFileRunner.UIResource;
namespace RyzStudio.Windows.ThemedForms
{
public class TFolderTextBox : TButtonTextBox
{
public TFolderTextBox() : base()
{
this.NormalImage = UIResources.folder;
this.HighlightImage = UIResources.folder2;
this.Text = string.Empty;
}
public FolderBrowserDialog FolderDialog { get; set; } = null;
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public new Image NormalImage { get => base.NormalImage; set => base.NormalImage = value; }
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public new Image HighlightImage { get => base.HighlightImage; set => base.HighlightImage = value; }
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public new Forms.TImageBox InnerImageBox { get => base.InnerImageBox; set => base.InnerImageBox = value; }
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public new TextBox InnerTextBox { get => base.InnerTextBox; set => base.InnerTextBox = value; }
protected override void imageBox1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left)
{
return;
}
if (this.FolderDialog == null)
{
this.FolderDialog = new FolderBrowserDialog();
this.FolderDialog.Description = "Choose a directory";
}
if (!string.IsNullOrWhiteSpace(this.Text))
{
if (Directory.Exists(this.Text))
{
this.FolderDialog.SelectedPath = this.Text;
}
}
if (this.FolderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.Text = this.FolderDialog.SelectedPath;
}
}
}
}