我的 WinForms 应用程序的组合框组件中列出了一些 flash 文件。现在,如果选择了文件,我希望它在 webBrowser 组件中播放,这里是代码:
将文件添加到组合框中:
private void Form1_Load(object sender, EventArgs e)
{
string[] filePaths = Directory.GetFiles(@"c:\folder\");
foreach (string s in filePaths)
{
comboBox1.Items.Add(s);
}
}
播放 Flash 文件:
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
this.webBrowser1.Navigate(comboBox1.SelectedText); //it doesnt work
}
我可以正常打开 Flash 文件,看起来我无法从组合框中传递选定的值。
更新
为了确保此事件有效,我将其更改为:
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
this.textBox1.Text = "adsfadsf";
this.textBox2.Text = comboBox1.SelectedText;
}
当我更改所选项目时,字符串 adsfadsf 出现在 textBox1 中,但 textBox2 保持为空。
更新2
这是完整的代码:
using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace App1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
string[] filePaths = Directory.GetFiles(@"c:\folder\");
foreach (string s in filePaths)
{
comboBox1.Items.Add(s);
}
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
this.textBox2.Text = "adsfadsf";
this.textBox1.Text = comboBox1.SelectedText;
// this.webBrowser1.Navigate(comboBox1.SelectedText);
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
}
}