當我在我的計算機中選擇多個文件並打開時,每個文件在我的應用程序中打開一個實例。在配置Windows應用程序運行一個實例,但一個文件與我的應用程序打開。如何打開選定的文件,並在我的應用程序列表框中添加地址文件。如何關聯c中的多個文件#
的Program.cs
static class Program
{
[STAThread]
static void Main(string[] args)
{
if (args != null && args.Length > 0)
{
string fileName = args[0];
if (File.Exists(fileName))
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Form1 MainFrom = new Form1();
MainFrom.OpenFile(fileName);
Application.Run(MainFrom);
}
else
{
MessageBox.Show("The file does not exist!", "BMPlayer Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
else
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
Form.cs
public void OpenFile(string filePath)
{
string file1 = File.ReadAllText(filePath);
axWindowsMediaPlayer1.URL = filePath;
}
這個代碼只對一個文件進行操作。
你嘗試過什麼嗎?你有任何代碼與示例數據分享?我不清楚你想達到什麼目的。 – Pac0
另外,你不應該給你的句子的每個單詞放一個大寫字母。 – Pac0
我知道你不是英語母語的人。讓我試圖強化這個問題,並告訴它是否碰到了問題:在資源管理器中,您要選擇多個文件。現在,如果您按Enter鍵,則希望您的應用程序打開時顯示所選文件的列表,而不是每個選定文件的應用程序的一個實例。您嘗試配置您的應用程序時,一次只能打開一個實例,導致只有一個實例包含選擇中的一個文件。那是對的嗎? – Fildor