我在listbox
中有路径。我想在listbox
项目点击打开文件。
我正在使用SelectedIndexChanged
,从中我能够知道被点击的项目。现在,我想打开它。
答案 0 :(得分:2)
public void OpenDialogBox()
{
Stream myStream = null;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "*YOURTEXTBOX.text";
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
if ((myStream = openFileDialog1.OpenFile()) != null)
{
//Do something with Open File
}
}
catch (Exception ex)
{
// You messed up
}
}
}