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

65 lines
2.1 KiB
C#
Raw Normal View History

2021-10-24 15:49:48 +00:00
using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using UIResources = RandomFileRunner.UIResource;
namespace RyzStudio.Windows.ThemedForms
{
public class TOpenFileTextBox : TButtonTextBox
{
public TOpenFileTextBox() : base()
{
this.NormalImage = UIResources.file;
this.HighlightImage = UIResources.file2;
this.Text = string.Empty;
}
public OpenFileDialog FileDialog { 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.FileDialog == null)
{
this.FileDialog = new OpenFileDialog();
this.FileDialog.Title = "Choose a file";
this.FileDialog.Filter = "All files|*";
}
if (!string.IsNullOrWhiteSpace(this.Text))
{
if (File.Exists(this.Text))
{
this.FileDialog.InitialDirectory = Path.GetDirectoryName(this.Text);
}
}
if (this.FileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.Text = this.FileDialog.FileName;
}
}
}
}