diff --git a/Bin/net40/SunnyUI.Demo.exe b/Bin/net40/SunnyUI.Demo.exe index 83d46240..bc9a2053 100644 Binary files a/Bin/net40/SunnyUI.Demo.exe and b/Bin/net40/SunnyUI.Demo.exe differ diff --git a/Bin/net40/SunnyUI.dll b/Bin/net40/SunnyUI.dll index 9845d7bf..997662e7 100644 Binary files a/Bin/net40/SunnyUI.dll and b/Bin/net40/SunnyUI.dll differ diff --git a/Bin/net45/SunnyUI.dll b/Bin/net45/SunnyUI.dll index cd163a16..283b16f1 100644 Binary files a/Bin/net45/SunnyUI.dll and b/Bin/net45/SunnyUI.dll differ diff --git a/Bin/net5.0-windows/SunnyUI.dll b/Bin/net5.0-windows/SunnyUI.dll index c7bae118..c74d0bc7 100644 Binary files a/Bin/net5.0-windows/SunnyUI.dll and b/Bin/net5.0-windows/SunnyUI.dll differ diff --git a/Bin/net5.0-windows/ref/SunnyUI.dll b/Bin/net5.0-windows/ref/SunnyUI.dll index 2b451949..bc7b5550 100644 Binary files a/Bin/net5.0-windows/ref/SunnyUI.dll and b/Bin/net5.0-windows/ref/SunnyUI.dll differ diff --git a/Bin/netcoreapp3.1/SunnyUI.dll b/Bin/netcoreapp3.1/SunnyUI.dll index 007674bb..04a8f766 100644 Binary files a/Bin/netcoreapp3.1/SunnyUI.dll and b/Bin/netcoreapp3.1/SunnyUI.dll differ diff --git a/SunnyUI/Controls/UIScrollingText.cs b/SunnyUI/Controls/UIScrollingText.cs index 726c0174..64120213 100644 --- a/SunnyUI/Controls/UIScrollingText.cs +++ b/SunnyUI/Controls/UIScrollingText.cs @@ -34,7 +34,7 @@ namespace Sunny.UI private int XPos = int.MinValue; private int XPos1 = int.MaxValue; private int interval = 200; - private int TextWidth = Int32.MinValue; + private int TextWidth = int.MinValue; public UIScrollingText() { @@ -104,7 +104,7 @@ namespace Sunny.UI private void Timer_Tick(object sender, EventArgs e) { - if (XPos == Int32.MinValue) + if (XPos == int.MinValue) { Invalidate(); } diff --git a/SunnyUI/Pages/UITitlePage.Designer.cs b/SunnyUI/Pages/UITitlePage.Designer.cs index 049af86e..5a0fa517 100644 --- a/SunnyUI/Pages/UITitlePage.Designer.cs +++ b/SunnyUI/Pages/UITitlePage.Designer.cs @@ -42,7 +42,7 @@ this.PageTitle.Padding = new System.Windows.Forms.Padding(6, 0, 0, 0); this.PageTitle.RadiusSides = Sunny.UI.UICornerRadiusSides.None; this.PageTitle.RectSides = System.Windows.Forms.ToolStripStatusLabelBorderSides.None; - this.PageTitle.Size = new System.Drawing.Size(913, 35); + this.PageTitle.Size = new System.Drawing.Size(1399, 35); this.PageTitle.Symbol = 0; this.PageTitle.SymbolSize = 24; this.PageTitle.TabIndex = 0; @@ -59,7 +59,7 @@ this.PagePanel.Name = "PagePanel"; this.PagePanel.RadiusSides = Sunny.UI.UICornerRadiusSides.None; this.PagePanel.RectSides = System.Windows.Forms.ToolStripStatusLabelBorderSides.None; - this.PagePanel.Size = new System.Drawing.Size(913, 367); + this.PagePanel.Size = new System.Drawing.Size(1399, 878); this.PagePanel.TabIndex = 1; this.PagePanel.Text = null; this.PagePanel.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter; @@ -67,7 +67,7 @@ // UITitlePage // this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; - this.ClientSize = new System.Drawing.Size(913, 402); + this.ClientSize = new System.Drawing.Size(1399, 913); this.Controls.Add(this.PagePanel); this.Controls.Add(this.PageTitle); this.Name = "UITitlePage"; diff --git a/SunnyUI/Pages/UITitlePage.cs b/SunnyUI/Pages/UITitlePage.cs index ec64086e..d5b4118e 100644 --- a/SunnyUI/Pages/UITitlePage.cs +++ b/SunnyUI/Pages/UITitlePage.cs @@ -31,6 +31,23 @@ namespace Sunny.UI public UITitlePage() { InitializeComponent(); + base.BackColor = UIColor.LightBlue; + TopLevel = false; + if (this.Register()) SetStyle(UIStyles.Style); + + SetStyle(ControlStyles.UserPaint, true); + SetStyle(ControlStyles.AllPaintingInWmPaint, true); + SetStyle(ControlStyles.DoubleBuffer, true); + UpdateStyles(); + + if (!IsDesignMode) base.Dock = DockStyle.Fill; + + Version = UIGlobal.Version; + } + + public new string Version + { + get; } private string text; diff --git a/SunnyUI/Units/UGif.cs b/SunnyUI/Units/UGif.cs new file mode 100644 index 00000000..9093c592 --- /dev/null +++ b/SunnyUI/Units/UGif.cs @@ -0,0 +1,195 @@ +using System; +using System.Drawing; +using System.Drawing.Imaging; +using System.Windows.Forms; + +namespace Sunny.UI +{ + public class Gif : IDisposable + { + public Gif(string fileName) + { + timer = new Timer(); + timer.Tick += Timer_Tick; + + if (FileEx.Exists(fileName)) + { + Image = Image.FromFile(fileName); + } + } + + public Gif(Image img) + { + timer = new Timer(); + timer.Tick += Timer_Tick; + + if (img != null) + { + Image = img; + } + } + + public bool Loop + { + get; set; + } + + public void Reset() + { + ImageCount = 0; + FrameIndex = 0; + Active = false; + } + + private void Timer_Tick(object sender, EventArgs e) + { + timer.Stop(); + + if (Image == null) + { + Reset(); + return; + } + + if (IsGif) + { + if (FrameIndex < ImageCount - 1) + { + FrameIndex++; + } + else + { + if (Loop) + { + FrameIndex = 0; + } + else + { + active = false; + } + } + + FrameDimension fd = image.GifFrameDimension(); + Image.SelectActiveFrame(fd, FrameIndex); + } + + ImageChanged?.Invoke(this, Image); + timer.Enabled = IsGif && active; + } + + public Color BackColor { get; set; } = Color.White; + + public delegate void OnImageChanged(object sender, Image image); + + public event OnImageChanged ImageChanged; + + private readonly Timer timer; + + private Image image; + + private int ImageCount; + public bool IsGif => ImageCount > 0; + + public Image Image + { + get => image; + set + { + Reset(); + image = value; + + if (Image != null) + { + ImageCount = image.GifFrameCount(); + + if (IsGif) + { + int delay = image.GifFrameInterval(); + if (delay > 0) + { + timer.Interval = delay; + } + } + } + } + } + + public void Invalidate() + { + if (!Active) + { + Active = true; + } + } + + public void Dispose() + { + Reset(); + Image?.Dispose(); + Image = null; + } + + private int FrameIndex; + private bool active; + public bool Active + { + get => active; + set + { + ImageCount = 0; + FrameIndex = 0; + active = value; + timer.Enabled = value; + } + } + } + + public static class GifHelper + { + public static FrameDimension GifFrameDimension(this Image img) + { + return new FrameDimension(img.FrameDimensionsList[0]); + } + + public static int GifFrameCount(this Image img) + { + if (img == null) return 0; + FrameDimension fd = new FrameDimension(img.FrameDimensionsList[0]); + return img.GetFrameCount(fd); + } + + public static int GifFrameInterval(this Image img) + { + FrameDimension dim = new FrameDimension(img.FrameDimensionsList[0]); + int frameCount = img.GetFrameCount(dim); + if (frameCount <= 1) + return 0; + + int delay = 0; + bool stop = false; + for (int i = 0; i < frameCount; i++)//遍历图像帧 + { + if (stop) break; + + img.SelectActiveFrame(dim, i);//激活当前帧 + for (int j = 0; j < img.PropertyIdList.Length; j++)//遍历帧属性 + { + if ((int)img.PropertyIdList.GetValue(j) == 0x5100)//如果是延迟时间 + { + PropertyItem pItem = (PropertyItem)img.PropertyItems.GetValue(j);//获取延迟时间属性 + byte[] delayByte = new byte[4];//延迟时间,以1/100秒为单位 + delayByte[0] = pItem.Value[i * 4]; + delayByte[1] = pItem.Value[1 + i * 4]; + delayByte[2] = pItem.Value[2 + i * 4]; + delayByte[3] = pItem.Value[3 + i * 4]; + delay = BitConverter.ToInt32(delayByte, 0) * 10; //乘以10,获取到毫秒 + stop = true; + break; + } + } + } + + return delay; + } + } +}