C# PictureBox设置背景图片及加载图片源码
作者:C/S框架网  发布日期:2018-08-12 13:01:40
  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





点击下载附件 点击下载附件 (如下载失败,请邮件通知我们寄回给您,或QQ:23404761留言.)
上一篇 下一篇