c# 从零到精通 form界面之imageList控件操作
using System;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Test02
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
pictureBox1.Width = 200;
pictureBox1.Height = 165;
string Path = Application.StartupPath.Substring(0, Application.StartupPath.Substring(0, Application.StartupPath.LastIndexOf(“\”)).LastIndexOf(“\”));
Path += @“\01.jpg”;
Image img = Image.FromFile(Path, true);
imageList1.Images.Add(img);
imageList1.ImageSize = new Size(200,165);
}
private void button1_Click(object sender, EventArgs e)
{
if (imageList1.Images.Count == 0)
{
MessageBox.Show(“没有图像”);
}
else
{
pictureBox1.Image = imageList1.Images[0];
}
}
private void button2_Click(object sender, EventArgs e)
{
imageList1.Images.RemoveAt(0);
pictureBox1.Image = null;
}
}
}
c# c# 从零到精通 form界面之imageList控件操作
最新推荐文章于 2024-06-01 20:21:34 发布
该文章介绍了如何在C#的WindowsForms应用中使用imageList控件。首先设置pictureBox的尺寸,然后读取图片文件并添加到imageList中,调整图片大小,最后在button点击事件中展示或移除imageList中的图像。
摘要由CSDN通过智能技术生成