热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

图片轮播控件

源码下载:CSharp图

 技术分享图片  技术分享图片

public partial class ImageCarouselDevelopExt : Control
{
#region
///


/// 动画播放定时器
///

private Timer carouselTimer = new Timer();
///
/// 轮播的五个PictureBox
///

private List carouselPictureBox = new List() { new PictureBox() { SizeMode = PictureBoxSizeMode.StretchImage }, new PictureBox() { SizeMode = PictureBoxSizeMode.StretchImage }, new PictureBox() { SizeMode = PictureBoxSizeMode.StretchImage }, new PictureBox() { SizeMode = PictureBoxSizeMode.StretchImage }, new PictureBox() { SizeMode = PictureBoxSizeMode.StretchImage } };
///
/// 轮播的五个PictureBox位置索引
///

private List<int> carouselPictureBoxIndex = new List<int>() { 0, 1, 2, 3, 4 };
///
/// 处理后的图片
///

private List transformImages = new List();
///
/// 图片轮播的时间间隔累计(-1为动画正在切换中)
///

private int intervalTimeValue = 0;
private AnimationTimer _Animation;
#endregion
#region
private bool isReflection = false;
///
/// 是否添加倒影
///

[DefaultValue(false)]
[Description(
"是否添加倒影")]
public bool IsReflection
{
get { return this.isReflection; }
set { this.isReflection = value; }
}
private List carouselImages = new List();
///
/// 要播放的图片
///

[Description("要播放的图片")]
public List CarouselImages
{
get { return this.carouselImages; }
set
{
this.carouselImages = value;
this.Reset();
}
}
private double animatiOnTime= 300;
///
/// 动画播放的总时间
///

[DefaultValue(300)]
[Description(
"动画播放的总时间(默认300毫秒)")]
public double AnimationTime
{
get { return this.animationTime; }
set
{
this.animatiOnTime= value;
this.Reset();
}
}
private int intervalTime = 1000;
///
/// 图片轮播的时间间隔
///

[DefaultValue(1000)]
[Description(
"图片轮播的时间间隔(默认1000毫秒)")]
public int IntervalTime
{
get { return this.intervalTime; }
set
{
this.intervalTime = value;
this.Reset();
}
}
#endregion
public ImageCarouselDevelopExt()
{
InitializeComponent();
this.Controls.Add(carouselPictureBox[0]);
this.Controls.Add(carouselPictureBox[1]);
this.Controls.Add(carouselPictureBox[2]);
this.Controls.Add(carouselPictureBox[3]);
this.Controls.Add(carouselPictureBox[4]);
this.carouselTimer.Interval = 50;
this.carouselTimer.Tick += new EventHandler(carouselTimer_Tick);
this._Animation = new AnimationTimer(this, new AnimationOptions());
this._Animation.AnimationIng += new AnimationTimer.AnimationHandel(Animation_AnimationIng);
this._Animation.AnimationEnding += new AnimationTimer.AnimationHandel(Animation_AnimationEnding);
}
///
/// 定时器
///

///
///
private void carouselTimer_Tick(object sender, EventArgs e)
{
if (this.intervalTimeValue == -1)
return;
this.intervalTimeValue += this.carouselTimer.Interval;
if (this.intervalTimeValue >= this.intervalTime)
{
this.intervalTimeValue = -1;
SizePoint _SizePoint
= new SizePoint();
_SizePoint.isswitch
= false;
_SizePoint._original_leftleft_x
= leftleftPoint.X;
_SizePoint._original_leftleft_y
= leftleftPoint.Y;
_SizePoint._transparent_leftleft_x
= (rightrightPoint.X - leftleftPoint.X);
_SizePoint._transparent_leftleft_y
= (rightrightPoint.Y - leftleftPoint.Y);
_SizePoint._original_left_width
= leftSize.Width;
_SizePoint._original_left_height
= leftSize.Height;
_SizePoint._transparent_left_width
= (leftleftSize.Width - leftSize.Width);
_SizePoint._transparent_left_height
= (leftleftSize.Height - leftSize.Height);
_SizePoint._original_left_x
= leftPoint.X;
_SizePoint._original_left_y
= leftPoint.Y;
_SizePoint._transparent_left_x
= (leftleftPoint.X - leftPoint.X);
_SizePoint._transparent_left_y
= (leftleftPoint.Y - leftPoint.Y);
_SizePoint._original_width
= centerSize.Width;
_SizePoint._original_height
= centerSize.Height;
_SizePoint._transparent_width
= (leftSize.Width - centerSize.Width);
_SizePoint._transparent_height
= (leftSize.Height - centerSize.Height);
_SizePoint._original_x
= centerPoint.X;
_SizePoint._original_y
= centerPoint.Y;
_SizePoint._transparent_x
= (leftPoint.X - centerPoint.X);
_SizePoint._transparent_y
= (leftPoint.Y - centerPoint.Y);
_SizePoint._original_right_width
= rightSize.Width;
_SizePoint._original_right_height
= rightSize.Height;
_SizePoint._transparent_right_width
= (centerSize.Width - rightSize.Width);
_SizePoint._transparent_right_height
= (centerSize.Height - rightSize.Height);
_SizePoint._original_right_x
= rightPoint.X;
_SizePoint._original_right_y
= rightPoint.Y;
_SizePoint._transparent_right_x
= (centerPoint.X - rightPoint.X);
_SizePoint._transparent_right_y
= (centerPoint.Y - rightPoint.Y);
_SizePoint._original_rightright_width
= rightrightSize.Width;
_SizePoint._original_rightright_heigh
= rightrightSize.Height;
_SizePoint._transparent_rightright_width
= (rightSize.Width - rightrightSize.Width);
_SizePoint._transparent_rightright_heigh
= (rightSize.Height - rightrightSize.Height);
_SizePoint._original_rightright_x
= rightrightPoint.X;
_SizePoint._original_rightright_y
= rightrightPoint.Y;
_SizePoint._transparent_rightright_x
= (rightPoint.X - rightrightPoint.X);
_SizePoint._transparent_rightright_y
= (rightPoint.Y - rightrightPoint.Y);
this._Animation.AT = AnimationType.EaseOut;
this._Animation.Options.Data = _SizePoint;
this._Animation.Options.AllTime = this.animationTime;
this._Animation.Start(true, 0);
}
}
protected void Animation_AnimationIng(object sender, AnimationEventArgs e)
{
SizePoint _SizePoint
= (SizePoint)e.Data;
this.carouselPictureBox[0].Location = new Point((int)(_SizePoint._original_leftleft_x + _SizePoint._transparent_leftleft_x * e.progressTime), (int)(_SizePoint._original_leftleft_y + _SizePoint._transparent_leftleft_y * e.progressTime));
if (!_SizePoint.isswitch)
{
if (this.carouselPictureBox[0].Location.X > _SizePoint._original_x)
{
_SizePoint.isswitch
= true;
this.carouselPictureBoxIndex[0] = this.carouselPictureBoxIndex[4] + 1 >= this.transformImages.Count ? 0 : this.carouselPictureBoxIndex[4] + 1;
this.carouselPictureBox[0].Image = this.transformImages[this.carouselPictureBoxIndex[0]];
}
}
this.carouselPictureBox[1].Size = new Size((int)(_SizePoint._original_left_width + _SizePoint._transparent_left_width * e.progressTime), (int)(_SizePoint._original_left_height + _SizePoint._transparent_left_height * e.progressTime));
this.carouselPictureBox[1].Location = new Point((int)(_SizePoint._original_left_x + _SizePoint._transparent_left_x * e.progressTime), (int)(_SizePoint._original_left_y + _SizePoint._transparent_left_y * e.progressTime));
this.carouselPictureBox[2].Size = new Size((int)(_SizePoint._original_width + _SizePoint._transparent_width * e.progressTime), (int)(_SizePoint._original_height + _SizePoint._transparent_height * e.progressTime));
this.carouselPictureBox[2].Location = new Point((int)(_SizePoint._original_x + _SizePoint._transparent_x * e.progressTime), (int)(_SizePoint._original_y + _SizePoint._transparent_y * e.progressTime));
this.carouselPictureBox[3].Size = new Size((int)(_SizePoint._original_right_width + _SizePoint._transparent_right_width * e.progressTime), (int)(_SizePoint._original_right_height + _SizePoint._transparent_right_height * e.progressTime));
this.carouselPictureBox[3].Location = new Point((int)(_SizePoint._original_right_x + _SizePoint._transparent_right_x * e.progressTime), (int)(_SizePoint._original_right_y + _SizePoint._transparent_right_y * e.progressTime));
this.carouselPictureBox[4].Size = new Size((int)(_SizePoint._original_rightright_width + _SizePoint._transparent_rightright_width * e.progressTime), (int)(_SizePoint._original_rightright_heigh + _SizePoint._transparent_rightright_heigh * e.progressTime));
this.carouselPictureBox[4].Location = new Point((int)(_SizePoint._original_rightright_x + _SizePoint._transparent_rightright_x * e.progressTime), (int)(_SizePoint._original_rightright_y + _SizePoint._transparent_rightright_y * e.progressTime));
}
protected void Animation_AnimationEnding(object sender, AnimationEventArgs e)
{
this.locationCorrect(carouselPictureBox);
this.carouselPictureBox[0].BringToFront();
this.carouselPictureBox[4].BringToFront();
this.carouselPictureBox[1].BringToFront();
this.carouselPictureBox[3].BringToFront();
this.carouselPictureBox[2].BringToFront();
this.indexCorrect(this.carouselPictureBoxIndex);
this.intervalTimeValue = 0;
}
///
/// 初始化图片
///

public void Load()
{
if (this.carouselImages.Count > 0)
{
this.carouselPictureBoxIndex = new List<int>() { 0, 1, 2, 3, 4 };
this.resizePictureBox();
this.loadImageToPictureBox();
this.carouselPictureBox[0].BringToFront();
this.carouselPictureBox[4].BringToFront();
this.carouselPictureBox[1].BringToFront();
this.carouselPictureBox[3].BringToFront();
this.carouselPictureBox[2].BringToFront();
}
}
///
/// 开始轮播图片
///

public void Play()
{
if (!this.carouselTimer.Enabled)
{
this.carouselTimer.Start();
}
}
///
/// 停止轮播图片
///

public void Stop()
{
if (this.carouselTimer.Enabled)
{
this.carouselTimer.Stop();
}
}
///
/// 刷新轮播图片
///

public void Reset()
{
if (this.carouselTimer.Enabled)
{
this.carouselTimer.Stop();
this.Load();
this.Play();
}
}
private Size centerSize;
private Point centerPoint;
private Size leftleftSize;
private Point leftleftPoint;
private Size leftSize;
private Point leftPoint;
private Size rightSize;
private Point rightPoint;
private Size rightrightSize;
private Point rightrightPoint;
///
/// 重置PictureBox大小位置
///

private void resizePictureBox()
{
centerSize
= new Size(this.Size.Width / 2, this.isReflection ? this.Size.Height / 3 * 2 : this.Size.Height / 2);
centerPoint
= new Point(centerSize.Width / 2, this.isReflection ? centerSize.Height / 3 : centerSize.Height / 2);
leftSize
= new Size(centerSize.Width / 2, centerSize.Height / 2);
leftPoint
= new Point(centerPoint.X - leftSize.Width / 2, centerPoint.Y + leftSize.Height / 2);
leftleftSize
= new Size(leftSize.Width / 2, leftSize.Height / 2);
leftleftPoint
= new Point(leftPoint.X - leftleftSize.Width / 2, leftPoint.Y + leftleftSize.Height / 2);
rightSize
= new Size(centerSize.Width / 2, centerSize.Height / 2);
rightPoint
= new Point(centerPoint.X + centerSize.Width - rightSize.Width / 2, centerPoint.Y + rightSize.Height / 2);
rightrightSize
= new Size(rightSize.Width / 2, rightSize.Height / 2);
rightrightPoint
= new Point(rightPoint.X + rightSize.Width - rightrightSize.Width / 2, rightPoint.Y + rightrightSize.Height / 2);
this.carouselPictureBox[0].Size = leftleftSize;
this.carouselPictureBox[0].Location = leftleftPoint;
this.carouselPictureBox[1].Size = leftSize;
this.carouselPictureBox[1].Location = leftPoint;
this.carouselPictureBox[2].Size = centerSize;
this.carouselPictureBox[2].Location = centerPoint;
this.carouselPictureBox[3].Size = rightSize;
this.carouselPictureBox[3].Location = rightPoint;
this.carouselPictureBox[4].Size = rightrightSize;
this.carouselPictureBox[4].Location = rightrightPoint;
}
///
/// PictureBox加载对应图片
///

private void loadImageToPictureBox()
{
this.carouselPictureBoxIndex[0] = 0;
this.carouselPictureBoxIndex[1] = this.carouselPictureBoxIndex[0] + 1 >= this.carouselImages.Count ? 0 : this.carouselPictureBoxIndex[0] + 1;
this.carouselPictureBoxIndex[2] = this.carouselPictureBoxIndex[1] + 1 >= this.carouselImages.Count ? 0 : this.carouselPictureBoxIndex[1] + 1;
this.carouselPictureBoxIndex[3] = this.carouselPictureBoxIndex[2] + 1 >= this.carouselImages.Count ? 0 : this.carouselPictureBoxIndex[2] + 1;
this.carouselPictureBoxIndex[4] = this.carouselPictureBoxIndex[3] + 1 >= this.carouselImages.Count ? 0 : this.carouselPictureBoxIndex[3] + 1;
foreach (Image image in this.carouselImages)
{
this.transformImages.Add(this.isReflection ? this.reflectionTransform((Bitmap)image) : image);
}
this.carouselPictureBox[0].Image = this.transformImages[this.carouselPictureBoxIndex[0]];
this.carouselPictureBox[1].Image = this.transformImages[this.carouselPictureBoxIndex[1]];
this.carouselPictureBox[2].Image = this.transformImages[this.carouselPictureBoxIndex[2]];
this.carouselPictureBox[3].Image = this.transformImages[this.carouselPictureBoxIndex[3]];
this.carouselPictureBox[4].Image = this.transformImages[this.carouselPictureBoxIndex[4]];
}
///
/// 纠正PictureBox位置
///

/// 要纠正的PictureBox
private void locationCorrect(List pbList)
{
PictureBox pb
= pbList[0];
for (int i = 0; i 1; i++)
{
pbList[i]
= pbList[i + 1];
}
pbList[pbList.Count
- 1] = pb;
}
///
/// 纠正PictureBox位置索引
///

/// 要纠正的PictureBox
private void indexCorrect(List<int> indexList)
{
int index = indexList[0];
for (int i = 0; i 1; i++)
{
indexList[i]
= indexList[i + 1];
}
indexList[indexList.Count
- 1] = index;
}
int reflectiOnTop= 10;//倒影边距
int reflectiOnBrightness= -50;//明亮度
int reflectiOnTransparentStart= 200;//倒影开始透明度
int reflectiOnTransparentEnd= -0;//倒影结束透明度
///
/// 倒影变换
///

///
/// 透明度(0-255)
private Bitmap reflectionTransform(Bitmap bmp)
{
Color pixel;
int reflectiOnHeight= bmp.Height / 2;//倒影高度
int transparentGradient = 0;//透明梯度
transparentGradient = (this.reflectionTransparentEnd - this.reflectionTransparentStart) / reflectionHeight;
if (transparentGradient == 0)
transparentGradient
= 1;
Bitmap result
= new Bitmap(bmp.Width, bmp.Height + reflectionHeight + this.reflectionTop);
for (int x = 0; x )
{
for (int y = 0; y )
{
result.SetPixel(x, y, bmp.GetPixel(x, y));
}
}
for (int y = 0; y )
{
for (int x = 0; x )
{
pixel = bmp.GetPixel(x, bmp.Height - 1 - y);
result.SetPixel(x, bmp.Height
- 1 + this.reflectionTop + y, Color.FromArgb(this.verifyRGB(this.reflectionTransparentStart + y * transparentGradient), this.verifyRGB(pixel.R + this.reflectionBrightness), this.verifyRGB(pixel.G + this.reflectionBrightness), this.verifyRGB(pixel.B + this.reflectionBrightness)));
}
}
return result;
}
///
/// 检查RGB值ed有效范围
///

///
///
private int verifyRGB(int rgb)
{
if (rgb <0)
return 0;
if (rgb > 255)
return 255;
return rgb;
}
protected struct SizePoint
{
public bool isswitch;
public int _transparent_leftleft_x;
public int _transparent_leftleft_y;
public int _original_leftleft_x;
public int _original_leftleft_y;
public int _transparent_left_width;
public int _transparent_left_height;
public int _transparent_left_x;
public int _transparent_left_y;
public int _original_left_width;
public int _original_left_height;
public int _original_left_x;
public int _original_left_y;
public int _transparent_width;
public int _transparent_height;
public int _transparent_x;
public int _transparent_y;
public int _original_width;
public int _original_height;
public int _original_x;
public int _original_y;
public int _transparent_right_width;
public int _transparent_right_height;
public int _transparent_right_x;
public int _transparent_right_y;
public int _original_right_width;
public int _original_right_height;
public int _original_right_x;
public int _original_right_y;
public int _transparent_rightright_width;
public int _transparent_rightright_heigh;
public int _transparent_rightright_x;
public int _transparent_rightright_y;
public int _original_rightright_width;
public int _original_rightright_heigh;
public int _original_rightright_x;
public int _original_rightright_y;
}
///
/// 清理所有正在使用的资源。
///

/// 如果应释放托管资源,为 true;否则为 false。
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
if (this._Animation != null)
{
this._Animation.Dispose();
}
if (this.carouselTimer != null)
{
this.carouselTimer.Dispose();
}
}
base.Dispose(disposing);
}
}

 源码下载:CSharp图片轮播.zip


