c# 照片轮播控件
来源:互联网 发布:淘宝秋天卖什么最火 编辑:程序博客网 时间:2024/04/28 13:54
新建一个usercontral
添加图片前要先stop
using System;using System.Collections.Generic;using System.ComponentModel;using System.Drawing;using System.Data;using System.Linq;using System.Text;using System.Windows.Forms;using System.IO;namespace usercontral1{ public partial class UserControl1 : UserControl { public UserControl1() { InitializeComponent(); } public UserControl1(Image[] img) { InitializeComponent(); Add(img); } bool state = false; int pic_weith = 100; int pic_heith = 100; int time_time = 10; int jiange_heith = 2; int jiange_weith = 2; public bool State { get { return state; } set { state = value ;} } public int Pic_weith { get { return pic_weith; } set { pic_weith = value ;} } public int Pic_heith { get { return pic_heith; } set { pic_heith = value ;} } public int Timer_time { get { return time_time ; } set { time_time = value; } } public int Jiange_weith { get { return jiange_weith ; } set { jiange_weith = value; } } public int Jiange_heith { get { return jiange_heith; } set { jiange_heith = value; } } List<Image> img = new List<Image>(); PictureBoxSizeMode mode = PictureBoxSizeMode.Zoom ; int heicount = 1, weicount=1, all=1,nowNo=0,nowheith=0; PictureBox[] pic; public int Add(Image[] img) { for (int i = 0; i < img.Length; i++) { try { this.img.Add(img[i]); } catch { return 0; } } return 1; } public int Clear() { img.Clear(); if (img.Count != 0) { return -1; } else { return 1; } } public int Start() { if (State == true) { return -1; } else { State = true ; imagego(); //轮播代码 return 1; } } public int Stop() { if (State == false ) { return -1; } else { imagestop(); State = false ; return 1; } } public int SetSize(int weith,int heith ,PictureBoxSizeMode mode) { Pic_weith = weith; Pic_heith = heith; return 1; } private void imagego() { timer1.Interval = Timer_time; //确定一共需要初始化多少个pictureBox Size s = this.Size; heicount = s.Height / (Pic_heith + Jiange_heith ); weicount = s.Width / (Pic_weith+Jiange_weith ); all = heicount * weicount + 1; pic = new PictureBox[all]; for (int i = 0; i < pic.Length; i++) { nowNo = i; pic[i] = new PictureBox(); pic[i].Name ="pic_"+i.ToString(); pic[i].SizeMode = mode ; pic[i].Size = new Size(Pic_weith, Pic_heith); pic[i].Image = img[i]; pic[i].Location = new Point ( 0 - (i + 1) *(Pic_weith+Jiange_weith ),0); this.Controls.Add(pic[i]); } timer1.Start(); } private void imagestop() { timer1.Stop(); } private void timer1_Tick(object sender, EventArgs e) { for (int i = 0; i < pic.Length; i++) { pic[i].Location = new Point(pic[i].Location.X + 1, pic[i].Location.Y); if (pic[i].Right > this.Right) { if (pic[i].Top + Pic_heith + Jiange_heith < this.Top + this.Height) { pic[i].Location = new Point(0-Pic_weith ,pic[i].Top + pic[i].Height + Jiange_heith ); nowheith=0; } else { pic[i].Location = new Point(0-Pic_weith ,0); if (nowNo >= img.Count) { nowNo = 0; } pic[i].Image = img[nowNo]; nowheith++; nowNo++; } } } } private void UserControl1_Load(object sender, EventArgs e) { FileInfo[] files = new DirectoryInfo(@"C:\Users\Administrator\Pictures\明星库\debug\2NE1").GetFiles("*.jpg"); for (int i = 0; i < files.Count <FileInfo >(); i++) { img.Add(new Bitmap(files[i].FullName)); } this.Start(); } }}
0 0
- c# 照片轮播控件
- 自定义图片轮播控件
- MUI-图片轮播控件
- Android 图片轮播控件
- 自定义图片轮播控件
- 上下轮播控件TextSwitcher
- LoopView-循环轮播控件
- Android图片轮播控件
- Android轮播控件 BGABanner
- 商品详情轮播控件
- Android图片轮播控件
- ImageView控件图片轮播
- 【web++_第四阶_Ui_照片轮播】
- 【web++_第四阶_Ui_导航、照片轮播_1】
- 常用控件(三) : 图片轮播控件
- Android ViewPager控件实现图片轮播
- UIScrollView控件实现图片轮播
- Android ViewPager控件实现图片轮播
- 绿色单选按钮以及复选框
- with temp as 定义变量
- 安卓多线程编程系列7:使用Looper的不同方式(子线程中实例化Handler方式)
- 小数 二进制 的 表示与转换
- 红包倒计时
- c# 照片轮播控件
- nRF iOS项目(github开源项目)编译运行相关问题解决方案
- 自定义复杂bean注册到spring
- 安装npm
- halcon 视觉寻找两个几何图形
- RecyclerView 控制分割线样式
- 大话设计模式-建造者模式
- 基于Android系统的socket UDP协议通信
- Android数据存储之往SD卡写数据和读数据CODE