今天开始编写button浏览中的代码,
private void button1_Click(object sender, EventArgs e)
{
if(this.openFileDialog1.ShowDialog()==DialogResult.OK)
{
this.listView1 .Items .Clear();
string[] FileNames = this.openFileDialog1.FileNames;
foreach (string FileName in FileNames )
{
FileInfo MyFileInfo = new FileInfo(FileName);
float MyFileSize = (float)MyFileInfo.Length / (1024 * 1024);//取得文件大小
this.axWindowsMediaPlayer1.FileName= FileName;
string MyAuthor = this.axWindowsMediaPlayer1.GetMediaInfoString(MediaPlayer.MPMediaInfoType.mpClipAuthor);//作者信息
string MyShortFileName = FileName.Substring(FileName.LastIndexOf("\") + 1);
MyShortFileName = MyShortFileName.Substring(0, MyShortFileName.Length - 4);//不含路径的文件名
string[] SubItem = { MyShortFileName, MyAuthor, MyFileSize.ToString().Substring(0, 4) + "M", FileName };
ListViewItem Item = new ListViewItem(SubItem);
this.listView1.Items.Add(Item);
this.listView1.Items[0].Selected = true;//填充在list view中
}
}
{
if(this.openFileDialog1.ShowDialog()==DialogResult.OK)
{
this.listView1 .Items .Clear();
string[] FileNames = this.openFileDialog1.FileNames;
foreach (string FileName in FileNames )
{
FileInfo MyFileInfo = new FileInfo(FileName);
float MyFileSize = (float)MyFileInfo.Length / (1024 * 1024);//取得文件大小
this.axWindowsMediaPlayer1.FileName= FileName;
string MyAuthor = this.axWindowsMediaPlayer1.GetMediaInfoString(MediaPlayer.MPMediaInfoType.mpClipAuthor);//作者信息
string MyShortFileName = FileName.Substring(FileName.LastIndexOf("\") + 1);
MyShortFileName = MyShortFileName.Substring(0, MyShortFileName.Length - 4);//不含路径的文件名
string[] SubItem = { MyShortFileName, MyAuthor, MyFileSize.ToString().Substring(0, 4) + "M", FileName };
ListViewItem Item = new ListViewItem(SubItem);
this.listView1.Items.Add(Item);
this.listView1.Items[0].Selected = true;//填充在list view中
}
}
}
代码大致是以上所述,
发现在每一个变量在使用之前都需要声明,相当于告诉系统将要使用这个东西,然后就可以告诉这个变量如何获得,最终将计算后的东西赋值到你想要的位置即可。但是今天的编程发生了一些小问题,播放器的地址与代码有点不能相联系起来,导致button1的功能不能运行,因为时间关系,今天的问题暂不解决,明天将抽出时间来解决这一点,然后进行播放button的编码工作中。
