using Lskj.Control.Commom; using Lskj.Control.ImageLibrary; using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.Design; using System.Drawing; using System.Drawing.Design; using System.Drawing.Drawing2D; using System.Windows.Forms; namespace Lskj.Control { /// /// 图片旋转播放控件 /// [ToolboxItem(true)] [Description("图片旋转播放控件")] [DefaultProperty("Images")] [DefaultEvent("NavigationBarBtnClick")] [Designer(typeof(ImageWhirligigExtDesigner))] public class ImageWhirligigExt : System.Windows.Forms.Control { #region 新增事件 public delegate void ImageFrameEventHandler(object sender, ImageFrameIndexChangedEventArgs e); private event ImageFrameEventHandler imageFrameIndexChanged; /// /// 图片旋转播放选项索引更改事件 /// [Description("图片旋转播放选项索引更改事件")] public event ImageFrameEventHandler ImageFrameIndexChanged { add { this.imageFrameIndexChanged += value; } remove { this.imageFrameIndexChanged -= value; } } public delegate void NavigationBarBtnClickEventHandler(object sender, NavigationBarBtnClickEventArgs e); private event NavigationBarBtnClickEventHandler navigationBarBtnClick; /// /// 导航栏按钮单击事件 /// [Description("导航栏按钮单击事件")] public event NavigationBarBtnClickEventHandler NavigationBarBtnClick { add { this.navigationBarBtnClick += value; } remove { this.navigationBarBtnClick -= value; } } #endregion #region 停用事件 [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public new event EventHandler PaddingChanged { add { base.PaddingChanged += value; } remove { base.PaddingChanged -= value; } } [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public new event EventHandler TextChanged { add { base.TextChanged += value; } remove { base.TextChanged -= value; } } [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public new event EventHandler FontChanged { add { base.FontChanged += value; } remove { base.FontChanged -= value; } } [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public new event EventHandler ForeColorChanged { add { base.ForeColorChanged += value; } remove { base.ForeColorChanged -= value; } } [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public new event EventHandler RightToLeftChanged { add { base.RightToLeftChanged += value; } remove { base.RightToLeftChanged -= value; } } [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public new event EventHandler ImeModeChanged { add { base.ImeModeChanged += value; } remove { base.ImeModeChanged -= value; } } #endregion #region 新增属性 private Orientations orientation = Orientations.RightToLeft; /// ///图片旋转播放方向 /// [DefaultValue(Orientations.RightToLeft)] [Description("图片旋转播放方向")] public Orientations Orientation { get { return this.orientation; } set { if (this.orientation == value) return; this.orientation = value; this.current_orientation = this.orientation; this.InitializeImageFrameRectangle(); this.InitializeImageFrameIndex(); this.Invalidate(); } } private bool borderShow = false; /// ///是否显示边框 /// [DefaultValue(false)] [Description("是否显示边框")] public bool BorderShow { get { return this.borderShow; } set { if (this.borderShow == value) return; this.borderShow = value; this.Invalidate(); } } private Color borderColor = Color.FromArgb(192, 192, 192); /// /// 边框颜色 /// [DefaultValue(typeof(Color), "192, 192, 192")] [Description("边框颜色")] [Editor(typeof(ColorEditorExt), typeof(UITypeEditor))] public Color BorderColor { get { return this.borderColor; } set { if (this.borderColor == value) return; this.borderColor = value; this.Invalidate(); } } private Color activateColor = Color.Gray; /// /// 控件激活的虚线框颜色 /// [DefaultValue(typeof(Color), "Gray")] [Description("控件激活的虚线框颜色")] [Editor(typeof(ColorEditorExt), typeof(UITypeEditor))] public Color ActivateColor { get { return this.activateColor; } set { if (this.activateColor == value) return; this.activateColor = value; this.Invalidate(); } } private bool enterStop = false; /// /// 鼠标进入是是否停止自动切换 /// [DefaultValue(false)] [Description("鼠标进入是是否停止自动切换")] public bool EnterStop { get { return this.enterStop; } set { if (this.enterStop == value) return; this.enterStop = value; } } private bool imageAutoFree = true; /// /// 控件释放时是否自动释放倒影图片 /// [DefaultValue(true)] [Description("控件释放时是否自动释放倒影图片")] public bool ImageAutoFree { get { return this.imageAutoFree; } set { if (this.imageAutoFree == value) return; this.imageAutoFree = value; } } private double animationTime = 300d; /// /// 动画播放的总时间 /// [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; /// /// 图片播放的时间间隔 /// [DefaultValue(1000)] [Description("图片播放的时间间隔(默认1000毫秒)")] public int IntervalTime { get { return this.intervalTime; } set { if (this.intervalTime == value || value < 10) return; this.intervalTime = value; } } private int enableImageCurrentIndex = 0; /// ///已启用图片列表的当前显示区的开始图片的索引 /// [DefaultValue(0)] [Description("已启用图片列表的当前显示区的开始图片的索引")] public int EnableImageCurrentIndex { get { return this.enableImageCurrentIndex; } set { if (value < 0 || value >= this.enableImageList.Count) return; this.enableImageCurrentIndex = value; this.InitializeImageFrameIndex(); //跳过更新索引 this.Invalidate(); if (!this.DesignMode) { this.OnFrameIndexChanged(new ImageFrameIndexChangedEventArgs() { index = value, Item = this.Images[this.enableImageList[value]] }); } } } private ImageItemCollection imageItemCollection; /// /// 要播放的图片集合 /// [DefaultValue(null)] [Description("要播放的图片集合")] [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public ImageItemCollection Images { get { if (this.imageItemCollection == null) { this.imageItemCollection = new ImageItemCollection(this); } return this.imageItemCollection; } } #region 图片框 private int imageFrameCount = 5; /// /// 显示区要显示的图片框数量(必须为奇数,最小值3) /// [DefaultValue(5)] [Description("显示区要显示的图片框数量(必须为奇数,最小值3)")] public int ImageFrameCount { get { return this.imageFrameCount; } set { if (this.imageFrameCount == value || value < 2 || value % 2 != 1) return; this.imageFrameCount = value; this.LoadImageFrame(); this.InitializeDisplayRectangle(); this.InitializeImageFrameIndex(); this.Invalidate(); } } private float imageFrameShrink = 0.8f; /// ///图片框间缩小比例 /// [DefaultValue(0.8f)] [Description("图片框间缩小比例")] public float ImageFrameShrink { get { return this.imageFrameShrink; } set { if (this.imageFrameShrink == value) return; this.imageFrameShrink = value; this.InitializeDisplayRectangle(); this.Invalidate(); } } private int imageFrameInterval = 0; /// ///图片框间隔距离偏移量(为0时自动分配) /// [DefaultValue(0)] [Description("图片框间隔距离偏移量(为0时自动分配)")] public int ImageFrameInterval { get { return this.imageFrameInterval; } set { if (this.imageFrameInterval == value || value < 0) return; this.imageFrameInterval = value; this.InitializeDisplayRectangle(); this.Invalidate(); } } private int imageFrameWidth = 400; /// /// 中间图片框宽度 /// [DefaultValue(400)] [Description("中间图片框宽度(默认400)")] public int ImageFrameWidth { get { return this.imageFrameWidth; } set { if (this.imageFrameWidth == value || value < 1) return; this.imageFrameWidth = value; this.InitializeDisplayRectangle(); this.Invalidate(); } } private int imageFrameHeight = 200; /// /// 中间图片框高度 /// [DefaultValue(200)] [Description("中间图片框高度(默认200)")] public int ImageFrameHeight { get { return this.imageFrameHeight; } set { if (this.imageFrameHeight == value || value < 1) return; this.imageFrameHeight = value; this.InitializeDisplayRectangle(); this.Invalidate(); } } /// /// 中间图片框最终高度 /// [Browsable(false)] [Description("中间图片框最终高度")] public int ImageFrameFinallyHeight { get { return this.ReflectionShow ? this.ImageFrameHeight + this.reflectionTop + this.ReflectionHeight : this.ImageFrameHeight; } } #endregion #region 图片文本 private bool textShow = true; /// ///是否显示图片文字 /// [DefaultValue(true)] [Description("是否显示图片文字")] public bool TextShow { get { return this.textShow; } set { if (this.textShow == value) return; this.textShow = value; this.Invalidate(); } } private Color textBackColor = Color.Transparent; /// ///图片文字背景颜色 /// [DefaultValue(typeof(Color), "Transparent")] [Description("图片文字背景颜色")] [Editor(typeof(ColorEditorExt), typeof(UITypeEditor))] public Color TextBackColor { get { return this.textBackColor; } set { if (this.textBackColor == value) return; this.textBackColor = value; this.Invalidate(); } } private Color textForeColor = Color.FromArgb(100, 255, 99, 71); /// ///图片文字颜色 /// [DefaultValue(typeof(Color), "100, 255, 99, 71")] [Description("图片文字颜色")] [Editor(typeof(ColorEditorExt), typeof(UITypeEditor))] public Color TextForeColor { get { return this.textForeColor; } set { if (this.textForeColor == value) return; this.textForeColor = value; this.Invalidate(); } } private Font textFont = new Font("宋体", 18, FontStyle.Regular); /// /// 图片文字字体 /// [DefaultValue(typeof(Font), "宋体,18pt,style=Regular")] [Description("图片文字字体")] public Font TextFont { get { return this.textFont; } set { if (this.textFont == value) return; this.textFont = value; this.Invalidate(); } } #endregion #region 导航栏 private NavigationBarShowTypes navigationBarShowType = NavigationBarShowTypes.Normal; /// ///导航栏按钮显示类型 /// [DefaultValue(NavigationBarShowTypes.Normal)] [Description("导航栏按钮显示类型")] public NavigationBarShowTypes NavigationBarShowType { get { return this.navigationBarShowType; } set { if (this.navigationBarShowType == value) return; this.navigationBarShowType = value; if (this.navigationBarShowType != NavigationBarShowTypes.Normal && this.TabStop) { this.TabStop = false; } else { if (this.TabStop != true) { this.TabStop = true; } } this.navigationBar.IsShow = this.NavigationBarShowType == NavigationBarShowTypes.Normal ? true : false; this.Invalidate(); } } private int navigationBarBtnWidth = 30; /// /// 按钮宽度 /// [DefaultValue(30)] [Description("按钮宽度")] public int NavigationBarBtnWidth { get { return this.navigationBarBtnWidth; } set { if (this.navigationBarBtnWidth == value || value < 0) return; this.navigationBarBtnWidth = value; this.InitializeNavigationBarRectangle(); this.Invalidate(); } } private int navigationBarBtnHeight = 60; /// /// 按钮高度 /// [DefaultValue(60)] [Description("按钮高度")] public int NavigationBarBtnHeight { get { return this.navigationBarBtnHeight; } set { if (this.navigationBarBtnHeight == value || value < 0) return; this.navigationBarBtnHeight = value; this.InitializeNavigationBarRectangle(); this.Invalidate(); } } private int navigationBarBtnLineThickness = 2; /// /// 按钮线条厚度 /// [DefaultValue(2)] [Description("按钮高度")] public int NavigationBarBtnLineThickness { get { return this.navigationBarBtnLineThickness; } set { if (this.navigationBarBtnLineThickness == value || value < 0) return; this.navigationBarBtnLineThickness = value; this.InitializeNavigationBarRectangle(); this.Invalidate(); } } private Color navigationBarBtnNormalBackColor = Color.FromArgb(70, 128, 128, 128); /// ///导航栏按钮背景颜色(正常) /// [DefaultValue(typeof(Color), "70, 128, 128, 128")] [Description("导航栏按钮背景颜色(正常)")] [Editor(typeof(ColorEditorExt), typeof(UITypeEditor))] public Color NavigationBarBtnNormalBackColor { get { return this.navigationBarBtnNormalBackColor; } set { if (this.navigationBarBtnNormalBackColor == value) return; this.navigationBarBtnNormalBackColor = value; this.Invalidate(); } } private Color navigationBarBtnEnterBackColor = Color.FromArgb(70, 64, 64, 64); /// ///导航栏按钮背景颜色(鼠标进入) /// [DefaultValue(typeof(Color), "70, 64, 64, 64")] [Description("导航栏按钮背景颜色(正常)")] [Editor(typeof(ColorEditorExt), typeof(UITypeEditor))] public Color NavigationBarBtnEnterBackColor { get { return this.navigationBarBtnEnterBackColor; } set { if (this.navigationBarBtnEnterBackColor == value) return; this.navigationBarBtnEnterBackColor = value; this.Invalidate(); } } private Color navigationBarBtnNormalLineColor = Color.FromArgb(100, 255, 255, 255); /// ///导航栏按钮线条颜色(正常) /// [DefaultValue(typeof(Color), "100, 255, 255, 255")] [Description("导航栏按钮线条颜色(正常)")] [Editor(typeof(ColorEditorExt), typeof(UITypeEditor))] public Color NavigationBarBtnNormalLineColor { get { return this.navigationBarBtnNormalLineColor; } set { if (this.navigationBarBtnNormalLineColor == value) return; this.navigationBarBtnNormalLineColor = value; this.Invalidate(); } } private Color navigationBarBtnEnterLineColor = Color.FromArgb(100, 255, 255, 255); /// ///导航栏按钮线条颜色(鼠标进入) /// [DefaultValue(typeof(Color), "100, 255, 255, 255")] [Description("导航栏按钮线条颜色(鼠标进入)")] [Editor(typeof(ColorEditorExt), typeof(UITypeEditor))] public Color NavigationBarBtnEnterLineColor { get { return this.navigationBarBtnEnterLineColor; } set { if (this.navigationBarBtnEnterLineColor == value) return; this.navigationBarBtnEnterLineColor = value; this.Invalidate(); } } #endregion #region 倒影 private bool reflectionShow = false; /// /// 是否添加倒影 /// [DefaultValue(false)] [Description("是否添加倒影")] public bool ReflectionShow { get { return this.reflectionShow; } set { if (this.reflectionShow == value) return; this.reflectionShow = value; if (this.reflectionShow) { this.InitializeReflectionImages(false); } this.InitializeDisplayRectangle(); this.InitializeImageFrameIndex(); this.Invalidate(); } } private int reflectionHeight = 50; /// /// 倒影高度 /// [DefaultValue(50)] [Description("倒影高度")] public int ReflectionHeight { get { return this.reflectionHeight; } set { if (this.reflectionHeight == value || value < 0) return; this.reflectionHeight = value; if (this.ReflectionShow) { this.InitializeReflectionImages(true); } this.InitializeDisplayRectangle(); this.InitializeImageFrameIndex(); this.Invalidate(); } } #endregion #endregion #region 重写属性 [Browsable(false)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] protected new bool DesignMode { get { if (this.GetService(typeof(IDesignerHost)) != null || System.ComponentModel.LicenseManager.UsageMode == System.ComponentModel.LicenseUsageMode.Designtime) { return true;   //界面设计模式 } else { return false;//运行时模式 } } } protected override Size DefaultSize { get { return new Size(750, 280); ; } } protected override ImeMode DefaultImeMode { get { return System.Windows.Forms.ImeMode.Disable; } } #endregion #region 停用属性 [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public new Padding Padding { get { return base.Padding; } set { base.Padding = value; } } [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override string Text { get { return base.Text; } set { base.Text = value; } } [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override Font Font { get { return base.Font; } set { base.Font = value; } } [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override Color ForeColor { get { return base.ForeColor; } set { base.ForeColor = value; } } [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override RightToLeft RightToLeft { get { return base.RightToLeft; } set { base.RightToLeft = value; } } [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public new ImeMode ImeMode { get { return base.ImeMode; } set { base.ImeMode = value; } } #endregion #region 字段 /// /// 控件激活状态 /// private bool activatedState = false; /// /// 控件激活状态选项索引 /// private int activatedStateIndex = -1; /// /// 图片框集合 /// [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] private List imageFrameList = new List(); /// /// 已启用图片索引集合 /// [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] private List enableImageList = new List(); /// /// 图片框是否已切换到指定图片(图片数量大于图片框数量时使用) /// private bool isSwitchImage = false; /// /// 图片播放的时间间隔累计(-1为动画正在切换中) /// private int intervalTimeValue = 0; /// /// 动画间隔定时器 /// private Timer intervalTimer; /// /// 控件是否开始播放功能 /// private bool allowPlay = false; /// /// 动画播放定时器 /// private AnimationTimer animation; /// /// 当前滑动方向 /// private Orientations current_orientation = Orientations.RightToLeft; /// /// 图片显示区 /// private RectangleF display_rectf = RectangleF.Empty; /// /// 导航栏 /// private NavigationBar navigationBar = new NavigationBar() { pre_btn = new NavigationBarItem() { type = NavigationBarBtnTypes.Pre }, next_btn = new NavigationBarItem() { type = NavigationBarBtnTypes.Next } }; /// /// 倒影边距 /// private int reflectionTop = 10; /// /// 明亮度 /// private int reflectionBrightness = -50; /// /// 倒影开始透明度 /// private int reflectionTransparentStart = 200; /// /// 倒影结束透明度 /// private int reflectionTransparentEnd = -0; #endregion public ImageWhirligigExt() { SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); SetStyle(ControlStyles.OptimizedDoubleBuffer, true); SetStyle(ControlStyles.ResizeRedraw, true); SetStyle(ControlStyles.SupportsTransparentBackColor, true); this.navigationBar.IsShow = (this.NavigationBarShowType == NavigationBarShowTypes.Normal) ? true : false; this.LoadImageFrame(); this.LoadEnableImageIndex(); this.InitializeDisplayRectangle(); if (!this.DesignMode) { this.intervalTimer = new Timer(); this.intervalTimer.Interval = 50; this.intervalTimer.Tick += new EventHandler(this.intervalTimer_Tick); this.animation = new AnimationTimer(this, new AnimationOptions() { EveryNewTimer = false }); this.animation.Animationing += new AnimationTimer.AnimationEventHandler(this.animationTimer_Animationing); this.animation.AnimationEnding += new AnimationTimer.AnimationEventHandler(this.animationTimer_AnimationEnding); } } #region 重写 protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics g = e.Graphics; if (this.imageFrameList.Count < 1 || this.enableImageList.Count < 1) { goto border; } #region 绘制图片 //绘制顺序很重要 SolidBrush image_sb = new SolidBrush(Color.White); int center_index = this.imageFrameList.Count / 2; //非动画状态时中间图片框为最前端 if (this.intervalTimeValue != -1) { for (int i = 0; i < center_index; i++) { //左边 this.DrawFrameImage(g, image_sb, this.Images[this.GetEnableImageRealityIndex(this.imageFrameList[i].image_index)], this.imageFrameList[i].current_rectf); //右边 this.DrawFrameImage(g, image_sb, this.Images[this.GetEnableImageRealityIndex(this.imageFrameList[this.imageFrameList.Count - 1 - i].image_index)], this.imageFrameList[this.imageFrameList.Count - 1 - i].current_rectf); } this.DrawFrameImage(g, image_sb, this.Images[this.GetEnableImageRealityIndex(this.imageFrameList[center_index].image_index)], this.imageFrameList[center_index].current_rectf); } else { if (this.IsNegative(this.current_orientation))//负向方向滑动 { int right_index = center_index + 1; //左边 for (int i = 0; i < right_index; i++) { this.DrawFrameImage(g, image_sb, this.Images[this.GetEnableImageRealityIndex(this.imageFrameList[i].image_index)], this.imageFrameList[i].current_rectf); } //右边 for (int i = this.imageFrameList.Count - 1; i >= right_index; i--) { this.DrawFrameImage(g, image_sb, this.Images[this.GetEnableImageRealityIndex(this.imageFrameList[i].image_index)], this.imageFrameList[i].current_rectf); } //负向滑动时中间左边图片框为最前端 this.DrawFrameImage(g, image_sb, this.Images[this.GetEnableImageRealityIndex(this.imageFrameList[right_index].image_index)], this.imageFrameList[right_index].current_rectf); } else { int left_index = center_index - 1; //右边 for (int i = this.imageFrameList.Count - 1; i > left_index; i--) { this.DrawFrameImage(g, image_sb, this.Images[this.GetEnableImageRealityIndex(this.imageFrameList[i].image_index)], this.imageFrameList[i].current_rectf); } //左边 for (int i = 0; i < left_index; i++) { this.DrawFrameImage(g, image_sb, this.Images[this.GetEnableImageRealityIndex(this.imageFrameList[i].image_index)], this.imageFrameList[i].current_rectf); } //正向滑动时中间右边图片框为最前端 this.DrawFrameImage(g, image_sb, this.Images[this.GetEnableImageRealityIndex(this.imageFrameList[left_index].image_index)], this.imageFrameList[left_index].current_rectf); } } image_sb.Dispose(); #endregion #region 图片文本 if (this.TextShow) { int index = this.imageFrameList.Count / 2; string pre_text = this.Images[this.imageFrameList[this.imageFrameList.Count / 2].image_index].Text; string text = this.Images[this.GetEnableImageRealityIndex(this.imageFrameList[center_index].image_index)].Text; if (!String.IsNullOrWhiteSpace(text)) { StringFormat text_sf = new StringFormat() { Alignment = StringAlignment.Center }; SolidBrush text_back_sb = null; SolidBrush text_fore_sb = null; SizeF text_size = g.MeasureString(text, this.TextFont, new SizeF(), text_sf); RectangleF text_rectf = new RectangleF(this.display_rectf.X + (this.display_rectf.Width - text_size.Width) / 2f, this.display_rectf.Bottom, text_size.Width, text_size.Height); if (this.intervalTimeValue == -1) { float animation_progress = this.imageFrameList[center_index].animation_progress; if (animation_progress <= 0.25f) { int a = ControlCommom.VerifyRGB((int)(this.TextBackColor.A * (1 - animation_progress * 4))); text_back_sb = new SolidBrush(Color.FromArgb(a, this.TextBackColor)); text_fore_sb = new SolidBrush(Color.FromArgb(a, this.TextForeColor)); } else { int a = ControlCommom.VerifyRGB((int)(this.TextBackColor.A * ((animation_progress - 0.25) * 1.333333333333))); text_back_sb = new SolidBrush(Color.FromArgb(a, this.TextBackColor)); text_fore_sb = new SolidBrush(Color.FromArgb(a, this.TextForeColor)); } } else { text_back_sb = new SolidBrush(this.TextBackColor); text_fore_sb = new SolidBrush(this.TextForeColor); } g.FillRectangle(text_back_sb, text_rectf); g.DrawString(text, this.TextFont, text_fore_sb, text_rectf, text_sf); if (text_fore_sb != null) text_fore_sb.Dispose(); if (text_back_sb != null) text_back_sb.Dispose(); if (text_sf != null) text_sf.Dispose(); } } #endregion #region 导航栏 SolidBrush normal_barbtn_back_sb = null; Pen normal_barbtn_fore_pen = null; SolidBrush enter_barbtn_back_sb = null; Pen enter_barbtn_fore_pen = null; Pen active_barbtn_line_pen = (this.activatedStateIndex > -1 && this.activatedStateIndex < this.navigationBar.GetBtnCount()) ? new Pen(this.ActivateColor, 1) { DashStyle = DashStyle.Dash } : null; #region if (this.NavigationBarShowType == NavigationBarShowTypes.Normal || (this.NavigationBarShowType == NavigationBarShowTypes.Enter && this.navigationBar.IsShow)) { g.SmoothingMode = SmoothingMode.AntiAlias; #region 画笔 normal_barbtn_back_sb = new SolidBrush(this.NavigationBarBtnNormalBackColor); normal_barbtn_fore_pen = new Pen(this.NavigationBarBtnNormalLineColor, this.NavigationBarBtnLineThickness) { StartCap = LineCap.Round, EndCap = LineCap.Round }; if (this.navigationBar.pre_btn.status == NavigationBarBtnStatus.Enter || this.navigationBar.next_btn.status == NavigationBarBtnStatus.Enter) { enter_barbtn_back_sb = new SolidBrush(this.NavigationBarBtnEnterBackColor); enter_barbtn_fore_pen = new Pen(this.NavigationBarBtnEnterLineColor, this.NavigationBarBtnLineThickness) { StartCap = LineCap.Round, EndCap = LineCap.Round }; } #endregion #region 向前按钮 g.FillRectangle(this.navigationBar.pre_btn.status == NavigationBarBtnStatus.Enter ? enter_barbtn_back_sb : normal_barbtn_back_sb, this.navigationBar.pre_btn.btn_rectf); g.DrawLines(this.navigationBar.pre_btn.status == NavigationBarBtnStatus.Enter ? enter_barbtn_fore_pen : normal_barbtn_fore_pen, this.navigationBar.pre_btn.btn_line_rectf); if (this.activatedStateIndex == 0) { g.DrawRectangle(active_barbtn_line_pen, this.navigationBar.pre_btn.btn_rectf.X, this.navigationBar.pre_btn.btn_rectf.Y, this.navigationBar.pre_btn.btn_rectf.Width, this.navigationBar.pre_btn.btn_rectf.Height); } #endregion #region 向后按钮 g.FillRectangle(this.navigationBar.next_btn.status == NavigationBarBtnStatus.Enter ? enter_barbtn_back_sb : normal_barbtn_back_sb, this.navigationBar.next_btn.btn_rectf); g.DrawLines(this.navigationBar.next_btn.status == NavigationBarBtnStatus.Enter ? enter_barbtn_fore_pen : normal_barbtn_fore_pen, this.navigationBar.next_btn.btn_line_rectf); if (this.activatedStateIndex == 1) { g.DrawRectangle(active_barbtn_line_pen, this.navigationBar.next_btn.btn_rectf.X, this.navigationBar.next_btn.btn_rectf.Y, this.navigationBar.next_btn.btn_rectf.Width, this.navigationBar.next_btn.btn_rectf.Height); } #endregion } #endregion if (normal_barbtn_back_sb != null) normal_barbtn_back_sb.Dispose(); if (normal_barbtn_fore_pen != null) normal_barbtn_fore_pen.Dispose(); if (enter_barbtn_back_sb != null) enter_barbtn_back_sb.Dispose(); if (enter_barbtn_fore_pen != null) enter_barbtn_fore_pen.Dispose(); if (active_barbtn_line_pen != null) active_barbtn_line_pen.Dispose(); #endregion border: #region 边框 if (this.BorderShow) { Pen border_pen = new Pen(this.BorderColor, 1); g.DrawRectangle(border_pen, this.display_rectf.X, this.display_rectf.Y, this.display_rectf.Width - 1, this.display_rectf.Height - 1); if (border_pen != null) border_pen.Dispose(); } #endregion } protected override void OnEnter(EventArgs e) { base.OnEnter(e); if (this.DesignMode) return; this.activatedState = true; this.activatedStateIndex = 0; this.Invalidate(); } protected override void OnLeave(EventArgs e) { base.OnLeave(e); if (this.DesignMode) return; this.activatedState = false; this.activatedStateIndex = -1; this.Invalidate(); } protected override void OnGotFocus(EventArgs e) { base.OnGotFocus(e); if (this.DesignMode) return; this.activatedState = true; this.Invalidate(); } protected override void OnLostFocus(EventArgs e) { base.OnLostFocus(e); if (this.DesignMode) return; this.activatedState = false; this.Invalidate(); } protected override bool ProcessDialogKey(Keys keyData) { if (this.DesignMode) { return base.ProcessDialogKey(keyData); } if (this.activatedState) { #region Left if (keyData == Keys.Left) { if (this.NavigationBarShowType == NavigationBarShowTypes.Normal) { this.activatedStateIndex--; if (this.activatedStateIndex < 0) { this.activatedStateIndex = this.navigationBar.GetBtnCount() - 1; } this.Invalidate(); } return false; } #endregion #region Right else if (keyData == Keys.Right) { if (this.NavigationBarShowType == NavigationBarShowTypes.Normal) { this.activatedStateIndex++; if (this.activatedStateIndex > this.navigationBar.GetBtnCount() - 1) { this.activatedStateIndex = 0; } this.Invalidate(); } return false; } #endregion #region Enter、Space else if (keyData == Keys.Enter || keyData == Keys.Space) { if (this.enableImageList.Count > 0) { if (this.NavigationBarShowType == NavigationBarShowTypes.Normal && this.activatedStateIndex > -1 && this.activatedStateIndex < this.navigationBar.GetBtnCount()) { if (!this.DesignMode) { this.OnImageCarouseBarBtnClick(new NavigationBarBtnClickEventArgs() { index = this.EnableImageCurrentIndex, Btn = this.navigationBar.GetBtn(this.activatedStateIndex) }); } } } return false; } #endregion } return base.ProcessDialogKey(keyData); } protected override void OnTabStopChanged(EventArgs e) { base.OnTabStopChanged(e); if (this.DesignMode) return; if (this.navigationBarShowType != NavigationBarShowTypes.Normal && this.TabStop) { this.TabStop = false; } } protected override void OnEnabledChanged(EventArgs e) { base.OnEnabledChanged(e); if (this.DesignMode) return; if (!this.Enabled) { this.Stop(); } } protected override void OnMouseClick(MouseEventArgs e) { base.OnMouseClick(e); if (this.DesignMode) return; if (e.Button == System.Windows.Forms.MouseButtons.Left) { #region 导航栏 if (this.NavigationBarShowType != NavigationBarShowTypes.None && this.enableImageList.Count > 0) { Point point = this.PointToClient(System.Windows.Forms.Control.MousePosition); if (this.navigationBar.pre_btn.btn_rectf.Contains(point)) { this.OnImageCarouseBarBtnClick(new NavigationBarBtnClickEventArgs() { index = this.EnableImageCurrentIndex, Btn = this.navigationBar.pre_btn }); } else if (this.navigationBar.next_btn.btn_rectf.Contains(point)) { this.OnImageCarouseBarBtnClick(new NavigationBarBtnClickEventArgs() { index = this.EnableImageCurrentIndex, Btn = this.navigationBar.next_btn }); } } #endregion } } protected override void OnMouseEnter(EventArgs e) { base.OnMouseEnter(e); if (this.DesignMode) return; Point point = this.PointToClient(System.Windows.Forms.Control.MousePosition); bool isReset = false; #region 导航栏 if (this.NavigationBarShowType == NavigationBarShowTypes.Enter) { bool tmp = this.display_rectf.Contains(point) ? true : false; if (this.navigationBar.IsShow != tmp) { isReset = true; } this.navigationBar.IsShow = tmp; } #endregion #region 停止轮播定时器 if (this.EnterStop) { if (this.display_rectf.Contains(point)) { this.StopIntervalTimer(); } } #endregion if (isReset) { this.Invalidate(); } } protected override void OnMouseLeave(EventArgs e) { base.OnMouseLeave(e); if (this.DesignMode) return; Point point = this.PointToClient(System.Windows.Forms.Control.MousePosition); bool isReset = false; #region 导航栏 if (this.NavigationBarShowType == NavigationBarShowTypes.Enter) { bool tmp = this.display_rectf.Contains(point) ? true : false; if (this.navigationBar.IsShow != tmp) { isReset = true; } this.navigationBar.IsShow = tmp; } else if (this.NavigationBarShowType == NavigationBarShowTypes.Normal) { if (this.navigationBar.pre_btn.status != NavigationBarBtnStatus.Normal || this.navigationBar.next_btn.status != NavigationBarBtnStatus.Normal) { this.navigationBar.pre_btn.status = NavigationBarBtnStatus.Normal; this.navigationBar.next_btn.status = NavigationBarBtnStatus.Normal; isReset = true; } } #endregion #region 停止轮播定时器 if (this.allowPlay && this.EnterStop) { this.StartIntervalTimer(); } #endregion if (isReset) { this.Invalidate(); } } protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (this.DesignMode) return; Point point = this.PointToClient(System.Windows.Forms.Control.MousePosition); bool isReset = false; bool tmp = this.display_rectf.Contains(point) ? true : false; #region 导航栏 #region Enter if (this.NavigationBarShowType == NavigationBarShowTypes.Enter) { if (this.navigationBar.IsShow != tmp) { this.navigationBar.IsShow = tmp; isReset = true; } if (this.navigationBar.IsShow) { NavigationBarBtnStatus pre_status = this.navigationBar.pre_btn.btn_rectf.Contains(e.Location) ? NavigationBarBtnStatus.Enter : NavigationBarBtnStatus.Normal; if (this.navigationBar.pre_btn.status != pre_status) { this.navigationBar.pre_btn.status = pre_status; this.Cursor = Cursors.Hand; isReset = true; } NavigationBarBtnStatus next_status = this.navigationBar.next_btn.btn_rectf.Contains(e.Location) ? NavigationBarBtnStatus.Enter : NavigationBarBtnStatus.Normal; if (this.navigationBar.next_btn.status != next_status) { this.navigationBar.next_btn.status = next_status; this.Cursor = Cursors.Hand; isReset = true; } if (this.navigationBar.pre_btn.status != NavigationBarBtnStatus.Enter && this.navigationBar.next_btn.status != NavigationBarBtnStatus.Enter && this.Cursor != Cursors.Default) { this.Cursor = Cursors.Default; isReset = true; } } } #endregion #region Normal else if (this.NavigationBarShowType == NavigationBarShowTypes.Normal) { NavigationBarBtnStatus pre_status = this.navigationBar.pre_btn.btn_rectf.Contains(e.Location) ? NavigationBarBtnStatus.Enter : NavigationBarBtnStatus.Normal; if (this.navigationBar.pre_btn.status != pre_status) { this.navigationBar.pre_btn.status = pre_status; this.Cursor = Cursors.Hand; isReset = true; } NavigationBarBtnStatus next_status = this.navigationBar.next_btn.btn_rectf.Contains(e.Location) ? NavigationBarBtnStatus.Enter : NavigationBarBtnStatus.Normal; if (this.navigationBar.next_btn.status != next_status) { this.navigationBar.next_btn.status = next_status; this.Cursor = Cursors.Hand; isReset = true; } if (this.navigationBar.pre_btn.status != NavigationBarBtnStatus.Enter && this.navigationBar.next_btn.status != NavigationBarBtnStatus.Enter && this.Cursor != Cursors.Default) { this.Cursor = Cursors.Default; isReset = true; } } #endregion #endregion #region 开始停止轮播定时器 if (this.EnterStop) { if (this.display_rectf.Contains(e.Location)) { this.StopIntervalTimer(); } else { this.StartIntervalTimer(); } } #endregion if (isReset) { this.Invalidate(); } } protected override void OnResize(EventArgs e) { base.OnResize(e); this.InitializeDisplayRectangle(); } /// /// 清理所有正在使用的资源。 /// /// 如果应释放托管资源,为 true;否则为 false。 protected override void Dispose(bool disposing) { if (disposing) { if (this.animation != null) this.animation.Dispose(); if (this.intervalTimer != null) this.intervalTimer.Dispose(); if (this.ImageAutoFree) this.FreeReflectionImages(); } base.Dispose(disposing); } #endregion #region 虚方法 protected virtual void OnFrameIndexChanged(ImageFrameIndexChangedEventArgs e) { if (this.imageFrameIndexChanged != null) { this.imageFrameIndexChanged(this, e); } } protected virtual void OnImageCarouseBarBtnClick(NavigationBarBtnClickEventArgs e) { if (this.intervalTimeValue == -1)//动画进行中 return; this.intervalTimeValue = -1; this.isSwitchImage = false; #region 获取当前滑动方向 if (e.Btn.type == NavigationBarBtnTypes.Pre) { if (this.Orientation == Orientations.LeftToRight) { this.current_orientation = Orientations.RightToLeft; } } else { if (this.Orientation == Orientations.RightToLeft) { this.current_orientation = Orientations.LeftToRight; } } #endregion if (this.navigationBarBtnClick != null) { this.navigationBarBtnClick(this, e); } this.ResetImageFrameRectangle(); this.AutoUpdateImageEnableCurrentIndex(); this.AutoUpdateEveryImageFrameIndex(); this.animation.Options.Data = this.current_orientation; this.animation.AnimationType = AnimationTypes.EaseOut; this.animation.Options.AllTransformTime = this.AnimationTime; this.animation.Start(AnimationIntervalTypes.Add, 0); } #endregion #region 公共方法 /// /// 开始播放图片 /// public void Play() { if (!this.Enabled) return; this.StartIntervalTimer(); } /// /// 指定索引开始播放图片 /// /// public void Play(int index) { if (!this.Enabled) return; if (!this.allowPlay) { this.allowPlay = true; this.intervalTimer.Enabled = true; this.EnableImageCurrentIndex = index; } } /// /// 停止播放图片 /// public void Stop() { this.StopIntervalTimer(); } /// /// 获取图片显示区 /// /// public RectangleF GetDisplayRectangle() { return this.display_rectf; } /// /// 获取启用的图片列表中图片真实索引值 /// /// 在启用的图片列表中的索引 /// public int GetEnableImageRealityIndex(int index) { if (index < 0 || index >= this.enableImageList.Count) return -1; return this.enableImageList[index]; } /// /// 获取所有已启用的图片列表索引 /// public List GetEnableImagesIndex() { List resultList = new List(); this.enableImageList.ForEach(a => resultList.Add(a)); return resultList; } /// /// 初始化所有倒影(已启用图片集) /// /// 强制重新生成倒影图片 public void InitializeReflectionImages(bool reload) { if (this.ReflectionShow) { for (int i = 0; i < this.enableImageList.Count; i++) { this.InitializeReflectionImages(reload, this.enableImageList[i]); } } } /// /// 初始化指定倒影图片 /// /// 强制重新生成倒影图片 /// Images集合图片索引 public void InitializeReflectionImages(bool reload, int index) { if (!this.ReflectionShow || index < 0 || index >= this.Images.Count) return; if (index >= 0) { if (reload) { if (this.Images[index].ReflectionImage != null) { this.Images[index].ReflectionImage.Dispose(); } this.Images[index].ReflectionImage = this.TransformReflection((Bitmap)this.Images[index].Image); } else { if (this.Images[index].ReflectionImage == null) { this.Images[index].ReflectionImage = TransformReflection((Bitmap)this.Images[index].Image); } } } } #endregion #region 私有方法 /// /// 图片轮播的时间间隔事件 /// /// /// private void intervalTimer_Tick(object sender, EventArgs e) { if (this.enableImageList.Count < 1) return; if (this.intervalTimeValue == -1)//动画进行中 return; this.intervalTimeValue += this.intervalTimer.Interval; if (this.intervalTimeValue >= this.intervalTime) { this.intervalTimeValue = -1; this.isSwitchImage = false; this.RestoreOrientation(); this.AutoUpdateImageEnableCurrentIndex(); this.AutoUpdateEveryImageFrameIndex(); this.animation.Options.Data = this.current_orientation; this.animation.AnimationType = AnimationTypes.EaseOut; this.animation.Options.AllTransformTime = this.animationTime; this.animation.Start(AnimationIntervalTypes.Add, 0); } } /// /// 动画进行中事件 /// /// /// protected void animationTimer_Animationing(object sender, AnimationEventArgs e) { int center_index = this.imageFrameList.Count / 2; #region 计算图片框当前Rectangle for (int i = 0; i < this.imageFrameList.Count; i++) { float w = this.imageFrameList[i].before_rectf.Width + (this.imageFrameList[i].target_rectf.Width - this.imageFrameList[i].before_rectf.Width) * (float)e.ProgressValue; float h = this.imageFrameList[i].before_rectf.Height + (this.imageFrameList[i].target_rectf.Height - this.imageFrameList[i].before_rectf.Height) * (float)e.ProgressValue; float x = this.imageFrameList[i].before_rectf.X + (this.imageFrameList[i].target_rectf.X - this.imageFrameList[i].before_rectf.X) * (float)e.ProgressValue; float y = this.display_rectf.Y + (this.display_rectf.Height - h) / 2; this.imageFrameList[i].current_rectf = new RectangleF(x, y, w, h); } #endregion #region 第一个图片框和最后一个图片框的图片索引更新 if (this.Images.Count > this.imageFrameList.Count && !this.isSwitchImage)//当图片数量大于图片框数处理 { if (this.Orientation == Orientations.RightToLeft) { if (this.imageFrameList[0].current_rectf.X > (this.display_rectf.Width - this.ImageFrameWidth) / 2) { this.imageFrameList[0].image_index = this.ValidEnableImageIndex(this.imageFrameList[this.imageFrameList.Count - 1].image_index + 1); this.isSwitchImage = true; } } else { if (this.imageFrameList[this.imageFrameList.Count - 1].current_rectf.X < (this.display_rectf.Width - this.ImageFrameWidth) / 2 + this.display_rectf.Width / 2) { this.imageFrameList[this.imageFrameList.Count - 1].image_index = this.ValidEnableImageIndex(this.imageFrameList[0].image_index + 1); this.isSwitchImage = true; } } } #endregion #region 图片文本显示问题 if (this.Orientation == Orientations.RightToLeft) { center_index += 1; while (center_index >= this.imageFrameList.Count) { center_index -= this.imageFrameList.Count; } } else { center_index -= 1; while (center_index < 0) { center_index += this.imageFrameList.Count; } } this.imageFrameList[center_index].animation_progress = (float)e.AnimationUsedTime / (float)this.animation.Options.AllTransformTime; #endregion if (this.Enabled && this.Visible) { this.Invalidate(); } } /// /// 动画结束时事件 /// /// /// protected void animationTimer_AnimationEnding(object sender, AnimationEventArgs e) { this.RestoreOrientation(); this.ResetImageFrameRectangle(); this.InitializeImageFrameIndex(); this.intervalTimeValue = 0; this.Invalidate(); } /// /// 加载已启用图片索引集合 /// internal void LoadEnableImageIndex() { List old_enableImageList = this.enableImageList; List new_enableImageList = new List(); for (int i = 0; i < this.Images.Count; i++) { if (this.Images[i].Enable) { new_enableImageList.Add(i); } } this.enableImageList = new_enableImageList; old_enableImageList.Clear(); ; } /// /// 加载图片框集合 /// private void LoadImageFrame() { List old_imageFrameList = this.imageFrameList; List new_imageFrameList = new List(); for (int i = 0; i < this.ImageFrameCount; i++) { new_imageFrameList.Add(new ImageFrameItem()); } this.imageFrameList = new_imageFrameList; old_imageFrameList.Clear(); } /// /// 初始化播放显示区Rectangle /// /// public void InitializeDisplayRectangle() { RectangleF rectf = RectangleF.Empty; int excursion = (int)(this.ImageFrameInterval != 0 ? this.ImageFrameInterval : this.ImageFrameWidth * this.ImageFrameShrink / 4); int center_index = this.ImageFrameCount / 2; float width = ImageFrameWidth + (this.ImageFrameCount - (center_index + 1)) * excursion * 2; float x = this.ClientRectangle.X; float y = this.ClientRectangle.Y; if (this.ClientRectangle.Width != width) { x = (this.ClientRectangle.Width - width) / 2f; } if (this.ClientRectangle.Height != this.ImageFrameFinallyHeight) { y = (this.ClientRectangle.Height - this.ImageFrameFinallyHeight) / 2f; } rectf = new RectangleF(x, y, width, this.ImageFrameFinallyHeight); this.display_rectf = rectf; this.InitializeNavigationBarRectangle(); this.InitializeImageFrameRectangle(); } /// /// 初始化导航栏Rectangle /// private void InitializeNavigationBarRectangle() { if (this.NavigationBarShowType != NavigationBarShowTypes.None) { float barbtn_avg_w = this.NavigationBarBtnWidth / 4f; float barbtn_avg_h = this.NavigationBarBtnHeight / 6f; float padding = this.NavigationBarBtnWidth / 5f; #region 向上一页按钮 this.navigationBar.pre_btn.btn_rectf = new RectangleF(this.display_rectf.X + padding, this.display_rectf.Y + (this.display_rectf.Height - this.NavigationBarBtnHeight) / 2f, this.NavigationBarBtnWidth, this.NavigationBarBtnHeight); PointF[] pre_line_points = new PointF[3]; pre_line_points[0] = new PointF((this.navigationBar.pre_btn.btn_rectf.X + barbtn_avg_w * 3), (this.navigationBar.pre_btn.btn_rectf.Y + barbtn_avg_h)); pre_line_points[1] = new PointF((this.navigationBar.pre_btn.btn_rectf.X + barbtn_avg_w), (this.navigationBar.pre_btn.btn_rectf.Y + barbtn_avg_h * 3)); pre_line_points[2] = new PointF((this.navigationBar.pre_btn.btn_rectf.X + barbtn_avg_w * 3), (this.navigationBar.pre_btn.btn_rectf.Y + barbtn_avg_h * 5)); this.navigationBar.pre_btn.btn_line_rectf = pre_line_points; #endregion #region 向下一页按钮 this.navigationBar.next_btn.btn_rectf = new RectangleF(this.display_rectf.Right - this.NavigationBarBtnWidth - padding, this.display_rectf.Y + (this.display_rectf.Height - this.NavigationBarBtnHeight) / 2f, this.NavigationBarBtnWidth, this.NavigationBarBtnHeight); PointF[] next_line_points = new PointF[3]; next_line_points[0] = new PointF((this.navigationBar.next_btn.btn_rectf.Right - barbtn_avg_w * 3), (this.navigationBar.next_btn.btn_rectf.Y + barbtn_avg_h)); next_line_points[1] = new PointF((this.navigationBar.next_btn.btn_rectf.Right - barbtn_avg_w), (this.navigationBar.next_btn.btn_rectf.Y + barbtn_avg_h * 3)); next_line_points[2] = new PointF((this.navigationBar.next_btn.btn_rectf.Right - barbtn_avg_w * 3), (this.navigationBar.next_btn.btn_rectf.Y + barbtn_avg_h * 5)); this.navigationBar.next_btn.btn_line_rectf = next_line_points; #endregion } } /// /// 初始化所有图片框Rectangle /// private void InitializeImageFrameRectangle() { if (this.imageFrameList.Count < 1) return; int excursion = (int)(this.ImageFrameInterval != 0 ? this.ImageFrameInterval : this.ImageFrameWidth * this.ImageFrameShrink / 4); int center_index = this.imageFrameList.Count / 2; #region 图片框Rectangle //中间图片框 this.imageFrameList[center_index].before_rectf = new RectangleF(this.display_rectf.X + (this.display_rectf.Width - this.ImageFrameWidth) / 2, this.display_rectf.Y + (this.display_rectf.Height - this.ImageFrameFinallyHeight) / 2, this.ImageFrameWidth, this.ImageFrameFinallyHeight); this.imageFrameList[center_index].current_rectf = this.imageFrameList[center_index].before_rectf; for (int i = center_index + 1; i < this.imageFrameList.Count; i++) { float w = this.imageFrameList[i - 1].current_rectf.Width * this.ImageFrameShrink; float h = this.imageFrameList[i - 1].current_rectf.Height * this.ImageFrameShrink; float y = (this.display_rectf.Height - h) / 2; //右边图片框 float x_right = this.imageFrameList[i - 1].current_rectf.Right + excursion - w; this.imageFrameList[i].before_rectf = new RectangleF(x_right, this.display_rectf.Y + y, w, h); this.imageFrameList[i].current_rectf = this.imageFrameList[i].before_rectf; //左边图片框 float x_left = this.imageFrameList[this.imageFrameList.Count - 1 - i + 1].current_rectf.X - excursion; this.imageFrameList[this.imageFrameList.Count - 1 - i].before_rectf = new RectangleF(x_left, this.display_rectf.Y + y, w, h); this.imageFrameList[this.imageFrameList.Count - 1 - i].current_rectf = this.imageFrameList[this.imageFrameList.Count - 1 - i].before_rectf; } #endregion #region 默认Rectangle #region 负方向 for (int i = 0; i < this.imageFrameList.Count; i++) { this.imageFrameList[i].target_right_rectf = this.imageFrameList[this.ValidImageFrameIndex(i - 1)].before_rectf; } #endregion #region 正方向 for (int i = 0; i < this.imageFrameList.Count; i++) { this.imageFrameList[i].target_left_rectf = this.imageFrameList[this.ValidImageFrameIndex(i + 1)].before_rectf; } #endregion #endregion #region 目标Rectangle #region 负方向 if (this.IsNegative(this.current_orientation)) { this.imageFrameList[0].target_rectf = this.imageFrameList[this.imageFrameList.Count - 1].before_rectf; for (int i = this.imageFrameList.Count - 1; i > 0; i--) { this.imageFrameList[i].target_rectf = this.imageFrameList[i - 1].before_rectf; } } #endregion #region 正方向 else { this.imageFrameList[this.imageFrameList.Count - 1].target_rectf = this.imageFrameList[0].before_rectf; for (int i = 0; i < this.imageFrameList.Count - 1; i++) { this.imageFrameList[i].target_rectf = this.imageFrameList[i + 1].before_rectf; } } #endregion #endregion } /// /// 初始化每一个图片框的图片索引(用于ImageEnableCurrentIndex更改但不进行切换的情况) /// private void InitializeImageFrameIndex() { if (this.imageFrameList.Count < 1 || this.enableImageList.Count < 1) return; int center_index = this.imageFrameList.Count / 2; #region 负方向 if (this.IsNegative(this.current_orientation)) { this.imageFrameList[center_index].image_index = this.ValidEnableImageIndex(this.EnableImageCurrentIndex); for (int i = center_index + 1; i < this.imageFrameList.Count; i++) { this.imageFrameList[i].image_index = this.ValidEnableImageIndex(this.EnableImageCurrentIndex + (i - center_index));//增加指定偏移量 } for (int i = center_index - 1; i >= 0; i--) { this.imageFrameList[i].image_index = this.ValidEnableImageIndex(this.EnableImageCurrentIndex + (i - center_index));//增加指定偏移量 } } #endregion #region 正方向 else { this.imageFrameList[center_index].image_index = this.ValidEnableImageIndex(this.EnableImageCurrentIndex); for (int i = center_index - 1; i >= 0; i--) { this.imageFrameList[i].image_index = this.ValidEnableImageIndex(this.EnableImageCurrentIndex - (i - center_index));//增加指定偏移量 } for (int i = center_index + 1; i < this.imageFrameList.Count; i++) { this.imageFrameList[i].image_index = this.ValidEnableImageIndex(this.EnableImageCurrentIndex - (i - center_index));//增加指定偏移量 } } #endregion } /// /// 每一次播放前还原图片框的默认Rectangle设置 /// private void ResetImageFrameRectangle() { #region 负方向滑动 if (this.IsNegative(this.current_orientation)) { for (int i = 0; i < this.imageFrameList.Count; i++) { this.imageFrameList[i].target_rectf = this.imageFrameList[i].target_right_rectf; this.imageFrameList[i].current_rectf = this.imageFrameList[i].before_rectf; } } #endregion #region 正方向滑动 else { for (int i = 0; i < this.imageFrameList.Count; i++) { this.imageFrameList[i].target_rectf = this.imageFrameList[i].target_left_rectf; this.imageFrameList[i].current_rectf = this.imageFrameList[i].before_rectf; } } #endregion } /// /// 自动更新已启用图片列表的当前显示区的开始图片的索引(用于定时器和按钮切换时索引加减1) /// private void AutoUpdateImageEnableCurrentIndex() { #region 同向 if (!this.IsReverse(this.Orientation, this.current_orientation))//同向滑动后当前图片索引加1 { int display_index_tmp = this.ValidEnableImageIndex(this.EnableImageCurrentIndex + 1); this.enableImageCurrentIndex = display_index_tmp; if (!this.DesignMode) { this.OnFrameIndexChanged(new ImageFrameIndexChangedEventArgs() { index = display_index_tmp, Item = this.Images[this.enableImageList[display_index_tmp]] }); } } #endregion #region 反向 else//反向滑动后当前图片索引减1 { int display_index_tmp = this.ValidEnableImageIndex(this.EnableImageCurrentIndex - 1); this.enableImageCurrentIndex = display_index_tmp; if (!this.DesignMode) { this.OnFrameIndexChanged(new ImageFrameIndexChangedEventArgs() { index = display_index_tmp, Item = this.Images[this.enableImageList[display_index_tmp]] }); } } #endregion } /// /// 更新每一个图片框的图片索引(用于定时器和按钮切换时索引加减1,一般用于AutoUpdateImageEnableCurrentIndex方法之后) /// private void AutoUpdateEveryImageFrameIndex() { #region 图片索引 if (this.imageFrameList.Count < 1 || this.enableImageList.Count < 1) return; int center_index = this.imageFrameList.Count / 2; #region 负方向 if (this.IsNegative(this.current_orientation)) { #region 负方向的同向 if (!this.IsReverse(this.Orientation, this.current_orientation)) { center_index += 1; this.imageFrameList[center_index].image_index = this.ValidEnableImageIndex(this.EnableImageCurrentIndex); for (int i = center_index + 1; i < this.imageFrameList.Count; i++) { this.imageFrameList[i].image_index = this.ValidEnableImageIndex(this.EnableImageCurrentIndex + (i - center_index));//增加指定偏移量 } for (int i = center_index - 1; i >= 0; i--) { this.imageFrameList[i].image_index = this.ValidEnableImageIndex(this.EnableImageCurrentIndex + (i - center_index));//增加指定偏移量 } } #endregion #region 负方向的反向 else if (!this.IsReverse(this.Orientation, this.current_orientation)) { center_index -= 1; this.imageFrameList[center_index].image_index = this.ValidEnableImageIndex(this.EnableImageCurrentIndex); for (int i = center_index - 1; i >= 0; i--) { this.imageFrameList[i].image_index = this.ValidEnableImageIndex(this.EnableImageCurrentIndex - (i - center_index));//增加指定偏移量 } for (int i = center_index + 1; i < this.imageFrameList.Count; i++) { this.imageFrameList[i].image_index = this.ValidEnableImageIndex(this.EnableImageCurrentIndex - (i - center_index));//增加指定偏移量 } } #endregion } #endregion #region 正方向 else { #region 正方向的同向 if (!this.IsReverse(this.Orientation, this.current_orientation)) { center_index -= 1; this.imageFrameList[center_index].image_index = this.ValidEnableImageIndex(this.EnableImageCurrentIndex); for (int i = center_index - 1; i >= 0; i--) { this.imageFrameList[i].image_index = this.ValidEnableImageIndex(this.EnableImageCurrentIndex - (i - center_index));//增加指定偏移量 } for (int i = center_index + 1; i < this.imageFrameList.Count; i++) { this.imageFrameList[i].image_index = this.ValidEnableImageIndex(this.EnableImageCurrentIndex - (i - center_index));//增加指定偏移量 } } #endregion #region 正方向的反向 else if (!this.IsReverse(this.Orientation, this.current_orientation)) { center_index += 1; this.imageFrameList[center_index].image_index = this.ValidEnableImageIndex(this.EnableImageCurrentIndex); for (int i = center_index + 1; i < this.imageFrameList.Count; i++) { this.imageFrameList[i].image_index = this.ValidEnableImageIndex(this.EnableImageCurrentIndex + (i - center_index));//增加指定偏移量 } for (int i = center_index - 1; i >= 0; i--) { this.imageFrameList[i].image_index = this.ValidEnableImageIndex(this.EnableImageCurrentIndex + (i - center_index));//增加指定偏移量 } } #endregion } #endregion #endregion } /// ///获取验证后图片在已启用图片列表的索引 /// /// 已启用图片列表的索引 /// private int ValidEnableImageIndex(int index) { while (index > this.enableImageList.Count - 1) index -= this.enableImageList.Count; while (index < 0) index += this.enableImageList.Count; return index; } /// ///获取验证后图片框列表的索引 /// /// 图片框的索引 /// private int ValidImageFrameIndex(int index) { while (index > this.imageFrameList.Count - 1) index -= this.imageFrameList.Count; while (index < 0) index += this.imageFrameList.Count; return index; } /// /// 还原默认方向 /// private void RestoreOrientation() { if (this.Orientation != this.current_orientation) { this.current_orientation = this.Orientation; } } /// /// 是否负方向滑动(RightToLeft) /// /// /// private bool IsNegative(Orientations _orientation) { return (_orientation == Orientations.RightToLeft); } /// /// 是否正方向滑动(LeftToRight) /// /// /// private bool IsPositive(Orientations _orientation) { return (_orientation == Orientations.LeftToRight); } /// /// 是否和设置运动方向相反 /// /// /// /// private bool IsReverse(Orientations old_orientation, Orientations new_orientation) { bool _old = this.IsNegative(old_orientation); bool _new = this.IsNegative(new_orientation); if (_old != _new) return true; return false; } /// /// 开始动画间隔定时器 /// private void StartIntervalTimer() { if (!this.allowPlay) { this.allowPlay = true; this.intervalTimer.Enabled = true; this.intervalTimeValue = 0; } } /// /// 停止动画间隔定时器 /// private void StopIntervalTimer() { if (this.allowPlay) { this.allowPlay = false; this.intervalTimer.Enabled = false; this.intervalTimeValue = 0; } } /// /// 绘制图片 /// /// /// /// private void DrawFrameImage(Graphics g, SolidBrush imageSb, ImageItem imageCarousel, RectangleF rectf) { if (this.ReflectionShow) { if (imageCarousel.ReflectionImage != null) g.DrawImage(imageCarousel.ReflectionImage, rectf); else g.FillRectangle(imageSb, rectf); } else { if (imageCarousel.Image != null) g.DrawImage(imageCarousel.Image, rectf); else g.FillRectangle(imageSb, rectf); } } /// /// 倒影变换 /// /// /// 透明度(0-255) private Bitmap TransformReflection(Bitmap bmp) { if (bmp == null) return null; return ControlCommom.TransformReflection(bmp, this.reflectionTop, this.reflectionBrightness, reflectionTransparentStart, reflectionTransparentEnd, this.ReflectionHeight); } /// /// 释放所有倒影图片 /// [EditorBrowsable(EditorBrowsableState.Never)] internal void FreeReflectionImages() { if (this.Images != null) { for (int i = 0; i < this.Images.Count; i++) { this.Images[i].ReflectionImage.Dispose(); this.Images[i].ReflectionImage = null; } this.Images.Clear(); } } /// /// 释放指定索引倒影图片 /// [EditorBrowsable(EditorBrowsableState.Never)] internal void FreeReflectionImage(int index) { if (this.Images != null && index >= 0 && index < this.Images.Count) { this.Images[index].ReflectionImage.Dispose(); this.Images[index].ReflectionImage = null; this.Images.RemoveAt(index); } } #endregion #region 类 /// /// 图片选项集合 /// [Description("图片选项集合")] [Editor(typeof(CollectionEditorExt), typeof(UITypeEditor))] public sealed class ImageItemCollection : IList, ICollection, IEnumerable { private ArrayList imageItemList = new ArrayList(); private ImageWhirligigExt owner; public ImageItemCollection(ImageWhirligigExt owner) { this.owner = owner; } #region IEnumerable public IEnumerator GetEnumerator() { ImageItem[] listArray = new ImageItem[this.imageItemList.Count]; for (int index = 0; index < listArray.Length; ++index) { listArray[index] = (ImageItem)this.imageItemList[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.imageItemList[i], i + index); } } public int Count { get { return this.imageItemList.Count; } } public bool IsSynchronized { get { return false; } } public object SyncRoot { get { return (object)this; } } #endregion #region IList public int Add(object value) { if (!(value is ImageItem)) { throw new ArgumentException("ImageItem"); } return this.Add((ImageItem)value); } public int Add(ImageItem item) { if (item == null) { throw new ArgumentNullException("item"); } this.imageItemList.Add(item); item.owner = owner; if (item.Enable) { this.owner.LoadEnableImageIndex(); } if (this.owner.ReflectionShow) { this.owner.InitializeReflectionImages(true, this.Count - 1); } this.owner.InitializeImageFrameIndex(); this.owner.Invalidate(); return this.Count - 1; } public void Clear() { if (this.owner.ImageAutoFree) { for (int i = 0; i < this.imageItemList.Count; i++) { ImageItem item = (ImageItem)this.imageItemList[i]; if (item.ReflectionImage != null) { item.ReflectionImage.Dispose(); item.ReflectionImage = null; } } } this.imageItemList.Clear(); this.owner.LoadEnableImageIndex(); this.owner.Invalidate(); } public bool Contains(object value) { if (value == null) throw new ArgumentNullException("value"); return this.IndexOf(value) != -1; } bool IList.Contains(object item) { if (item is ImageItem) { return this.Contains((ImageItem)item); } return false; } public int IndexOf(object item) { if (item is ImageItem) { return this.imageItemList.IndexOf(item); } return -1; } 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) { if (!(value is ImageItem)) { throw new ArgumentException("ImageItem"); } this.Remove((ImageItem)value); } public void Remove(ImageItem item) { if (this.owner.ImageAutoFree) { if (item.ReflectionImage != null) { item.ReflectionImage.Dispose(); item.ReflectionImage = null; } } this.imageItemList.Remove(item); this.owner.LoadEnableImageIndex(); this.owner.Invalidate(); } public void RemoveAt(int index) { ImageItem item = (ImageItem)this.imageItemList[index]; if (this.owner.ImageAutoFree) { if (item.ReflectionImage != null) { item.ReflectionImage.Dispose(); item.ReflectionImage = null; } } this.imageItemList.RemoveAt(index); this.owner.LoadEnableImageIndex(); this.owner.Invalidate(); } public ImageItem this[int index] { get { return (ImageItem)this.imageItemList[index]; } set { ImageItem item = (ImageItem)this.imageItemList[index]; if (item.ReflectionImage != null) { item.ReflectionImage.Dispose(); item.ReflectionImage = null; } this.imageItemList[index] = (ImageItem)value; } } object IList.this[int index] { get { return (object)this.imageItemList[index]; } set { ImageItem item = (ImageItem)this.imageItemList[index]; if (item.ReflectionImage != null) { item.ReflectionImage.Dispose(); item.ReflectionImage = null; } this.imageItemList[index] = (ImageItem)value; } } #endregion } /// /// 图片选项 /// [Description("图片选项")] public class ImageItem { internal ImageWhirligigExt owner; private Image image = null; /// /// 图片 /// [DefaultValue(null)] [Description("图片")] public Image Image { get { return this.image; } set { if (this.image == value) return; this.image = value; if (this.owner != null && this.owner.ReflectionShow) { this.owner.InitializeReflectionImages(true, this.owner.Images.IndexOf(this)); } } } private string text = null; /// /// 图片文本 /// [Description("图片文本")] public string Text { get { return this.text; } set { if (this.text == value) return; this.text = value; } } private Image reflectionImage = null; /// /// 倒影图片 /// [Browsable(false)] [DefaultValue(null)] [EditorBrowsable(EditorBrowsableState.Never)] [Description("倒影图片")] public Image ReflectionImage { get { return this.reflectionImage; } set { if (this.reflectionImage == value) return; this.reflectionImage = value; } } private bool enable = true; /// /// 是否启用 /// [DefaultValue(true)] [Description("是否启用")] public bool Enable { get { return this.enable; } set { if (this.enable == value) return; this.enable = value; if (this.owner != null) { this.owner.LoadEnableImageIndex(); } } } } /// /// 图片旋转播放选项 /// [Description("图片旋转播放选项")] public class ImageFrameItem { /// /// 向左滑动时默认目标rectf /// [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] [Description("向左滑动时默认目标rectf")] public RectangleF target_left_rectf { get; set; } /// /// 向右滑动时默认目标rectf /// [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] [Description("向右滑动时默认目标rectf")] public RectangleF target_right_rectf { get; set; } /// /// 运动前rectf /// [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] [Description("框运动前rectf")] public RectangleF before_rectf { get; set; } /// /// 目标rectf /// [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] [Description("框目标rectf")] public RectangleF target_rectf { get; set; } /// /// 当前rectf /// [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] [Description("框当前rectf")] public RectangleF current_rectf { get; set; } /// /// 已启用显示属性的图片列表的索引值 /// [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] [Description("已启用显示属性的图片列表的索引值")] public int image_index { get; set; } /// /// 动画进度(0-1) /// [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] [Description("动画进度(0-1)")] public float animation_progress { get; set; } } /// /// 导航栏 /// [Description("导航栏")] public class NavigationBar { /// /// 向前按钮 /// [Browsable(false)] [Description("向前按钮")] public NavigationBarItem pre_btn { get; set; } /// /// 向后按钮 /// [Browsable(false)] [Description("向后按钮")] public NavigationBarItem next_btn { get; set; } /// /// 导航栏显示状态 /// [Browsable(false)] [Description("导航栏显示状态")] public bool IsShow { get; set; } /// /// 获取导航栏按钮数量 /// /// public int GetBtnCount() { return 2; } /// /// 根据索引获取按钮对象 /// /// /// public NavigationBarItem GetBtn(int index) { if (index == 1) return pre_btn; else return next_btn; } } /// /// 导航栏选项 /// [Description("导航栏选项")] public class NavigationBarItem { /// /// 按钮rectf /// [Browsable(false)] [Description("按钮rectf")] public RectangleF btn_rectf { get; set; } /// /// 按钮线条rectf /// [Browsable(false)] [Description("按钮线条rectf")] public PointF[] btn_line_rectf { get; set; } /// /// 按钮状态 /// [Browsable(false)] [DefaultValue(NavigationBarBtnStatus.Normal)] [Description("按钮状态")] public NavigationBarBtnStatus status { get; set; } /// /// 导航栏按钮类型 /// [Browsable(false)] [Description("导航栏按钮类型")] public NavigationBarBtnTypes type { get; set; } } /// /// 图片轮播选项索引更改事件参数 /// [Description("图片轮播选项索引更改事件参数")] public class ImageFrameIndexChangedEventArgs : EventArgs { /// /// 图片选项在已启动图片列表的索引 /// [Description("图片选项在已启动图片列表的索引")] public int index { get; set; } /// /// 图片选项 /// [Description("图片选项")] public ImageItem Item { get; set; } } /// /// 导航栏按钮单击事件参数 /// [Description("导航栏按钮单击事件参数")] public class NavigationBarBtnClickEventArgs : EventArgs { /// /// 图片选项在已启动图片列表的索引 /// [Description("图片选项在已启动图片列表的索引")] public int index { get; set; } /// /// 导航栏按钮 /// [Description("导航栏按钮")] public NavigationBarItem Btn { get; set; } } #endregion #region 枚举 /// /// 图片旋转播放方向 /// [Description("图片旋转播放方向")] public enum Orientations { /// /// 由右往左 /// RightToLeft, /// /// 由左往右 /// LeftToRight } /// /// 导航栏按钮显示类型 /// [Description("导航栏按钮状态")] public enum NavigationBarShowTypes { /// /// 不显示 /// None, /// /// 一直显示 /// Normal, /// /// 鼠标进入才显示 /// Enter } /// /// 导航栏按钮状态 /// [Description("导航栏按钮状态")] public enum NavigationBarBtnStatus { /// /// 正常 /// Normal, /// /// 鼠标进入 /// Enter } /// /// 导航栏按钮类型 /// [Description("导航栏按钮类型")] public enum NavigationBarBtnTypes { /// /// 向前按钮 /// Pre, /// /// 向后按钮 /// Next } #endregion } }