加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

图片轮播控件----------WinForm控件开发系列

发布时间:2020-12-15 08:00:36 所属栏目:Java 来源:网络整理
导读:??? /// summary /// 图片轮播控件 /// 但部分属性更改时要调用Reset()方法刷新,这涉及到大量倒影图片的生成原因 /// /summary [ToolboxItem( true )] [DefaultProperty( " Images " )] [Description( " 图片轮播控件,但部分属性更改时要调用Reset()方法刷

???

  /// <summary>
  /// 图片轮播控件
  /// 但部分属性更改时要调用Reset()方法刷新,这涉及到大量倒影图片的生成原因
  /// </summary>
  [ToolboxItem(true)]
  [DefaultProperty("Images")]
  [Description("图片轮播控件,但部分属性更改时要调用Reset()方法刷新,这涉及到大量倒影图片的生成原因")]
  public partial class ImageCarouselDevelopExt : Control
  {
    #region

    private int displayCount = 5;
    /// <summary>
    /// 图片框数量(必须为奇数)
    /// </summary>
    [DefaultValue(5)]
    [Description("图片框数量(必须为奇数)")]
    public int DisplayCount
    {
      get { return this.displayCount; }
      set
      {
        if (this.displayCount == value || value < 1 || value % 2 != 1)
          return;
        this.displayCount = value;
      }
    }

    private int displayWidth = 400;
    /// <summary>
    /// 中间图片框宽度
    /// </summary>
    [DefaultValue(400)]
    [Description("中间图片框宽度(默认400)")]
    public int DisplayWidth
    {
      get { return this.displayWidth; }
      set
      {
        if (this.displayWidth == value || value < 1)
          return;
        this.displayWidth = value;
      }
    }

    private int displayHeight = 200;
    /// <summary>
    /// 中间图片框高度
    /// </summary>
    [DefaultValue(200)]
    [Description("中间图片框高度(默认200)")]
    public int DisplayHeight
    {
      get { return this.displayHeight; }
      set
      {
        if (this.displayHeight == value || value < 1)
          return;
        this.displayHeight = value;
      }
    }
    /// <summary>
    /// 中间图片框最终高度
    /// </summary>
    [Browsable(false)]
    [Description("中间图片框最终高度")]
    public int DisplayFinallyHeight
    {
      get
      {
        return this.ReflectionShow ? this.DisplayHeight + this.reflectionTop + this.ReflectionHeight : this.DisplayHeight;
      }
    }

    private float displayShrink = 0.8f;
    /// <summary>
    ///图片框间缩小比例 
    /// </summary>
    [DefaultValue(0.8f)]
    [Description("图片框间缩小比例")]
    public float DisplayShrink
    {
      get { return this.displayShrink; }
      set
      {
        if (this.displayShrink == value)
          return;
        this.displayShrink = value;
      }
    }

    private int displayInterval = 0;
    /// <summary>
    ///图片框间隔距离偏移量(为0时自动分配)
    /// </summary>
    [DefaultValue(0)]
    [Description("图片框间隔距离偏移量(为0时自动分配)")]
    public int DisplayInterval
    {
      get { return this.displayInterval; }
      set
      {
        if (this.displayInterval == value || value < 0)
          return;
        this.displayInterval = value;
      }
    }

    private SlideType displaySlideDirection = SlideType.RightToLeft;
    /// <summary>
    ///图片框滑动方向 
    /// </summary>
    [DefaultValue(SlideType.RightToLeft)]
    [Description("图片框滑动方向")]
    public SlideType DisplaySlideDirection
    {
      get { return this.displaySlideDirection; }
      set
      {
        if (this.displaySlideDirection == value)
          return;
        this.displaySlideDirection = value;
      }
    }

    private bool reflectionShow = false;
    /// <summary>
    /// 是否添加倒影
    /// </summary>
    [DefaultValue(false)]
    [Description("是否添加倒影")]
    public bool ReflectionShow
    {
      get { return this.reflectionShow; }
      set
      {
        if (this.reflectionShow == value)
          return;
        this.reflectionShow = value;
      }
    }

    private int reflectionHeight = 50;
    /// <summary>
    /// 倒影高度
    /// </summary>
    [DefaultValue(50)]
    [Description("倒影高度")]
    public int ReflectionHeight
    {
      get { return this.reflectionHeight; }
      set
      {
        if (this.reflectionHeight == value || value < 0)
          return;
        this.reflectionHeight = value;
      }
    }

    private double animationTime = 300d;
    /// <summary>
    /// 动画播放的总时间
    /// </summary>
    [DefaultValue(300d)]
    [Description("动画播放的总时间(默认300毫秒)")]
    public double AnimationTime
    {
      get { return this.animationTime; }
      set
      {
        if (this.animationTime == value || value < 10)
          return;
        this.animationTime = value;
      }
    }

    private int intervalTime = 1000;
    /// <summary>
    /// 图片轮播的时间间隔
    /// </summary>
    [DefaultValue(1000)]
    [Description("图片轮播的时间间隔(默认1000毫秒)")]
    public int IntervalTime
    {
      get { return this.intervalTime; }
      set
      {
        if (this.intervalTime == value || value < 10)
          return;
        this.intervalTime = value;
      }
    }

    private ImageCarouselCollection imageCarouselDevelopCollection;
    /// <summary>
    /// 要播放的图片集合
    /// </summary>
    [DefaultValue(null)]
    [Description("要播放的图片集合")]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
    public ImageCarouselCollection Images
    {
      get
      {
        if (this.imageCarouselDevelopCollection == null)
        {
          this.imageCarouselDevelopCollection = new ImageCarouselCollection(this);
        }
        return this.imageCarouselDevelopCollection;
      }
    }

    /// <summary>
    ///当前图片框索引 
    /// </summary>
    int currentDisplayIndex = 0;
    /// <summary>
    ///当前图片框索引 
    /// </summary>
    int currentImageIndex = 0;
    /// <summary>
    /// 图片框是否已切换到指定图片(图片数量大于图片框数量时使用)
    /// </summary>
    private bool isSwitchImage = false;
    /// <summary>
    /// 图片框集合
    /// </summary>
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
    private List<DisplayItem> displayList = new List<DisplayItem>();
    /// <summary>
    /// 图片轮播的时间间隔累计(-1为动画正在切换中)
    /// </summary>
    private int intervalTimeValue = 0;
    /// <summary>
    /// 动画间隔定时器
    /// </summary>
    private Timer intervalTimer;
    /// <summary>
    /// 动画播放定时器
    /// </summary>
    private AnimationTimer animationTimer;
    /// <summary>
    /// 倒影边距
    /// </summary>
    int reflectionTop = 10;
    /// <summary>
    /// 明亮度
    /// </summary>
    int reflectionBrightness = -50;
    /// <summary>
    /// 倒影开始透明度
    /// </summary>
    int reflectionTransparentStart = 200;
    /// <summary>
    /// 倒影结束透明度
    /// </summary>
    int reflectionTransparentEnd = -0;
    #endregion

    public ImageCarouselDevelopExt()
    {
      SetStyle(ControlStyles.UserPaint,true);
      SetStyle(ControlStyles.AllPaintingInWmPaint,true);
      SetStyle(ControlStyles.OptimizedDoubleBuffer,true);
      SetStyle(ControlStyles.ResizeRedraw,true);
      SetStyle(ControlStyles.SupportsTransparentBackColor,true);
      InitializeComponent();

      this.intervalTimer = new Timer();
      this.intervalTimer.Interval = 50;
      this.intervalTimer.Tick += new EventHandler(this.intervalTimer_Tick);

      this.animationTimer = new AnimationTimer(this,new AnimationOptions());
      this.animationTimer.AnimationIng += new AnimationTimer.AnimationHandel(this.animationTimer_AnimationIng);
      this.animationTimer.AnimationEnding += new AnimationTimer.AnimationHandel(this.animationTimer_AnimationEnding);
    }

    protected override void OnPaint(PaintEventArgs e)
    {
      base.OnPaint(e);

      Graphics g = e.Graphics;

      //绘制顺序很重要
      if (this.displayList.Count > 0)
      {
        SolidBrush image_sb = new SolidBrush(Color.White);
        int center_index = this.DisplayCount / 2;
        if (this.DisplaySlideDirection == SlideType.RightToLeft)//右往左
        {
          for (int i = 0; i < center_index; i++)
          {
            //左边图片框
            int left_index = this.TransformDisplayIndex(i);
            this.DrawImageItem(g,image_sb,this.Images[this.displayList[left_index].ImageIndex],this.displayList[left_index].CurrentRectF);
            //中间图片框
            if (i == center_index - 1 && this.intervalTimeValue == -1)
            {
              int index = this.TransformDisplayIndex(center_index);
              this.DrawImageItem(g,this.Images[this.displayList[index].ImageIndex],this.displayList[index].CurrentRectF);
            }
            //右边图片框
            int right_index = this.TransformDisplayIndex(this.DisplayCount - 1 - i);
            this.DrawImageItem(g,this.Images[this.displayList[right_index].ImageIndex],this.displayList[right_index].CurrentRectF);
          }
        }
        else
        {
          for (int i = this.DisplayCount - 1; i > center_index; i--)//左往右
          {
            //右边图片框
            int right_index = this.TransformDisplayIndex(i);
            this.DrawImageItem(g,this.displayList[right_index].CurrentRectF);
            //中间图片框
            if (i == center_index + 1 && this.intervalTimeValue == -1)
            {
              int index = this.TransformDisplayIndex(center_index);
              this.DrawImageItem(g,this.displayList[index].CurrentRectF);
            }
            //左边图片框
            int left_index = this.TransformDisplayIndex(this.DisplayCount - 1 - i);
            this.DrawImageItem(g,this.displayList[left_index].CurrentRectF);
          }
        }

        //中间图片框
        if (this.intervalTimeValue == 0)
        {
          int index2 = this.TransformDisplayIndex(center_index);
          this.DrawImageItem(g,this.Images[this.displayList[index2].ImageIndex],this.displayList[index2].CurrentRectF);
        }
        image_sb.Dispose();
      }
    }

    /// <summary>
    /// 定时器
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void intervalTimer_Tick(object sender,EventArgs e)
    {
      if (this.intervalTimeValue == -1)
        return;
      this.intervalTimeValue += this.intervalTimer.Interval;
      if (this.intervalTimeValue >= this.intervalTime)
      {
        this.intervalTimeValue = -1;
        this.isSwitchImage = false;

        if (this.DisplaySlideDirection == SlideType.RightToLeft)
        {
          for (int i = 0; i < this.DisplayCount; i++)
          {
            int index = this.TransformDisplayIndex(i);
            int prev_index = this.TransformDisplayIndex((i == 0) ? this.DisplayCount - 1 : i - 1);
            this.displayList[index].BeforeRectF = this.displayList[index].CurrentRectF;
            this.displayList[index].TargrtRectF = this.displayList[prev_index].CurrentRectF;
          }
        }
        else
        {
          for (int i = 0; i < this.DisplayCount; i++)
          {
            int index = this.TransformDisplayIndex(i);
            int next_index = this.TransformDisplayIndex((i == this.DisplayCount - 1) ? 0 : i + 1);
            this.displayList[index].BeforeRectF = this.displayList[index].CurrentRectF;
            this.displayList[index].TargrtRectF = this.displayList[next_index].CurrentRectF;
          }
        }
        this.animationTimer.AT = AnimationType.EaSEOut;
        this.animationTimer.Options.AllTime = this.animationTime;
        this.animationTimer.Start(true,0);
      }
    }

    /// <summary>
    /// 动画进行中
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void animationTimer_AnimationIng(object sender,AnimationEventArgs e)
    {
      int center_index = this.DisplayCount / 2;
      for (int i = 0; i <= center_index; i++)
      {
        int index = this.TransformDisplayIndex(i);
        float w = this.displayList[index].BeforeRectF.Width + (this.displayList[index].TargrtRectF.Width - this.displayList[index].BeforeRectF.Width) * (float)e.progressTime;
        float h = this.displayList[index].BeforeRectF.Height + (this.displayList[index].TargrtRectF.Height - this.displayList[index].BeforeRectF.Height) * (float)e.progressTime;
        float x = this.displayList[index].BeforeRectF.X + (this.displayList[index].TargrtRectF.X - this.displayList[index].BeforeRectF.X) * (float)e.progressTime;
        float y = (this.ClientRectangle.Height - h) / 2;
        this.displayList[index].CurrentRectF = new RectangleF(x,y,w,h);
      }
      for (int i = this.DisplayCount - 1; i > center_index; i--)
      {
        int index = this.TransformDisplayIndex(i);
        float w = this.displayList[index].BeforeRectF.Width + (this.displayList[index].TargrtRectF.Width - this.displayList[index].BeforeRectF.Width) * (float)e.progressTime;
        float h = this.displayList[index].BeforeRectF.Height + (this.displayList[index].TargrtRectF.Height - this.displayList[index].BeforeRectF.Height) * (float)e.progressTime;
        float x = this.displayList[index].BeforeRectF.X + (this.displayList[index].TargrtRectF.X - this.displayList[index].BeforeRectF.X) * (float)e.progressTime;
        float y = (this.ClientRectangle.Height - h) / 2;
        this.displayList[index].CurrentRectF = new RectangleF(x,h);
      }

      if (this.Images.Count > this.DisplayCount && !this.isSwitchImage)//当图片数量大于图片框数处理
      {
        if (this.DisplaySlideDirection == SlideType.RightToLeft)
        {
          if (this.displayList[this.TransformDisplayIndex(0)].CurrentRectF.X > (this.ClientRectangle.Width - this.DisplayWidth) / 2)
          {
            int index = this.displayList[this.TransformDisplayIndex(this.DisplayCount - 1)].ImageIndex;
            index += 1;
            if (index > this.Images.Count - 1)
              index -= this.Images.Count;
            this.displayList[this.TransformDisplayIndex(0)].ImageIndex = index;

            this.isSwitchImage = true;
          }
        }
        else
        {
          if (this.displayList[this.TransformDisplayIndex(this.DisplayCount - 1)].CurrentRectF.X < (this.ClientRectangle.Width - this.DisplayWidth) / 2 + this.ClientRectangle.Width / 2)
          {
            int index = this.displayList[this.TransformDisplayIndex(0)].ImageIndex;
            index += 1;
            if (index > this.Images.Count - 1)
              index -= this.Images.Count;
            this.displayList[this.TransformDisplayIndex(this.DisplayCount - 1)].ImageIndex = index;

            this.isSwitchImage = true;
          }
        }
      }
      this.Invalidate();

    }

    /// <summary>
    /// 动画结束
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void animationTimer_AnimationEnding(object sender,AnimationEventArgs e)
    {
      if (this.DisplaySlideDirection == SlideType.RightToLeft)
      {
        this.currentDisplayIndex++;
        if (this.currentDisplayIndex > this.DisplayCount - 1)
          this.currentDisplayIndex -= this.DisplayCount;
      }
      else
      {
        this.currentDisplayIndex--;
        if (this.currentDisplayIndex < 0)
          this.currentDisplayIndex += this.DisplayCount;
      }

      this.intervalTimeValue = 0;
    }

    /// <summary>
    /// 绘制图片
    /// </summary>
    /// <param name="g"></param>
    /// <param name="imageCarousel"></param>
    /// <param name="rectf"></param>
    private void DrawImageItem(Graphics g,SolidBrush imageSb,ImageCarousel imageCarousel,RectangleF rectf)
    {
      if (this.ReflectionShow)
      {
        if (imageCarousel.ReflectionImage != null)
        {
          g.DrawImage(imageCarousel.ReflectionImage,rectf);
        }
        else
        {
          if (imageCarousel.Image != null)
          {
            imageCarousel.ReflectionImage = this.TransformReflection((Bitmap)imageCarousel.Image);
          }
          else
          {
            g.FillRectangle(imageSb,rectf);
          }
        }
      }
      else
      {
        if (imageCarousel.Image != null)
          g.DrawImage(imageCarousel.Image,rectf);
        else
          g.FillRectangle(imageSb,rectf);
      }
    }

    /// <summary>
    /// 初始化图片框
    /// </summary>
    private void InitializeDisplay()
    {
      this.currentDisplayIndex = 0;
      this.currentImageIndex = 0;
      this.displayList = new List<DisplayItem>();
      for (int i = 0; i < this.DisplayCount; i++)
      {
        this.displayList.Add(new DisplayItem());
      }

      int excursion = (int)(this.DisplayInterval != 0 ? this.DisplayInterval : this.DisplayWidth * this.DisplayShrink / 4);
      int center_index = this.DisplayCount / 2;

      //中间图片框
      this.displayList[center_index].CurrentRectF = new RectangleF((this.ClientRectangle.Width - this.DisplayWidth) / 2,(this.ClientRectangle.Height - this.DisplayFinallyHeight) / 2,this.DisplayWidth,this.DisplayFinallyHeight);

      for (int i = center_index + 1; i < this.DisplayCount; i++)
      {
        float w = this.displayList[i - 1].CurrentRectF.Width * this.DisplayShrink;
        float h = this.displayList[i - 1].CurrentRectF.Height * this.DisplayShrink;
        float y = (this.ClientRectangle.Height - h) / 2;

        //右边图片框
        float x_right = this.displayList[i - 1].CurrentRectF.Right + excursion - w;
        this.displayList[i].CurrentRectF = new RectangleF(x_right,h);

        //左边图片框
        float x_left = this.displayList[this.DisplayCount - 1 - i + 1].CurrentRectF.X - excursion;
        this.displayList[this.DisplayCount - 1 - i].CurrentRectF = new RectangleF(x_left,h);
      }

      if (this.DisplaySlideDirection == SlideType.RightToLeft)
      {
        for (int i = 0; i < this.DisplayCount; i++)
        {
          this.displayList[i].ImageIndex = this.TransformImageIndex(i);
        }
      }
      else
      {
        for (int i = 0; i < this.DisplayCount; i++)
        {
          this.displayList[this.DisplayCount-1-i].ImageIndex = this.TransformImageIndex(i);
        }
      }
    }

    /// <summary>
    /// 初始化倒影图片集
    /// </summary>
    /// <param name="index">1-为初始化所有图片</param>
    private void InitializeReflectionImages(int index = -1)
    {
      if (this.ReflectionShow)
      {
        if (index >= 0)
        {
          if (this.Images[index].ReflectionImage != null)
          {
            this.Images[index].ReflectionImage.Dispose();
          }
          if (this.Images[index].Image != null)
          {
            this.Images[index].ReflectionImage = TransformReflection((Bitmap)this.Images[index].Image);
          }
        }
        else
        {
          for (int i = 0; i < this.Images.Count; i++)
          {
            if (this.Images[i].ReflectionImage != null)
            {
              this.Images[i].ReflectionImage.Dispose();
            }
            if (this.Images[i].Image != null)
            {
              this.Images[i].ReflectionImage = TransformReflection((Bitmap)this.Images[i].Image);
            }
          }
        }
      }
    }
    /// <summary>
    /// 获取指定索引图片框
    /// </summary>
    /// <param name="i">定索引</param>
    /// <returns></returns>
    private int TransformDisplayIndex(int i)
    {
      int index = this.currentDisplayIndex + i;
      if (index > this.DisplayCount - 1)
        index -= this.DisplayCount;
      return index;
    }

    /// <summary>
    /// 获取指定索引图片(防止图片比图片框少)
    /// </summary>
    /// <param name="i">定索引</param>
    /// <returns></returns>
    private int TransformImageIndex(int i)
    {
      int index = this.currentImageIndex + i;
      if (index > this.Images.Count - 1)
        index -= this.Images.Count;
      return index;
    }

    /// <summary>
    /// 倒影变换
    /// </summary>
    /// <param name="bmp"></param>
    /// <param name="val">透明度(0-255)</param>
    private Bitmap TransformReflection(Bitmap bmp)
    {
      Color pixel;
      int transparentGradient = 0;//透明梯度
      transparentGradient = (this.reflectionTransparentEnd - this.reflectionTransparentStart) / this.ReflectionHeight;
      if (transparentGradient == 0)
        transparentGradient = 1;

      Bitmap result = new Bitmap(bmp.Width,this.DisplayFinallyHeight);
      for (int x = 0; x < bmp.Width; x++)
      {
        for (int y = 0; y < bmp.Height; y++)
        {
          result.SetPixel(x,bmp.GetPixel(x,y));
        }
      }

      for (int y = 0; y < this.ReflectionHeight; y++)
      {
        for (int x = 0; x < bmp.Width; x++)
        {
          pixel = bmp.GetPixel(x,bmp.Height - 1 - y);
          int a = this.VerifyRGB(this.reflectionTransparentStart + y * transparentGradient);
          int r = this.VerifyRGB(pixel.R + this.reflectionBrightness);
          int g = this.VerifyRGB(pixel.G + this.reflectionBrightness);
          int b = this.VerifyRGB(pixel.B + this.reflectionBrightness);
          result.SetPixel(x,bmp.Height - 1 + this.reflectionTop + y,Color.FromArgb(a,r,g,b));
        }
      }
      return result;
    }

    /// <summary>
    /// 检查RGB值ed有效范围
    /// </summary>
    /// <param name="rgb"></param>
    /// <returns></returns>
    private int VerifyRGB(int rgb)
    {
      if (rgb < 0)
        return 0;
      if (rgb > 255)
        return 255;
      return rgb;
    }

    #region 公共方法

    /// <summary>
    /// 开始轮播图片
    /// </summary>
    public void Play()
    {
      this.InitializeDisplay();
      this.intervalTimer.Enabled = true;
    }

    /// <summary>
    /// 继续轮播图片
    /// </summary>
    public void Continue()
    {
      this.intervalTimer.Enabled = true;
    }

    /// <summary>
    /// 暂停轮播图片
    /// </summary>
    public void Suspend()
    {
      this.intervalTimer.Enabled = false;
    }

    /// <summary>
    /// 重新加载轮播图片
    /// </summary>
    /// <param name="RefreshDisplay">true为重新计算图片框信息</param>
    /// <param name="RefreshImage">true为重新生成倒影图片</param>
    public void Reset(bool RefreshDisplay,bool RefreshImage)
    {
      this.currentDisplayIndex = 0;
      this.currentImageIndex = 0;
      bool status = (this.intervalTimer == null ? false : true) && this.intervalTimer.Enabled;
      if (status)
      {
        this.intervalTimer.Enabled = false;
        this.animationTimer.Stop();
      }
      if (RefreshImage)
        this.InitializeReflectionImages(-1);
      if (RefreshDisplay)
        this.InitializeDisplay();
      if (status)
      {
        int i = this.intervalTimer.Interval;
        this.intervalTimeValue = this.intervalTime;
        this.intervalTimer.Interval = 1;
        this.intervalTimer.Enabled = true;
        this.intervalTimer.Interval = i;
      }
    }

    #endregion

    protected override void Dispose(bool disposing)
    {
      if (disposing && (components != null))
      {
        components.Dispose();
        if (this.animationTimer != null)
        {
          this.animationTimer.Dispose();
        }
        if (this.intervalTimer != null)
        {
          this.intervalTimer.Dispose();
        }
        if (this.Images != null)
        {
          for (int i = 0; i < this.Images.Count; i++)
          {
            this.Images[i].ReflectionImage.Dispose();
          }
        }
      }
      base.Dispose(disposing);
    }

    /// <summary>
    /// 图片集合
    /// </summary>
    [Description("图片集合")]
    [Editor(typeof(CollectionEditorExt),typeof(UITypeEditor))]
    public sealed class ImageCarouselCollection : IList,ICollection,IEnumerable
    {
      private ArrayList imageCarouselList = new ArrayList();
      private ImageCarouselDevelopExt owner;

      public ImageCarouselCollection(ImageCarouselDevelopExt owner)
      {
        this.owner = owner;
      }

      #region IEnumerable

      public IEnumerator GetEnumerator()
      {
        ImageCarouselDevelopExt.ImageCarousel[] listArray = new ImageCarouselDevelopExt.ImageCarousel[this.imageCarouselList.Count];
        for (int index = 0; index < listArray.Length; ++index)
          listArray[index] = (ImageCarouselDevelopExt.ImageCarousel)this.imageCarouselList[index];
        return listArray.GetEnumerator();
      }

      #endregion

      #region ICollection

      public void CopyTo(Array array,int index)
      {
        for (int i = 0; i < this.Count; i++)
          array.SetValue(this.imageCarouselList[i],i + index);
      }

      public int Count
      {
        get
        {
          return this.imageCarouselList.Count;
        }
      }

      public bool IsSynchronized
      {
        get
        {
          return false;
        }
      }

      public object SyncRoot
      {
        get
        {
          return (object)this;
        }
      }

      #endregion

      #region IList

      public int Add(object value)
      {
        ImageCarouselDevelopExt.ImageCarousel fisheyeItem = (ImageCarouselDevelopExt.ImageCarousel)value;
        this.imageCarouselList.Add(fisheyeItem);
        return this.Count - 1;
      }

      public void Clear()
      {
        for (int i = 0; i < this.imageCarouselList.Count; i++)
        {
          ImageCarouselDevelopExt.ImageCarousel item = (ImageCarouselDevelopExt.ImageCarousel)this.imageCarouselList[i];
          if (item.ReflectionImage != null)
          {
            item.ReflectionImage.Dispose();
          }
        }
        this.imageCarouselList.Clear();
      }

      public bool Contains(object value)
      {
        return this.IndexOf(value) != -1;
      }

      public int IndexOf(object value)
      {
        return this.imageCarouselList.IndexOf(value);
      }

      public void Insert(int index,object value)
      {
        throw new NotImplementedException();
      }

      public bool IsFixedSize
      {
        get { return false; }
      }

      public bool IsReadOnly
      {
        get { return false; }
      }

      public void Remove(object value)
      {
        ImageCarouselDevelopExt.ImageCarousel item = (ImageCarouselDevelopExt.ImageCarousel)value;
        if (item.ReflectionImage != null)
        {
          item.ReflectionImage.Dispose();
        }
        this.imageCarouselList.Remove(item);
      }

      public void RemoveAt(int index)
      {
        ImageCarouselDevelopExt.ImageCarousel item = (ImageCarouselDevelopExt.ImageCarousel)this.imageCarouselList[index];
        if (item.ReflectionImage != null)
        {
          item.ReflectionImage.Dispose();
        }
        this.imageCarouselList.RemoveAt(index);
      }

      public ImageCarouselDevelopExt.ImageCarousel this[int index]
      {
        get
        {
          return (ImageCarouselDevelopExt.ImageCarousel)this.imageCarouselList[index];
        }
        set
        {
          ImageCarouselDevelopExt.ImageCarousel item = (ImageCarouselDevelopExt.ImageCarousel)this.imageCarouselList[index];
          if (item.ReflectionImage != null)
          {
            item.ReflectionImage.Dispose();
            item.ReflectionImage = null;
          }
          this.imageCarouselList[index] = (ImageCarouselDevelopExt.ImageCarousel)value;
        }
      }

      object IList.this[int index]
      {
        get
        {
          return (object)this.imageCarouselList[index];
        }
        set
        {
          ImageCarouselDevelopExt.ImageCarousel item = (ImageCarouselDevelopExt.ImageCarousel)this.imageCarouselList[index];
          if (item.ReflectionImage != null)
          {
            item.ReflectionImage.Dispose();
            item.ReflectionImage = null;
          }
          this.imageCarouselList[index] = (ImageCarouselDevelopExt.ImageCarousel)value;
        }
      }

      #endregion

    }

    /// <summary>
    /// 图片
    /// </summary>
    [Description("图片")]
    public class ImageCarousel
    {
      /// <summary>
      /// 图片
      /// </summary>
      [Description("图片")]
      public Image Image { get; set; }
      /// <summary>
      /// 倒影图片
      /// </summary>
      [Browsable(false)]
      [Description("倒影图片")]
      public Image ReflectionImage { get; set; }
    }

    /// <summary>
    /// 图片框滑动方向
    /// </summary>
    [Description("图片框滑动方向")]
    public enum SlideType
    {
      /// <summary>
      /// 由右往左
      /// </summary>
      RightToLeft,/// <summary>
      /// 由左往右
      /// </summary>
      LeftToRight
    }

    /// <summary>
    /// 图片框
    /// </summary>
    [Description("图片框")]
    public class DisplayItem
    {
      /// <summary>
      /// 图片框运动前rectf
      /// </summary>
      [Description("图片框运动前rectf")]
      public RectangleF BeforeRectF { get; set; }

      /// <summary>
      /// 图片框目标rectf
      /// </summary>
      [Description("图片框目标rectf")]
      public RectangleF TargrtRectF { get; set; }

      /// <summary>
      /// 图片框当前rectf
      /// </summary>
      [Description("图片框当前rectf")]
      public RectangleF CurrentRectF { get; set; }

      /// <summary>
      /// 图片框对应transformImages中指定索引的Image
      /// </summary>
      [Description("图片框对应transformImages中指定索引的Image")]
      public int ImageIndex { get; set; }
    }

  }

?

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读