60 lines
1.6 KiB
C#
60 lines
1.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Drawing;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using System.IO;
|
|
|
|
namespace PluginCommon.Controls
|
|
{
|
|
[DefaultEvent("TextChanged")]
|
|
[DefaultBindingProperty("Text")]
|
|
public partial class FileChooser: UserControl
|
|
{
|
|
public string RootDir { get; set; }
|
|
|
|
[Browsable(true)]
|
|
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
|
|
[EditorBrowsable(EditorBrowsableState.Always)]
|
|
public override string Text
|
|
{
|
|
get { return textPath.Text; }
|
|
set { textPath.Text = value; }
|
|
}
|
|
|
|
public FileChooser()
|
|
{
|
|
InitializeComponent();
|
|
RootDir = "";
|
|
}
|
|
|
|
private void btnBrowse_Click(object sender, EventArgs e)
|
|
{
|
|
OpenFileDialog dialog = new OpenFileDialog();
|
|
|
|
dialog.CheckFileExists = true;
|
|
dialog.InitialDirectory = Text != ""
|
|
? Path.GetDirectoryName(Path.Combine(RootDir, textPath.Text))
|
|
: RootDir != ""
|
|
? RootDir
|
|
: "";
|
|
DialogResult result = dialog.ShowDialog();
|
|
|
|
if(result == DialogResult.OK)
|
|
textPath.Text = dialog.FileName;
|
|
}
|
|
|
|
private void textPath_TextChanged(object sender, EventArgs e)
|
|
{
|
|
OnTextChanged(e);
|
|
}
|
|
|
|
private void FileChooser_SizeChanged(object sender, EventArgs e)
|
|
{
|
|
Size = new Size(Size.Width, textPath.Height);
|
|
}
|
|
}
|
|
}
|