-1

我有路径。listbox我想在listbox项目单击时打开文件。

我正在使用SelectedIndexChanged,从中我可以知道被点击的项目。现在,我想打开它。

4

1 回答 1

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
        }
    }
}
于 2013-09-19T12:11:33.750 回答