using System;
using System.Drawing;
using System.Windows.Forms;
public class PictureBoxExample : Form
{
private PictureBox pictureBox1;
public PictureBoxExample()
{
// 创建一个 PictureBox 控件
pictureBox1 = new PictureBox
{
// 设置 PictureBox 的大小模式为拉伸图像
SizeMode = PictureBoxSizeMode.StretchImage,
// 设置 PictureBox 的位置和大小
Location = new Point(10, 10),
Size = new Size(200, 200),
// 加载图像
Image = Image.FromFile("example.jpg") // 替换为你的图片路径
};
// 将 PictureBox 添加到窗体中
this.Controls.Add(pictureBox1);
// 设置窗体的属性
this.Text = "PictureBox Example";
this.Size = new Size(300, 300);
}
[STAThread]
public static void Main()
{
Application.EnableVisualStyles();
Application.Run(new PictureBoxExample());
}
}
new PictureBox() 创建一个新的 PictureBox 控件,并设置其属性,如 SizeMode、Location 和 Size。Image.FromFile("example.jpg") 方法从文件加载图像。你需要将 "example.jpg" 替换为你自己的图像路径。this.Controls.Add(pictureBox1) 将 PictureBox 控件添加到窗体中。Main 方法中调用 Application.Run(new PictureBoxExample()) 来启动应用程序。希望这段代码和解释对你有帮助!
上一篇:c#switch
下一篇:c#winform
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站