请大家帮忙看看
namespace 图片控件使用{
public partial class Form1 : Form
{
图片控件使用.rar
(165.02 KB)
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
int i;
for (i = 1; i <=4; i++)
{
this.listBox1.Items.Add("风景为:" + i.ToString());
}
this.listBox1.SelectedIndex = 0;
}
private void button1_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button2_Click(object sender, EventArgs e)
{
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
//this.pictureBox1.Image = Image.FromFile("C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\示例图片\\Blue hills.jpg");
string m;
m = Application.StartupPath + @"\pic\Blue hills.jpg";
Bitmap p = new Bitmap(m);
this.pictureBox1.Image = p;
}
private void button3_Click(object sender, EventArgs e)
{
timer1.Stop();
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string m;
m = Application.StartupPath + picfile(this.listBox1.Text);
Bitmap p = new Bitmap(m);
this.pictureBox1.Image = p;
}
string picfile(string x)
{
if (x == "风景为:1")
return @"\pic\64.jpg";
// return "C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\示例图片\\Blue hills.jpg";
else if (x == "风景为:2")
return @"\pic\$NO[B{LLT{%OT(ED_$R7F]6.jpg";
else if (x == "风景为:3")
return @"\pic\`YD1`5$FR_ASGORBG95IYXP.gif";
else if (x == "风景为:4")
return @"\pic\6AO6LK~YG87KUZ%KXFQ%G@8.jpg";
else
return @"\pic\64.jpg";
}
}
}
上面的代码中:
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string m;
m = Application.StartupPath + picfile(this.listBox1.Text);
Bitmap p = new Bitmap(m);
this.pictureBox1.Image = p;
}中的Bitmap p = new Bitmap(m);出了问题
请问为什么错了?
我做这段代码的目的是:想在ListBox1中点击风景之后在pictureBox1中显示相应的图片。