58 lines
1.6 KiB
C#
58 lines
1.6 KiB
C#
using System;
|
|
using System.Windows.Forms;
|
|
|
|
namespace ModVersionChecker.controls
|
|
{
|
|
public class DirectoryPickerControl : UserControl
|
|
{
|
|
private readonly TextBox _textBox;
|
|
private readonly Button _browseButton;
|
|
|
|
public string SelectedPath
|
|
{
|
|
get => _textBox.Text;
|
|
set => _textBox.Text = value;
|
|
}
|
|
|
|
public DirectoryPickerControl()
|
|
{
|
|
_textBox = new TextBox
|
|
{
|
|
Width = 300,
|
|
ReadOnly = true,
|
|
Dock = DockStyle.Fill
|
|
};
|
|
|
|
_browseButton = new Button
|
|
{
|
|
Text = "Browse",
|
|
Width = 80,
|
|
Dock = DockStyle.Right
|
|
};
|
|
|
|
_browseButton.Click += (s, e) =>
|
|
{
|
|
using var folderDialog = new FolderBrowserDialog();
|
|
folderDialog.Description = "Select directory";
|
|
if (folderDialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
SelectedPath = folderDialog.SelectedPath;
|
|
}
|
|
};
|
|
|
|
var panel = new TableLayoutPanel
|
|
{
|
|
ColumnCount = 2,
|
|
Dock = DockStyle.Fill,
|
|
AutoSize = true
|
|
};
|
|
panel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 80));
|
|
panel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 20));
|
|
panel.Controls.Add(_textBox, 0, 0);
|
|
panel.Controls.Add(_browseButton, 1, 0);
|
|
|
|
Controls.Add(panel);
|
|
AutoSize = true;
|
|
}
|
|
}
|
|
} |