diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs index c8abc1f..8b8e0d1 100644 --- a/MainForm.Designer.cs +++ b/MainForm.Designer.cs @@ -30,9 +30,9 @@ private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); - this.label1 = new System.Windows.Forms.Label(); - this.timer1 = new System.Windows.Forms.Timer(this.components); this.progressBar1 = new SteamGuardDesktop.ProgressBarPlus(); + this.linkLabel1 = new System.Windows.Forms.LinkLabel(); + this.timer1 = new System.Windows.Forms.Timer(this.components); this.tableLayoutPanel1.SuspendLayout(); this.SuspendLayout(); // @@ -41,7 +41,7 @@ private void InitializeComponent() this.tableLayoutPanel1.ColumnCount = 1; this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); this.tableLayoutPanel1.Controls.Add(this.progressBar1, 0, 1); - this.tableLayoutPanel1.Controls.Add(this.label1, 0, 0); + this.tableLayoutPanel1.Controls.Add(this.linkLabel1, 0, 0); this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0); this.tableLayoutPanel1.Name = "tableLayoutPanel1"; @@ -52,23 +52,6 @@ private void InitializeComponent() this.tableLayoutPanel1.Size = new System.Drawing.Size(308, 120); this.tableLayoutPanel1.TabIndex = 0; // - // label1 - // - this.label1.Anchor = System.Windows.Forms.AnchorStyles.None; - this.label1.AutoSize = true; - this.label1.Font = new System.Drawing.Font("微软雅黑", 21.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.label1.Location = new System.Drawing.Point(108, 16); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(92, 39); - this.label1.TabIndex = 0; - this.label1.Text = "Code"; - // - // timer1 - // - this.timer1.Enabled = true; - this.timer1.Interval = 1000; - this.timer1.Tick += new System.EventHandler(this.timer1_Tick); - // // progressBar1 // this.progressBar1.Anchor = System.Windows.Forms.AnchorStyles.None; @@ -78,6 +61,30 @@ private void InitializeComponent() this.progressBar1.Size = new System.Drawing.Size(292, 34); this.progressBar1.TabIndex = 2; // + // linkLabel1 + // + this.linkLabel1.ActiveLinkColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); + this.linkLabel1.Anchor = System.Windows.Forms.AnchorStyles.None; + this.linkLabel1.AutoSize = true; + this.linkLabel1.DisabledLinkColor = System.Drawing.Color.Red; + this.linkLabel1.Font = new System.Drawing.Font("微软雅黑", 21.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.linkLabel1.LinkBehavior = System.Windows.Forms.LinkBehavior.NeverUnderline; + this.linkLabel1.LinkColor = System.Drawing.Color.Black; + this.linkLabel1.Location = new System.Drawing.Point(70, 16); + this.linkLabel1.Name = "linkLabel1"; + this.linkLabel1.Size = new System.Drawing.Size(167, 39); + this.linkLabel1.TabIndex = 3; + this.linkLabel1.TabStop = true; + this.linkLabel1.Text = "linkLabel1"; + this.linkLabel1.VisitedLinkColor = System.Drawing.Color.Black; + this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked); + // + // timer1 + // + this.timer1.Enabled = true; + this.timer1.Interval = 1000; + this.timer1.Tick += new System.EventHandler(this.timer1_Tick); + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); @@ -98,9 +105,9 @@ private void InitializeComponent() #endregion private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; - private System.Windows.Forms.Label label1; private ProgressBarPlus progressBar1; private System.Windows.Forms.Timer timer1; + private System.Windows.Forms.LinkLabel linkLabel1; } } diff --git a/MainForm.cs b/MainForm.cs index bfa8ea5..42bb1c6 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -51,7 +51,8 @@ private void Initialize(object sender, EventArgs e) if (!File.Exists("config.json")) { - label1.Text = "Config first!"; + linkLabel1.Text = "Config first!"; + linkLabel1.Enabled = false; timer1.Enabled = false; Utils.FileWrite(Application.StartupPath + "\\config.json", Json.stringify(new SharedSecret())); return; @@ -69,8 +70,9 @@ private void Initialize(object sender, EventArgs e) catch (Exception) { code = "Secret invalid!"; - this.label1.Text = code; + this.linkLabel1.Text = code; timer1.Enabled = false; + linkLabel1.Enabled = false; progressBar1.Value = 0; return; } @@ -84,7 +86,25 @@ private void RefreshCode() { long timestamp = Utils.GetSystemUnixTime(); code = SteamAuth.GenerateSteamGuardCodeForTime(secret.SharedSecretString, timestamp); - this.label1.Text = code; + this.linkLabel1.Text = code; + } + + private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) + { + string tmp = linkLabel1.Text; + Clipboard.SetText(tmp); + linkLabel1.Text = "Copied!"; + Delay(1000); + linkLabel1.Text = tmp; + } + + private static void Delay(int milliSecond) + { + int start = Environment.TickCount; + while (Math.Abs(Environment.TickCount - start) < milliSecond)//毫秒 + { + Application.DoEvents();//可执行某无聊的操作 + } } } }