程序说明:(1)当点击“选择图片”时,每添加一张图片就在picturebox中显示出上一次添加的图片,并在ListBox中显示所添加图片的路径
(2)放映速度默认为慢速3秒,当点击幻灯片放映图片时根据放映速度放映图片,且选定放映图片后“下一张”不可用
程序问题:(1)InvalidArgument=“1”的值对于“index”无效。(当添加图片时每次到第二张显示这个)
(2)如果成功无措的话,那么放映图片过程中是无法中断的,那么问题在于在不使用线程的情况下,如何让可中断放映呢?
(3)图片无法设置大小超过(256,256)『非拉伸图片,否则图片严重不清晰』,否则报错,是因为picturebox中显示的图片无法超过256呢,还是什么其他原因,请各位大神请教
程序代码:public Windows窗体的图片切换效果()
{
InitializeComponent();
}
ImageList IL;
public int i = 0;
private void Add_Pt_Click(object sender, EventArgs e) //添加图片
{
IL= new ImageList();
openFileDialog1.Filter = "(*.jpg)|*.jpg";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string Add_Pt = openFileDialog1.FileName;
listBox1.Items.Add(openFileDialog1.FileName);
Image I_Add = Image.FromFile(Add_Pt, true);
IL.Images.Add(I_Add);
IL.ImageSize = new Size(256,256);
pictureBox1.Image=IL.Images;
i++;
}
}
private void Windows窗体的图片切换效果_Load(object sender, EventArgs e)//程序加载事件
{
Select_Show_V.Items.Add("快(1秒)");
Select_Show_V.Items.Add("中(3秒)");
Select_Show_V.Items.Add("慢(5秒)");
Select_Show_V.Items.Add("特慢(7秒)");
Select_Show_V.Items.Add("非常慢(10秒)");
Select_Show_V.SelectedIndex = 0;
}
private void Show_Pt_Click(object sender, EventArgs e)//幻灯片放映图片
{
Next_Pt.Enabled = false;
int times=3;
switch (Select_Show_V.SelectedIndex)
{
case 0: times = 1; break;
case 1: times = 3; break;
case 2: times = 5; break;
case 3: times = 7; break;
case 4: times = 10; break;
default: break;
}
if (IL.Images.Count != 0)
{
int i = 0;
while (true)
{
Thread.Sleep(times * 1000);
pictureBox1.Image = IL.Images;
if (i == IL.Images.Count)
{
break;
}
i++;
}
}
else
{
MessageBox.Show("请先导入图片(添加图片)","提示");
}
}
private void Stop_Show_Click(object sender, EventArgs e)//停止放映图片
{
Next_Pt.Enabled = true;
pictureBox1.Image = IL.Images[0];
}
}
|