video-preview/RyzStudio/Windows/ThemedForms/TextBox/TOpenFileTextBox.cs
2021-10-03 18:43:59 +01:00

49 lines
1.3 KiB
C#

using System;
using System.IO;
using System.Windows.Forms;
using UIResources = VideoPreview.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;
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;
}
}
}
}