推荐阅读
  • 如果应用程序经常播放密集、急促而又短暂的音效(如游戏音效)那么使用MediaPlayer显得有些不太适合了。因为MediaPlayer存在如下缺点:1)延时时间较长,且资源占用率高 ... [详细]
  • 本文详细介绍了Linux系统中用于管理IPC(Inter-Process Communication)资源的两个重要命令:ipcs和ipcrm。通过这些命令,用户可以查看和删除系统中的消息队列、共享内存和信号量。 ... [详细]
  • 利用python爬取豆瓣电影Top250的相关信息,包括电影详情链接,图片链接,影片中文名,影片外国名,评分,评价数,概况,导演,主演,年份,地区,类别这12项内容,然后将爬取的信息写入Exce ... [详细]
  • malloc 是 C 语言中的一个标准库函数,全称为 memory allocation,即动态内存分配。它用于在程序运行时申请一块指定大小的连续内存区域,并返回该区域的起始地址。当无法预先确定内存的具体位置时,可以通过 malloc 动态分配内存。 ... [详细]
  • NX二次开发:UFUN点收集器UF_UI_select_point_collection详解
    本文介绍了如何在NX中使用UFUN库进行点收集器的二次开发,包括必要的头文件包含、初始化和选择点集合的具体实现。 ... [详细]
  • 解决SQL Server数据库sa登录名无法连接的问题
    在安装SQL Server数据库后,使用Windows身份验证成功,但使用SQL Server身份验证时遇到问题。本文将介绍如何通过设置sa登录名的密码、启用登录名状态以及开启TCP协议来解决这一问题。 ... [详细]
  • 机器学习算法:SVM(支持向量机)
    SVM算法(SupportVectorMachine,支持向量机)的核心思想有2点:1、如果数据线性可分,那么基于最大间隔的方式来确定超平面,以确保全局最优, ... [详细]
  • 本文介绍了如何在 ASP.NET 中设置 Excel 单元格格式为文本,获取多个单元格区域并作为表头,以及进行单元格合并、赋值、格式设置等操作。 ... [详细]
  • LDAP服务器配置与管理
    本文介绍如何通过安装和配置SSSD服务来统一管理用户账户信息,并实现其他系统的登录调用。通过图形化交互界面配置LDAP服务器,确保用户账户信息的集中管理和安全访问。 ... [详细]
  • 本文详细介绍了Java代码分层的基本概念和常见分层模式,特别是MVC模式。同时探讨了不同项目需求下的分层策略,帮助读者更好地理解和应用Java分层思想。 ... [详细]
  • 网络爬虫的规范与限制
    本文探讨了网络爬虫引发的问题及其解决方案,重点介绍了Robots协议的作用和使用方法,旨在为网络爬虫的合理使用提供指导。 ... [详细]
  • 自动验证时页面显示问题的解决方法
    在使用自动验证功能时,页面未能正确显示错误信息。通过使用 `dump($info->getError())` 可以帮助诊断和解决问题。 ... [详细]
  • IOS Run loop详解
    为什么80%的码农都做不了架构师?转自http:blog.csdn.netztp800201articledetails9240913感谢作者分享Objecti ... [详细]
  • 深入解析HTML5字符集属性:charset与defaultCharset
    本文将详细介绍HTML5中新增的字符集属性charset和defaultCharset,帮助开发者更好地理解和应用这些属性,以确保网页在不同环境下的正确显示。 ... [详细]
  • 网站访问全流程解析
    本文详细介绍了从用户在浏览器中输入一个域名(如www.yy.com)到页面完全展示的整个过程,包括DNS解析、TCP连接、请求响应等多个步骤。 ... [详细]
author-avatar
堕落戥囝_631
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有