欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

WinForm中實(shí)現(xiàn)picturebox自適應(yīng)圖片大小的方法

 更新時(shí)間:2017年05月17日 08:55:37   作者:何問起  
這篇文章主要介紹了WinForm中實(shí)現(xiàn)picturebox自適應(yīng)圖片大小的方法,涉及pictureBox控件相關(guān)屬性設(shè)置技巧,需要的朋友可以參考下

本文實(shí)例講述了WinForm中實(shí)現(xiàn)picturebox自適應(yīng)圖片大小的方法。分享給大家供大家參考,具體如下:

picturebox控件共有兩種載入圖片方式,分別為:

pictureBox1.BackgroundImage = ImagepictureBox1.load(url)

為使加載的圖片自使用控件尺寸,可以分別對(duì)pictureBox控件設(shè)置BackGroundImageLayout=Stretch,SizeMode=StretchImagewinform中picturebox自適應(yīng)圖片大小

做了一個(gè)示例,代碼如下,后面附完整項(xiàng)目源碼下載:

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;
      try
      {
        pictureBox_HoverTree.Load("http://hovertree.com/hvtimg/bjafjc/rgevo2ea.jpg");
      }
      catch (Exception ex){ MessageBox.Show("何問起",ex.Message); }
    }
    private void button_hovertreeZoom_Click(object sender, EventArgs e)
    {
      //圖像大小按其原有的大小比例被增加或減少 by 何問起
      pictureBox_HoverTree.SizeMode = PictureBoxSizeMode.Zoom;
    }
    private void button_HovertreeStretch_Click(object sender, EventArgs e)
    {
      //PictureBox 中的圖像被拉伸或收縮,以適應(yīng)PictureBox的大小。 by 何問起
      pictureBox_HoverTree.SizeMode = PictureBoxSizeMode.StretchImage;
    }
    private void s_Click(object sender, EventArgs e)
    {
      //調(diào)整PictureBox的大小,使其等于所包含圖像的大小 by 何問起
      pictureBox_HoverTree.SizeMode = PictureBoxSizeMode.AutoSize;
    }
  }
}

附:完整實(shí)例代碼點(diǎn)擊此處本站下載。

更多關(guān)于C#相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《WinForm控件用法總結(jié)》、《C#窗體操作技巧匯總》、《C#數(shù)據(jù)結(jié)構(gòu)與算法教程》、《C#常見控件用法教程》、《C#面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》及《C#程序設(shè)計(jì)之線程使用技巧總結(jié)

希望本文所述對(duì)大家C#程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論