使用 Visual Studio 2008
我有一个用户控件。该按钮调用文件夹浏览器对话框。我正在尝试将路径传递给父表单,但它没有到达那里。我需要一点输入......
用户控制:
public partial class FolderSelectDDL : UserControl
{
public delegate void ButtonClickedEventHandler(object sender, EventArgs e);
public static event ButtonClickedEventHandler OnUserControlButtonClicked;
private string folderPath;
public string FolderPath
{
get { return folderPath; }
set { folderPath = value; }
}
public FolderSelectDDL()
{
InitializeComponent();
}
private void btnSaveToPath_Click(object sender, EventArgs e)
{
string path;
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
path = folderBrowserDialog1.SelectedPath;
if (OnUserControlButtonClicked != null)
OnUserControlButtonClicked(this, e);
folderPath = path;
}
}
}
和形式:
public partial class ImportCreateExcel : Form
{
FolderSelectDDL uc = new FolderSelectDDL();
public ImportCreateExcel()
{
FolderSelectDDL.OnUserControlButtonClicked += new FolderSelectDDL.ButtonClickedEventHandler(btnSaveToPath_Click);
InitializeComponent();
}
private void btnSaveToPath_Click(object sender, EventArgs e)
{
MessageBox.Show(uc.FolderPath); //blank
//MessageBox.Show(uc.folderBrowserDialog1.SelectedPath); //blank
}
}
路径始终为空白,无论是来自设置为公共的对话框还是变量 FolderPath。
任何意见总是受欢迎的。
谢谢!