From 6dbc49852ca0c5b792399f798c3935bbc4d0cad0 Mon Sep 17 00:00:00 2001 From: lxxgd Date: Thu, 4 Apr 2024 00:18:37 +0800 Subject: [PATCH] RainbowButton --- CBTool/CBTool.csproj.user | 6 +- CBTool/CBToolCS.Designer.cs | 11 ++ CBTool/CBToolCS.resx | 29 ++- CBTool/README.Designer.cs | 74 -------- CBTool/README.cs | 20 --- CBTool/README.resx | 120 ------------- CBTool/RainbowButton.cs | 167 ++++++++++++++++++ .../net8.0-windows/CBTool.AssemblyInfo.cs | 9 +- 8 files changed, 211 insertions(+), 225 deletions(-) delete mode 100644 CBTool/README.Designer.cs delete mode 100644 CBTool/README.cs delete mode 100644 CBTool/README.resx create mode 100644 CBTool/RainbowButton.cs diff --git a/CBTool/CBTool.csproj.user b/CBTool/CBTool.csproj.user index 6d86792..caff894 100644 --- a/CBTool/CBTool.csproj.user +++ b/CBTool/CBTool.csproj.user @@ -13,11 +13,11 @@ Form - + Component - - Form + + Component Form diff --git a/CBTool/CBToolCS.Designer.cs b/CBTool/CBToolCS.Designer.cs index 10a7c63..87762ef 100644 --- a/CBTool/CBToolCS.Designer.cs +++ b/CBTool/CBToolCS.Designer.cs @@ -35,6 +35,7 @@ private void InitializeComponent() button3 = new Button(); timer1 = new System.Windows.Forms.Timer(components); rainbowLabel1 = new RainbowLabel(); + rainbowButton1 = new RainbowButton(); SuspendLayout(); // // button1 @@ -64,10 +65,19 @@ private void InitializeComponent() rainbowLabel1.Float = true; rainbowLabel1.Name = "rainbowLabel1"; // + // rainbowButton1 + // + rainbowButton1.Float = true; + resources.ApplyResources(rainbowButton1, "rainbowButton1"); + rainbowButton1.Name = "rainbowButton1"; + rainbowButton1.RealText = "test"; + rainbowButton1.UseVisualStyleBackColor = true; + // // CBToolCS // resources.ApplyResources(this, "$this"); AutoScaleMode = AutoScaleMode.Font; + Controls.Add(rainbowButton1); Controls.Add(rainbowLabel1); Controls.Add(button3); Controls.Add(button2); @@ -87,5 +97,6 @@ private void InitializeComponent() private Button button3; private System.Windows.Forms.Timer timer1; private RainbowLabel rainbowLabel1; + private RainbowButton rainbowButton1; } } diff --git a/CBTool/CBToolCS.resx b/CBTool/CBToolCS.resx index b489aa5..99536fa 100644 --- a/CBTool/CBToolCS.resx +++ b/CBTool/CBToolCS.resx @@ -141,7 +141,7 @@ $this - 3 + 4 12, 62 @@ -165,7 +165,7 @@ $this - 2 + 3 12, 95 @@ -189,7 +189,7 @@ $this - 1 + 2 17, 17 @@ -219,6 +219,27 @@ $this + 1 + + + 66, 128 + + + 75, 23 + + + 5 + + + rainbowButton1 + + + CBTool.RainbowButton, CBTool, Culture=neutral, PublicKeyToken=null + + + $this + + 0 @@ -231,7 +252,7 @@ True - 225, 144 + 225, 179 diff --git a/CBTool/README.Designer.cs b/CBTool/README.Designer.cs deleted file mode 100644 index 3bbec4a..0000000 --- a/CBTool/README.Designer.cs +++ /dev/null @@ -1,74 +0,0 @@ -namespace CBTool -{ - partial class README - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - pictureBox1 = new PictureBox(); - panel1 = new Panel(); - ((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit(); - panel1.SuspendLayout(); - SuspendLayout(); - // - // pictureBox1 - // - pictureBox1.Image = Properties.Resources.屏幕截图_2024_04_02_204233; - pictureBox1.Location = new Point(12, 12); - pictureBox1.Name = "pictureBox1"; - pictureBox1.Size = new Size(589, 353); - pictureBox1.SizeMode = PictureBoxSizeMode.Zoom; - pictureBox1.TabIndex = 1; - pictureBox1.TabStop = false; - // - // panel1 - // - panel1.AutoScroll = true; - panel1.Controls.Add(pictureBox1); - panel1.Dock = DockStyle.Fill; - panel1.Location = new Point(0, 0); - panel1.Name = "panel1"; - panel1.Size = new Size(936, 618); - panel1.TabIndex = 2; - // - // README - // - AutoScaleDimensions = new SizeF(7F, 17F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(936, 618); - Controls.Add(panel1); - Name = "README"; - Text = "README"; - ((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit(); - panel1.ResumeLayout(false); - ResumeLayout(false); - } - - #endregion - private PictureBox pictureBox1; - private Panel panel1; - } -} \ No newline at end of file diff --git a/CBTool/README.cs b/CBTool/README.cs deleted file mode 100644 index 8ee57d9..0000000 --- a/CBTool/README.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace CBTool -{ - public partial class README : Form - { - public README() - { - InitializeComponent(); - } - } -} diff --git a/CBTool/README.resx b/CBTool/README.resx deleted file mode 100644 index af32865..0000000 --- a/CBTool/README.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/CBTool/RainbowButton.cs b/CBTool/RainbowButton.cs new file mode 100644 index 0000000..cc3740c --- /dev/null +++ b/CBTool/RainbowButton.cs @@ -0,0 +1,167 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.DirectoryServices.ActiveDirectory; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using static System.Runtime.InteropServices.JavaScript.JSType; +using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window; + +namespace CBTool +{ + internal class RainbowButton : Button + { + System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer(); + private int DiscoStyle; + private int DiscoG; + private int DiscoB; + private int DiscoR; + + [Browsable(true)] + [Category("Appearance")] + [Description("是否启用浮动效果")] + public bool Float { get; set; } + [Browsable(true)] + [Category("Appearance")] + [Description("真实文本")] + public string RealText { get; set; } + + public RainbowButton() : base() + { + timer.Interval = 16; + timer.Start(); + timer.Tick += Timer_Tick; + RealText = ""; + } + + private void Timer_Tick(object? sender, EventArgs e) + { + this.Refresh(); + } + + protected override void Dispose(bool disposing) + { + if (disposing) + timer.Dispose(); + base.Dispose(disposing); + } + + float num3 = 0; + + public static double Lerp(double value1, double value2, double amount) + { + return value1 + (value2 - value1) * amount; + } + + public static Rectangle DeflateRect(Rectangle rect, Padding padding) + { + rect.X += padding.Left; + rect.Y += padding.Top; + rect.Width -= padding.Horizontal; + rect.Height -= padding.Vertical; + return rect; + } + + protected override void OnPaint(PaintEventArgs pevent) + { + Graphics graphics = pevent.Graphics; + Text = ""; + base.OnPaint(pevent); + //Pen pen = new Pen(BackColor); + //graphics.FillRectangle(new SolidBrush(BackColor), new RectangleF(new PointF(0,0),new SizeF(Size*0.8f))); + int num = 7; + if (this.DiscoStyle == 0) + { + DiscoG += num; + if (DiscoG >= 255) + { + DiscoG = 255; + this.DiscoStyle++; + } + } + if (this.DiscoStyle == 1) + { + DiscoR -= num; + if (DiscoR <= 0) + { + DiscoR = 0; + this.DiscoStyle++; + } + } + if (this.DiscoStyle == 2) + { + DiscoB += num; + if (DiscoB >= 255) + { + DiscoB = 255; + this.DiscoStyle++; + } + } + if (this.DiscoStyle == 3) + { + DiscoG -= num; + if (DiscoG <= 0) + { + DiscoG = 0; + this.DiscoStyle++; + } + } + if (this.DiscoStyle == 4) + { + DiscoR += num; + if (DiscoR >= 255) + { + DiscoR = 255; + this.DiscoStyle++; + } + } + if (this.DiscoStyle == 5) + { + DiscoB -= num; + if (DiscoB <= 0) + { + DiscoB = 0; + this.DiscoStyle = 0; + } + } + num += 1; + if (num > 180.0F) + { + num = 0; + } + string text = RealText; + System.Drawing.Font font = new System.Drawing.Font(this.Font.FontFamily, 10f); + Rectangle rectangle = DeflateRect(this.ClientRectangle, this.Padding); + float x = (rectangle.X + rectangle.Width/2 - graphics.MeasureString(text, font, int.MaxValue, StringFormat.GenericTypographic).Width/2); + float y = rectangle.Y; + double huehuehue = (DateTime.Now.Ticks) % 1; + double s = 0; + double l = 0; + ColorHelper.RGBToHSL(Color.FromArgb(DiscoR, DiscoG, DiscoB), ref huehuehue, ref s, ref l); + num3 += 1; + if (num3 > 512) + { + num3 = 0; + } + huehuehue /= 360; + float huehuehueStep = (float)Math.PI / 60f/*(float)rangeRemap(Math.Sin((double)((float)DateTime.Now.Ticksnum2 / 500)) % 6.28318, -1.5, 1.5, 0.01, 0.15)*/; + Color color = Color.White; + float posX = x; + for (int i = 0; i < text.Length; i++) + { + float yOffset = (float)Math.Sin(i + num3 / 6); + //huehuehue /= i; + huehuehue += huehuehueStep; + huehuehue %= 1.0F; + //posX +=TextRenderer.MeasureText(text[i].ToString(), font, new Size(int.MaxValue, int.MaxValue), TextFormatFlags.Default).Width*0.6f; + Brush brush = new SolidBrush(ColorHelper.HslToRgb(huehuehue * 360, 1 * 255, 0.5f * 255)); + if (Float) + graphics.DrawString(text[i].ToString(), font, brush, posX, y + yOffset * 3); + else + graphics.DrawString(text[i].ToString(), font, brush, posX, y); + posX += graphics.MeasureString(text[i].ToString(), font, int.MaxValue, StringFormat.GenericTypographic).Width; + } + } + } +} diff --git a/CBTool/obj/Debug/net8.0-windows/CBTool.AssemblyInfo.cs b/CBTool/obj/Debug/net8.0-windows/CBTool.AssemblyInfo.cs index 3174e6f..3f7e6db 100644 --- a/CBTool/obj/Debug/net8.0-windows/CBTool.AssemblyInfo.cs +++ b/CBTool/obj/Debug/net8.0-windows/CBTool.AssemblyInfo.cs @@ -1,9 +1,10 @@ //------------------------------------------------------------------------------ // -// This code was generated by a tool. +// 此代码由工具生成。 +// 运行时版本:4.0.30319.42000 // -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 // //------------------------------------------------------------------------------ @@ -13,7 +14,7 @@ [assembly: System.Reflection.AssemblyCompanyAttribute("CBTool")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.2.1")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+a0b51ec10a6bb66950b962ffeed13ea20e350d24")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+3a0d295981461ceea63049137adca51f94dabcc1")] [assembly: System.Reflection.AssemblyProductAttribute("CBTool")] [assembly: System.Reflection.AssemblyTitleAttribute("CBTool")] [assembly: System.Reflection.AssemblyVersionAttribute("1.2.1")]