--pictureBox--支持静态的图像格式
image属性导入一张图片
--imageLocation属性--也可以导入图片
url地址就可
可以改变
使图像填充正确
-----NumericUpDown-----
--ProgressBar---进度条
--value仅显示进度条外观,没有实际意义
---step步进条
---timer---没有外观
--间隔--ms为单位
编写实例:
加载窗体
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_Csharp
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
private void progressBar1_Click(object sender, EventArgs e)
{
}
private void Form3_Load(object sender, EventArgs e)
{
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.ImageLocation = @"D:\9宫格.png";
}
}
}
加载窗口时指定位置的图片
---实现timer控件获取图片加载的时间并设置到进度条上显示
1.timer控件的启动--button
2.添加根据timer时间控件所增加的进度条
3.设置numericUpDown来调节增加进度条的
b必须加控制语句来控制进度条,不然会出现异常
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_Csharp
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
private void progressBar1_Click(object sender, EventArgs e)
{
}
private void Form3_Load(object sender, EventArgs e)
{
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.ImageLocation = @"D:\9宫格.png";
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
var incr = Convert.ToInt32(numericUpDown1.Value);
//progressBar1.Value++;
if (progressBar1.Value + incr <= progressBar1.Maximum)
progressBar1.Value += Convert.ToInt32(numericUpDown1.Value);
else
progressBar1.Value = Convert.ToInt32(progressBar1.Maximum);
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
}
}
}
----切换图像----
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_Csharp
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
private void progressBar1_Click(object sender, EventArgs e)
{
}
private void Form3_Load(object sender, EventArgs e)
{
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.ImageLocation = @"D:\9宫格.png";
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}
int index;//切换索引
private void timer1_Tick(object sender, EventArgs e)
{
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
/* var incr = Convert.ToInt32(numericUpDown1.Value);
//progressBar1.Value++;
if (progressBar1.Value + incr <= progressBar1.Maximum)
progressBar1.Value += Convert.ToInt32(numericUpDown1.Value);
else
progressBar1.Value = Convert.ToInt32(progressBar1.Maximum);
*/ //每隔四秒
index = (index + 1) % 4;
switch (index)
{
case 0:
pictureBox1.ImageLocation = @"D:\9宫格.png";
break;
case 1:
pictureBox1.ImageLocation = @"D:\1.png";
break;
case 2:
pictureBox1.ImageLocation = @"D:\2.png";
break;
case 3:
pictureBox1.ImageLocation = @"D:\3.png";
break;
}
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
}
}
}
---换一个环境 图片加载失败问题,可以用属性图片资源加载图片解决---
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_Csharp
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
private void progressBar1_Click(object sender, EventArgs e)
{
}
private void Form3_Load(object sender, EventArgs e)
{
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.ImageLocation = @"D:\9宫格.png";
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}
int index;//切换索引
private void timer1_Tick(object sender, EventArgs e)
{
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
/* var incr = Convert.ToInt32(numericUpDown1.Value);
//progressBar1.Value++;
if (progressBar1.Value + incr <= progressBar1.Maximum)
progressBar1.Value += Convert.ToInt32(numericUpDown1.Value);
else
progressBar1.Value = Convert.ToInt32(progressBar1.Maximum);
*/ //每隔四秒
index = (index + 1) % 4;
switch (index)
{
case 0:
pictureBox1.Image = Properties.Resources._9宫格;
// pictureBox1.ImageLocation = @"D:\9宫格.png";
break;
case 1:
pictureBox1.Image = Properties.Resources._1;
// pictureBox1.ImageLocation = @"D:\1.png";
break;
case 2:
pictureBox1.Image = Properties.Resources._2;
//pictureBox1.ImageLocation = @"D:\2.png";
break;
case 3:
pictureBox1.Image = Properties.Resources._3;
// pictureBox1.ImageLocation = @"D:\3.png";
break;
}
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
}
}
}