国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
Winform --- PictureBox控件 實例

Winform --- PictureBox控件 實例

Winform 2010-07-28 12:36:52 閱讀54 評論0   字號: 訂閱

1、PictureBox 常用屬性

         Location : 控件左上角相對容器左上角的坐標;

         ImageLocagion : 加載圖片的磁盤或者Web的位置; 

 

2、PictureBox  實例實現(xiàn)的功能:顯示4張圖像,其中兩張圖片是靜態(tài)的,兩張是不停的變化,鼠標雙擊圖像時,圖像會變大或者縮小。

 
 
 
 
3、具體代碼實現(xiàn):
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplicationIntegratedDemo
{
    public partial class Form1 : Form
    {
        private string _directoryInfoPath = string.Empty;//文件夾相對路徑
        public string DirectoryInfoPath
        {
            set { _directoryInfoPath = value; }
            get { return _directoryInfoPath; }
        }

        private int _imageCount = 0;//文件數(shù)
        public int ImageCount
        {
            set { _imageCount = value; }
            get { return _imageCount; }
        }
 
        private int _imageIndex = 1;//當前圖片的索引值
        public int ImageIndex
        {
            set { _imageIndex = value; }
            get {return _imageIndex;}
        }
 
        private bool _signExtend = false;//圖片是否放大標示
        public bool SignExtend
        {
            set { _signExtend = value; }
            get { return _signExtend; }
        }
 
        public Form1()
        {
            InitializeComponent();
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            this.DirectoryInfoPath = @"../Images";
            DirectoryInfo directoryInfo = new DirectoryInfo(this.DirectoryInfoPath);//創(chuàng)建文件夾對象
            if (directoryInfo.Exists)
            {
                FileInfo[] fileInfos = directoryInfo.GetFiles("*.png");//查詢出后綴名為.png的所有文件
                if(fileInfos!=null)
                    this.ImageCount = fileInfos.Count();
            }
            this.timer1.Start();//打開計數(shù)器
            //this.pictureBox3.Image = this.imageList1.Images[0];//ImageList控件將大圖像的像素改變了
            this.pictureBox3.SizeMode = PictureBoxSizeMode.StretchImage;//設(shè)置圖片大小
            this.pictureBox4.SizeMode = PictureBoxSizeMode.StretchImage;//設(shè)置圖片大小
        }
 
        //計時器事件
        private void timer1_Tick(object sender, EventArgs e)
        {          
            this.pictureBox3.ImageLocation = GetImagePath(this.DirectoryInfoPath,this.ImageIndex);//加載的圖片的路徑
            this.pictureBox4.ImageLocation = GetImagePath(this.DirectoryInfoPath, this.ImageCount + 1 - this.ImageIndex);//加載的圖片的路徑
            this._imageIndex++;
            this.ImageIndex = this._imageIndex;
            if (this.ImageIndex == (this.ImageCount + 1))//從新開始顯示圖片
            {
                this._imageIndex = 1;
                this.ImageIndex = 1;
            }             
        }
 
        /// <summary>
        /// 圖片的相對路徑
        /// </summary>
        /// <param name="pathPrefix">路徑前綴(文件夾路徑)</param>
        /// <param name="index">圖片索引值</param>
        /// <returns></returns>
        private string GetImagePath(string pathPrefix,int index)
        {
            string strIndex = string.Format("/aaa{0:000}.png", index);//將整數(shù)格式化為“/aaa000.png”樣式
            string imagePath = pathPrefix + strIndex;
            return imagePath;
        }

        //PictureBox 雙擊事件
        private void pictureBox_DoubleClick(object sender, EventArgs e)
        {
            PictureBox pictureBox = sender as PictureBox;
            if (pictureBox != null)
            {
                if (!this.SignExtend)
                {
                    pictureBox.Width = 220;
                    pictureBox.Height = 190;
                    pictureBox.Location = new Point(pictureBox.Location.X + 5, pictureBox.Location.Y + 5);//左上角的位置
                    this.SignExtend = true;//放大縮小標示
                }
                else
                {
                    pictureBox.Width = 110;
                    pictureBox.Height = 90;
                    pictureBox.Location = new Point(pictureBox.Location.X - 5, pictureBox.Location.Y - 5);//左上角的位置
                    this.SignExtend = false;//放大縮小標示
                }
            }
        }
    }
}
 
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
vb.net入門——ImageList 組件的使用
C#2010 在TreeView控件下顯示路徑下所有文件和文件夾
信息技術(shù)教研活動記錄
為ComboBox控件添加圖片
Winform開發(fā)框架之權(quán)限管理系統(tǒng)的改進
《C#語言程序設(shè)計項目教程》第10章 文件寫字字帖
更多類似文章 >>
生活服務(wù)
分享 收藏 導長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服