C# PictureBox设置背景图片及加载图片源码
C# PictureBox设置背景图片及加载图片源码
PictureBox.Image属性:加载图片,支持图片缩放对应SizeMode属性。
PictureBox.BackgroundImage属性:设置背景图片,支持背景平铺对应BackgroundImageLayout属性。
C# Code:
public partial class Form4 : Form
{
public Form4()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{//加载图片
this.pictureBox1.Image = Image.FromFile(textBox2.Text);
}
private void button2_Click(object sender, EventArgs e)
{//设置背景
this.pictureBox1.BackgroundImage = Image.FromFile(textBox1.Text);
}
private void Form4_Load(object sender, EventArgs e)
{
cbBackground.Text = "Tile";
cbImageZoom.Text = "Zoom";
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
ImageLayout mode = (ImageLayout)Enum.Parse(typeof(ImageLayout), cbBackground.Text);
pictureBox1.BackgroundImageLayout = mode;
pictureBox1.Invalidate();
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
PictureBoxSizeMode mode = (PictureBoxSizeMode)Enum.Parse(typeof(PictureBoxSizeMode), cbImageZoom.Text);
pictureBox1.SizeMode = mode;
pictureBox1.Invalidate();
}
}
//来源:C/S框架网(www.csframework.com) QQ:23404761
public partial class Form4 : Form
{
public Form4()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{//加载图片
this.pictureBox1.Image = Image.FromFile(textBox2.Text);
}
private void button2_Click(object sender, EventArgs e)
{//设置背景
this.pictureBox1.BackgroundImage = Image.FromFile(textBox1.Text);
}
private void Form4_Load(object sender, EventArgs e)
{
cbBackground.Text = "Tile";
cbImageZoom.Text = "Zoom";
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
ImageLayout mode = (ImageLayout)Enum.Parse(typeof(ImageLayout), cbBackground.Text);
pictureBox1.BackgroundImageLayout = mode;
pictureBox1.Invalidate();
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
PictureBoxSizeMode mode = (PictureBoxSizeMode)Enum.Parse(typeof(PictureBoxSizeMode), cbImageZoom.Text);
pictureBox1.SizeMode = mode;
pictureBox1.Invalidate();
}
}
//来源:C/S框架网(www.csframework.com) QQ:23404761
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网