if (dialog.ShowDialog() == DialogResult.OK)
return dialog.FileName;
}
return null;
}
public static string? 选择文件夹(string 标题 = "选择文件夹")
{
using (FolderBrowserDialog dialog = new FolderBrowserDialog())
{
dialog.Description = 标题;
dialog.ShowNewFolderButton = true;
if (dialog.ShowDialog() == DialogResult.OK)
return dialog.SelectedPath;
}
return null;
}
public static string? 输入文本(string 提示 = "请输入", string 标题 = "输入",
string 默认值 = "")
{
Form inputForm = new Form
{
Width = 400,
Height = 150,
FormBorderStyle = FormBorderStyle.FixedDialog,
Text = 标题,
StartPosition = FormStartPosition.CenterScreen,
MaximizeBox = false,
MinimizeBox = false
};
Label label = new Label { Left = 20, Top = 20, Text = 提示, Width = 350 };
TextBox textBox = new TextBox
{
Left = 20,
Top = 50,
Width = 350,
Text = 默认值
};
Button buttonOk = new Button
{
Text = "确定",
Left = 200,
Width = 80,
Top = 85,
DialogResult = DialogResult.OK
};
Button buttonCancel = new Button
{
Text = "取消",
Left = 290,
Width = 80,
Top = 85,
DialogResult = DialogResult.Cancel
};
if (dateForm.ShowDialog() == DialogResult.OK)
return picker.Value;
return null;
}
public static (DateTime? 开始日期, DateTime? 结束日期)? 选择日期范围(string 标题 = "选择日期范围")
{
Form rangeForm = new Form
{
Width = 350,
Height = 180,
FormBorderStyle = FormBorderStyle.FixedDialog,
Text = 标题,
StartPosition = FormStartPosition.CenterScreen,
MaximizeBox = false,
MinimizeBox = false
};
Label label1 = new Label { Left = 20, Top = 20, Text = "开始日期:", Width = 70 };
DateTimePicker startPicker = new DateTimePicker
{
Left = 100,
Top = 17,
Width = 200,
Format = DateTimePickerFormat.Short
};
Label label2 = new Label { Left = 20, Top = 60, Text = "结束日期:", Width = 70 };
DateTimePicker endPicker = new DateTimePicker
{
Left = 100,
Top = 57,
Width = 200,
Format = DateTimePickerFormat.Short
};
Button buttonOk = new Button
{
Text = "确定",
Left = 150,
Width = 80,
Top = 110,
DialogResult = DialogResult.OK
};
Button buttonCancel = new Button
{
Text = "取消",
Left = 240,
Width = 80,
Top = 110,
DialogResult = DialogResult.Cancel
};