【发布时间】:2014-05-08 09:23:40
【问题描述】:
我目前正在尝试为一个项目制作我的 mp3 播放器。
我按照指南编写了这段代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string[] files, path;
[STAThread]
private void button1_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
files = openFileDialog1.SafeFileNames;
path = openFileDialog1.FileNames;
for (int i = 0; i < files.Length; i++)
{
listBox1.Items.Add(files[i]);
}
}
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
axWindowsMediaPlayer1.URL = path[listBox1.SelectedIndex];
}
}
}
这是我的表单屏幕:
由于某种原因,当我单击“打开”按钮时,没有任何反应。首先,当我使用此代码时,我收到一个关于“Form1_load”的错误,但由于我没有使用它,我只是删除了错误行,然后没有发现错误。
我很无知,所以有人知道出了什么问题吗?
我完全遵循了本指南: http://www.c-sharpcorner.com/UploadFile/8ea152/mp3-media-player-in-C-Sharp-4-0/
谢谢
【问题讨论】:
-
为“打开文件”按钮粘贴代码
-
@andy "OPEN FILES" 的 ID 可能为
button1 -
您是否将 Click 事件分配给您的按钮?