|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using HuizhongLibrary.Log;
|
|
|
|
|
using HuizhongLibrary;
|
|
|
|
|
|
|
|
|
|
namespace HuizhongLibrary.MyAlphaControl
|
|
|
|
|
{
|
|
|
|
|
public partial class MyPanel : UserControl
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
private Bitmap m_BackgroundImage;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 背景图片
|
|
|
|
|
/// </summary>
|
|
|
|
|
public new Bitmap BackgroundImage
|
|
|
|
|
{
|
|
|
|
|
get { return m_BackgroundImage; }
|
|
|
|
|
set{ m_BackgroundImage = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private PictureBoxSizeMode m_BackgroundSizeMode = PictureBoxSizeMode.Normal;
|
|
|
|
|
|
|
|
|
|
public PictureBoxSizeMode BackgroundSizeMode
|
|
|
|
|
{
|
|
|
|
|
get { return m_BackgroundSizeMode; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
m_BackgroundSizeMode = value;
|
|
|
|
|
pictureBox1.SizeMode = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<MyImageList> m_ImageArray = new List<MyImageList>();
|
|
|
|
|
|
|
|
|
|
public List<MyImageList> ImageArray
|
|
|
|
|
{
|
|
|
|
|
get { return m_ImageArray; }
|
|
|
|
|
set { m_ImageArray = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private string m_ImageList = "";
|
|
|
|
|
|
|
|
|
|
public string ImageList
|
|
|
|
|
{
|
|
|
|
|
get { return m_ImageList; }
|
|
|
|
|
set { m_ImageList = value; }
|
|
|
|
|
}
|
|
|
|
|
private bool m_Visible = true;
|
|
|
|
|
|
|
|
|
|
public new bool Visible
|
|
|
|
|
{
|
|
|
|
|
get { return m_Visible; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
m_Visible = value;
|
|
|
|
|
base.Visible = value;
|
|
|
|
|
int index = 0;
|
|
|
|
|
//if (pictureBox1.Image == null && this.BackgroundImage != null) RefshImage();
|
|
|
|
|
pictureBox1.BringToFront();
|
|
|
|
|
foreach (System.Windows.Forms.Control ctrl in this.Controls)
|
|
|
|
|
{
|
|
|
|
|
index++;
|
|
|
|
|
if (index == 1) continue;
|
|
|
|
|
if (ctrl.Visible == true) ctrl.BringToFront();
|
|
|
|
|
}
|
|
|
|
|
//pictureBox1.SendToBack();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsRun = true;
|
|
|
|
|
public int MainTop = 0;
|
|
|
|
|
public int MainLeft = 0;
|
|
|
|
|
public int MainWidth = 0;
|
|
|
|
|
public int MainHeight = 0;
|
|
|
|
|
public int MaxWidth = 0;
|
|
|
|
|
public int MaxHeight = 0;
|
|
|
|
|
public int FlackMode = 0; //0全屏宣教1首页宣教
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public event EventHandler FeelImage;
|
|
|
|
|
public event RemoveImageDelegate RemoveImage;
|
|
|
|
|
public delegate void RemoveImageDelegate(string ImageListName, string ImgName);
|
|
|
|
|
public event Action<string> RemoveScrollString;
|
|
|
|
|
|
|
|
|
|
public MyPanel()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
pictureBox1.Click += pictureBox1_Click;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void pictureBox1_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (this.FeelImage != null) this.FeelImage(sender, e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int ImageIndex= 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 切换到上一页
|
|
|
|
|
public int PrevImage()
|
|
|
|
|
{
|
|
|
|
|
if (ImageArray.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
this.BackgroundImage = null;
|
|
|
|
|
return 10;
|
|
|
|
|
}
|
|
|
|
|
ImageIndex--;
|
|
|
|
|
if (ImageIndex < 0) ImageIndex = ImageArray.Count - 1;
|
|
|
|
|
MyImageList model = CheckOut(ImageIndex);
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
ImageIndex++;
|
|
|
|
|
return PrevImage();
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
DateTime dt = DateTime.Now;
|
|
|
|
|
if (File.Exists(model.FilePath) == false || (model.EndTime != null && dt > model.EndTime))
|
|
|
|
|
{
|
|
|
|
|
if (this.RemoveImage != null) this.RemoveImage(this.ImageList, model.Name);
|
|
|
|
|
RemoveAt(ImageIndex);
|
|
|
|
|
ImageIndex++;
|
|
|
|
|
return PrevImage();
|
|
|
|
|
}
|
|
|
|
|
this.BackgroundImage = CustomIO.GetBitmap(model.FilePath);
|
|
|
|
|
if (this.BackgroundImage == null)
|
|
|
|
|
{
|
|
|
|
|
if (this.RemoveImage != null) this.RemoveImage(this.ImageList, model.Name);
|
|
|
|
|
RemoveAt(ImageIndex);
|
|
|
|
|
ImageIndex++;
|
|
|
|
|
return PrevImage();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ErrorFollow.TraceWrite("NextImage", ex.StackTrace, ex.Message);
|
|
|
|
|
if (this.RemoveImage != null) this.RemoveImage(this.ImageList, model.Name);
|
|
|
|
|
RemoveAt(ImageIndex);
|
|
|
|
|
ImageIndex++;
|
|
|
|
|
return PrevImage();
|
|
|
|
|
}
|
|
|
|
|
return model.Interval;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
#region 切换到下一页
|
|
|
|
|
public int NextImage()
|
|
|
|
|
{
|
|
|
|
|
if (ImageArray.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
this.BackgroundImage = null;
|
|
|
|
|
return 10;
|
|
|
|
|
}
|
|
|
|
|
ImageIndex++;
|
|
|
|
|
if (ImageIndex >= ImageArray.Count) ImageIndex = 0;
|
|
|
|
|
MyImageList model = CheckOut(ImageIndex);
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
ImageIndex--;
|
|
|
|
|
return NextImage();
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
DateTime dt = DateTime.Now;
|
|
|
|
|
if (File.Exists(model.FilePath) == false || (model.EndTime != null && dt > model.EndTime))
|
|
|
|
|
{
|
|
|
|
|
if (this.RemoveImage != null) this.RemoveImage(this.ImageList, model.Name);
|
|
|
|
|
RemoveAt(ImageIndex);
|
|
|
|
|
ImageIndex--;
|
|
|
|
|
return NextImage();
|
|
|
|
|
}
|
|
|
|
|
this.BackgroundImage = CustomIO.GetBitmap(model.FilePath);
|
|
|
|
|
if (this.BackgroundImage == null)
|
|
|
|
|
{
|
|
|
|
|
if (this.RemoveImage != null) this.RemoveImage(this.ImageList, model.Name);
|
|
|
|
|
RemoveAt(ImageIndex);
|
|
|
|
|
ImageIndex--;
|
|
|
|
|
return NextImage();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ErrorFollow.TraceWrite("NextImage", ex.StackTrace, ex.Message);
|
|
|
|
|
if (this.RemoveImage != null) this.RemoveImage(this.ImageList, model.Name);
|
|
|
|
|
RemoveAt(ImageIndex);
|
|
|
|
|
ImageIndex--;
|
|
|
|
|
return NextImage();
|
|
|
|
|
}
|
|
|
|
|
return model.Interval;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
#region 刷新背景
|
|
|
|
|
public void RefshImage()
|
|
|
|
|
{
|
|
|
|
|
if (pictureBox1.Image != null) pictureBox1.Image.Dispose();
|
|
|
|
|
pictureBox1.Image = this.BackgroundImage;
|
|
|
|
|
GC.Collect();
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
#region 新增图片
|
|
|
|
|
public void CheckIn(MyImageList item)
|
|
|
|
|
{
|
|
|
|
|
lock (ImageArray)
|
|
|
|
|
{
|
|
|
|
|
MyImageList Citem = null;
|
|
|
|
|
foreach (MyImageList item2 in ImageArray)
|
|
|
|
|
{
|
|
|
|
|
if (item2.Name == item.Name) Citem = item2;
|
|
|
|
|
}
|
|
|
|
|
if (Citem == null) { ImageArray.Add(item); }
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Citem.EndTime = item.EndTime;
|
|
|
|
|
Citem.FilePath = item.FilePath;
|
|
|
|
|
Citem.Interval = item.Interval;
|
|
|
|
|
Citem.Name = item.Name;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (ImageArray.Count == 1)
|
|
|
|
|
{
|
|
|
|
|
FirstImage();
|
|
|
|
|
RefshImage();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
#region 读取图片
|
|
|
|
|
public MyImageList CheckOut(int Index)
|
|
|
|
|
{
|
|
|
|
|
MyImageList model = null;
|
|
|
|
|
lock (ImageArray)
|
|
|
|
|
{
|
|
|
|
|
if (ImageArray.Count == 0) return null;
|
|
|
|
|
if (Index < 0 || Index > ImageArray.Count - 1)
|
|
|
|
|
{
|
|
|
|
|
Index = 0;
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
model=ImageArray[Index];
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
|
|
|
|
return model;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
#region 清除全部图片
|
|
|
|
|
public void Clear()
|
|
|
|
|
{
|
|
|
|
|
lock (ImageArray)
|
|
|
|
|
{
|
|
|
|
|
ImageArray.Clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
#region 清除图片
|
|
|
|
|
public void RemoveAt(int Index)
|
|
|
|
|
{
|
|
|
|
|
lock (ImageArray)
|
|
|
|
|
{
|
|
|
|
|
if (ImageArray.Count == 0) return;
|
|
|
|
|
if (Index < 0 || Index > ImageArray.Count - 1) return;
|
|
|
|
|
ImageArray.RemoveAt(Index);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
#region 清除图片
|
|
|
|
|
public void Remove(string Name)
|
|
|
|
|
{
|
|
|
|
|
lock (ImageArray)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < ImageArray.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (ImageArray[i].Name != Name) continue;
|
|
|
|
|
ImageArray.RemoveAt(i);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
NextImage();
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
#region 切换到首张图片
|
|
|
|
|
public void FirstImage()
|
|
|
|
|
{
|
|
|
|
|
ImageIndex = 0;
|
|
|
|
|
MyImageList model = CheckOut(ImageIndex);
|
|
|
|
|
if (model == null) { this.BackgroundImage = null; }
|
|
|
|
|
else { this.BackgroundImage = CustomIO.GetBitmap(model.FilePath); }
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
#region 切换到最后一张图片
|
|
|
|
|
public void LastImage()
|
|
|
|
|
{
|
|
|
|
|
ImageIndex = ImageArray.Count-1;
|
|
|
|
|
MyImageList model = CheckOut(ImageIndex);
|
|
|
|
|
if (model == null) { this.BackgroundImage = null; }
|
|
|
|
|
else { this.BackgroundImage = CustomIO.GetBitmap(model.FilePath); }
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 缩放
|
|
|
|
|
public void Zoom()
|
|
|
|
|
{
|
|
|
|
|
if (FlackMode == 0 || ImageArray.Count == 0) return;
|
|
|
|
|
if (this.Width == MaxWidth)
|
|
|
|
|
{
|
|
|
|
|
this.Left = MainLeft;
|
|
|
|
|
this.Top = MainTop;
|
|
|
|
|
this.Width = MainWidth;
|
|
|
|
|
this.Height = MainHeight;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this.Left = 0;
|
|
|
|
|
this.Top = 0;
|
|
|
|
|
this.Width = MaxWidth;
|
|
|
|
|
this.Height = MaxHeight;
|
|
|
|
|
}
|
|
|
|
|
RefshImage();
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 计算文字大小
|
|
|
|
|
private SizeF MeasureString(string Text, Font font)
|
|
|
|
|
{
|
|
|
|
|
Bitmap bmp = new Bitmap(1, 1, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
|
|
|
|
|
Graphics g = Graphics.FromImage(bmp);
|
|
|
|
|
SizeF s = g.MeasureString(Text, font);
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 是否有需要播报的消息
|
|
|
|
|
public bool IsPlay()
|
|
|
|
|
{
|
|
|
|
|
if (this.IsRun == false) return false;
|
|
|
|
|
if (ImageArray.Count > 0) return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 引发移除滚动文本事件
|
|
|
|
|
public void OnRemoveScrollString(string Name)
|
|
|
|
|
{
|
|
|
|
|
if (this.RemoveScrollString != null) this.RemoveScrollString(Name);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|