本文实例讲述了WinForm中实现picturebox自适应图片大小的方法。分享给大家供大家参考,具体如下:
picturebox控件共有两种载入图片方式,分别为:
pictureBox1.BackgroundImage = Image,pictureBox1.load(url)
为使加载的图片自使用控件尺寸,可以分别对pictureBox控件设置BackGroundImageLayout=Stretch,SizeMode=StretchImagewinform中picturebox自适应图片大小
做了一个示例,代码如下,后面附完整项目源码下载:
using System;
using System.Windows.Forms;
namespace HoverTreePictureBox
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
WindowState = FormWindowState.Maximized;
}
private void button_getPicture_Click(object sender, EventArgs e)
{
pictureBox_HoverTree.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox_HoverTree.BackgroundImageLayout = ImageLayout.Stretch;<