using System; using System.ComponentModel; using System.Drawing; using System.Linq; using System.Timers; using System.Windows.Forms; namespace qk30ic; public class Form2 : Form { private Bitmap bitmapA = new Bitmap(AppDomain.CurrentDomain.BaseDirectory + "\\pic1.png"); private Bitmap bitmapB = new Bitmap(AppDomain.CurrentDomain.BaseDirectory + "\\pic1_B.png"); private Bitmap bitmapC = new Bitmap(AppDomain.CurrentDomain.BaseDirectory + "\\pic1_C.png"); private Bitmap bitmapD = new Bitmap(AppDomain.CurrentDomain.BaseDirectory + "\\pic1_D.png"); private System.Timers.Timer timer; private IContainer components = null; public Label label1; public Form2() { InitializeComponent(); DoubleBuffered = true; } private void textBox1_TextChanged(object sender, EventArgs e) { } private void Form2_Load(object sender, EventArgs e) { base.FormBorderStyle = FormBorderStyle.None; string[] commandLineArgs = Environment.GetCommandLineArgs(); string[] array = commandLineArgs; foreach (string text in array) { if (text.Equals("/debug")) { base.FormBorderStyle = FormBorderStyle.FixedSingle; } } } private void Form2_FormClosing(object sender, FormClosingEventArgs e) { } private void label1_Click(object sender, EventArgs e) { } private void Form2_Click(object sender, EventArgs e) { if (CompareImages(bitmapA, BackgroundImage)) { Button button = new Button(); button.Size = new Size(500, 500); button.FlatStyle = FlatStyle.Flat; button.FlatAppearance.BorderSize = 0; button.BackColor = Color.Transparent; button.ForeColor = Color.Transparent; button.FlatAppearance.MouseOverBackColor = Color.Transparent; button.FlatAppearance.MouseDownBackColor = Color.Transparent; button.Location = new Point(100, 230); button.Name = "QRButton"; button.Click += QrIcButton_Click; base.Controls.Add(button); Button button2 = new Button(); button2.Size = new Size(500, 500); button2.FlatStyle = FlatStyle.Flat; button2.FlatAppearance.BorderSize = 0; button2.BackColor = Color.Transparent; button2.ForeColor = Color.Transparent; button2.FlatAppearance.MouseOverBackColor = Color.Transparent; button2.FlatAppearance.MouseDownBackColor = Color.Transparent; button2.Location = new Point(700, 230); button2.Name = "ICButton"; button2.Click += QrIcButton_Click; base.Controls.Add(button2); BackgroundImage = bitmapB; SetHomeButton(); StartTimer(10000); } } private void QrIcButton_Click(object sender, EventArgs e) { if (CompareImages(bitmapB, BackgroundImage)) { Button button = (Button)sender; string name = button.Name; if (name == "QRButton") { BackgroundImage = bitmapC; } else if (name == "ICButton") { BackgroundImage = bitmapD; } } RemoveMachiukeButtons(); SetHomeButton(); StartTimer(10000); } public void RemoveMachiukeButtons() { if (base.Controls["QRButton"] is Button value) { base.Controls.Remove(value); } if (base.Controls["ICButton"] is Button value2) { base.Controls.Remove(value2); } } public void StartTimer(int ms) { if (timer != null) { timer.Stop(); timer.Dispose(); } timer = new System.Timers.Timer(ms); timer.Elapsed += Timer_Elapsed; timer.Start(); } private void Timer_Elapsed(object sender, EventArgs e) { Invoke((MethodInvoker)delegate { Console.WriteLine("タイマーが経過しました."); System.Timers.Timer timer = (System.Timers.Timer)sender; timer.Stop(); RemoveMachiukeButtons(); if (CompareImages(bitmapB, BackgroundImage) || CompareImages(bitmapC, BackgroundImage) || CompareImages(bitmapD, BackgroundImage)) { Control control = base.Controls.Find("homeButton", searchAllChildren: true).FirstOrDefault(); if (control != null) { base.Controls.Remove(control); control.Dispose(); } BackgroundImage = bitmapA; } }); } private bool CompareImages(Bitmap imageA, Image backgroundImage) { for (int i = 0; i < imageA.Width; i += 10) { for (int j = 0; j < imageA.Height; j += 10) { if (imageA.GetPixel(i, j) != ((Bitmap)backgroundImage).GetPixel(i, j)) { return false; } } } return true; } private void SetHomeButton() { Control control = base.Controls.Find("homeButton", searchAllChildren: true).FirstOrDefault(); if (control != null) { base.Controls.Remove(control); control.Dispose(); } PictureBox pictureBox = new PictureBox(); pictureBox.Image = Image.FromFile(AppDomain.CurrentDomain.BaseDirectory + "\\homeButton.png"); pictureBox.BackColor = Color.Transparent; pictureBox.ForeColor = Color.Transparent; pictureBox.Size = new Size(125, 125); int num = Screen.PrimaryScreen.WorkingArea.Height; pictureBox.Location = new Point(1275 - pictureBox.Width, 795 - pictureBox.Height); pictureBox.Click += HomeButton_Click; pictureBox.Name = "homeButton"; base.Controls.Add(pictureBox); pictureBox.BringToFront(); } private void HomeButton_Click(object sender, EventArgs e) { RemoveMachiukeButtons(); for (int num = base.Controls.Count - 1; num >= 0; num--) { Control control = base.Controls[num]; if (control is Button || control is Label || control is PictureBox) { base.Controls.Remove(control); control.Dispose(); } } BackgroundImage = bitmapA; } protected override void Dispose(bool disposing) { if (disposing && components != null) { components.Dispose(); } base.Dispose(disposing); } private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(qk30ic.Form2)); this.label1 = new System.Windows.Forms.Label(); base.SuspendLayout(); this.label1.AllowDrop = true; this.label1.Anchor = System.Windows.Forms.AnchorStyles.Left; this.label1.AutoEllipsis = true; this.label1.AutoSize = true; this.label1.Font = new System.Drawing.Font("MS UI Gothic", 30f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 128); this.label1.ImageAlign = System.Drawing.ContentAlignment.BottomRight; this.label1.Location = new System.Drawing.Point(1, 1); this.label1.Margin = new System.Windows.Forms.Padding(0); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(137, 40); this.label1.TabIndex = 0; this.label1.Text = "起動中"; this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.label1.Visible = false; this.label1.Click += new System.EventHandler(label1_Click); base.AutoScaleDimensions = new System.Drawing.SizeF(6f, 12f); base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; base.ClientSize = new System.Drawing.Size(1796, 646); base.Controls.Add(this.label1); base.Icon = (System.Drawing.Icon)resources.GetObject("$this.Icon"); base.Name = "Form2"; this.Text = "Form2"; base.WindowState = System.Windows.Forms.FormWindowState.Maximized; base.FormClosing += new System.Windows.Forms.FormClosingEventHandler(Form2_FormClosing); base.Load += new System.EventHandler(Form2_Load); base.Click += new System.EventHandler(Form2_Click); base.ResumeLayout(false); base.PerformLayout(); } }