我最近在c#WindowsFormsApplications中開發了一個音樂播放器。如何在音樂播放器中關聯多個文件c#
只有當您選擇程序默認時,一切都會變好,它可以完美地打開一個音樂文件,但是當您選擇5個音樂文件時。 5音樂播放器打開。
如何解決這個問題當你設置它默認打開多個文件就像在C#中的播放列表? 我沒有試過任何東西或任何代碼來做到這一點。 請幫忙!
這是我的Program.cs
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//with args(user open file with the program)
if (args != null && args.Length > 0)
{
string fileName = args[0];
//Check file exists
if (File.Exists(fileName))
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Form1 MainFrom = new Form1();
MainFrom.OpenFile(fileName);
Application.Run(MainFrom);
}
//The file does not exist
else
{
MessageBox.Show("The file does not exist!", "BMPlayer Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
//without args
else
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
,這是Form1.cs中打開文件
public void OpenFile(string filePath)
{
string file1 = File.ReadAllText(filePath);
axWindowsMediaPlayer1.URL = filePath;
}
有點COde不會受傷,你怎麼做你的選擇/負載?你的應用程序中是否有任何類型的標題列表? – MaxW
由於您顯示了0行代碼,我只能假設一直困擾着你。我認爲你應該在應用程序的'Main'方法中處理多重文件名(在'Program.cs'中) – Nino
這段代碼適用於一個文件 – Mohsen