From dd12dc3ea28bffbdcaa77a775d5c4e5781a2a0c3 Mon Sep 17 00:00:00 2001 From: yibo <361071264@qq.com> Date: Tue, 12 Jun 2018 09:42:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0MessageBox.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WinFormControl/NMessageBox.Designer.cs | 88 ++++++++++++++++++ WinFormControl/NMessageBox.cs | 72 +++++++++++++++ WinFormControl/NMessageBox.resx | 120 +++++++++++++++++++++++++ WinFormControl/WinFormControl.csproj | 9 ++ 4 files changed, 289 insertions(+) create mode 100644 WinFormControl/NMessageBox.Designer.cs create mode 100644 WinFormControl/NMessageBox.cs create mode 100644 WinFormControl/NMessageBox.resx diff --git a/WinFormControl/NMessageBox.Designer.cs b/WinFormControl/NMessageBox.Designer.cs new file mode 100644 index 0000000..9762475 --- /dev/null +++ b/WinFormControl/NMessageBox.Designer.cs @@ -0,0 +1,88 @@ +namespace WinFormControl +{ + partial class NMessageBox + { + /// + /// 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() + { + this.okBtn = new WinFormControl.NButton(); + this.msgLbl = new WinFormControl.ULabel(); + this.SuspendLayout(); + // + // okBtn + // + this.okBtn.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(51)))), ((int)(((byte)(136)))), ((int)(((byte)(255))))); + this.okBtn.ClickColor = System.Drawing.Color.YellowGreen; + this.okBtn.Font = new System.Drawing.Font("宋体", 18F); + this.okBtn.ForeColor = System.Drawing.Color.White; + this.okBtn.Location = new System.Drawing.Point(125, 150); + this.okBtn.Name = "okBtn"; + this.okBtn.PlaySound = false; + this.okBtn.Size = new System.Drawing.Size(158, 63); + this.okBtn.SoundType = WinFormControl.SoundType.Click; + this.okBtn.TabIndex = 3; + this.okBtn.Text = "nButton1"; + this.okBtn.ToColor = System.Drawing.Color.FromArgb(((int)(((byte)(51)))), ((int)(((byte)(136)))), ((int)(((byte)(255))))); + this.okBtn.UseVisualStyleBackColor = false; + this.okBtn.Click += new System.EventHandler(this.okBtn_Click); + // + // msgLbl + // + this.msgLbl.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.msgLbl.BackColor = System.Drawing.Color.Transparent; + this.msgLbl.Font = new System.Drawing.Font("宋体", 18F); + this.msgLbl.ForeColor = System.Drawing.Color.Red; + this.msgLbl.Location = new System.Drawing.Point(65, 37); + this.msgLbl.Name = "msgLbl"; + this.msgLbl.Size = new System.Drawing.Size(286, 97); + this.msgLbl.TabIndex = 2; + this.msgLbl.Text = "uLabel1"; + this.msgLbl.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // NMessageBox + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackColor = System.Drawing.SystemColors.Control; + this.ClientSize = new System.Drawing.Size(417, 251); + this.Controls.Add(this.okBtn); + this.Controls.Add(this.msgLbl); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; + this.Name = "NMessageBox"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "NMessageBox"; + this.ResumeLayout(false); + + } + + #endregion + + private NButton okBtn; + private ULabel msgLbl; + + } +} \ No newline at end of file diff --git a/WinFormControl/NMessageBox.cs b/WinFormControl/NMessageBox.cs new file mode 100644 index 0000000..0d209c7 --- /dev/null +++ b/WinFormControl/NMessageBox.cs @@ -0,0 +1,72 @@ +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 WinFormControl +{ + public partial class NMessageBox : Form + { + + System.Timers.Timer timer; + int sec = 0; + private NMessageBox(string msg, int closeSec) + { + InitializeComponent(); + msgLbl.Text = msg; + okBtn.Text = "确定"; + if (closeSec > 0) + { + sec = closeSec; + timer = new System.Timers.Timer(); + timer.Interval = 1000; + timer.Elapsed += timer_Elapsed; + timer.Start(); + } + this.FormClosing += DialogForm_FormClosing; + } + + void DialogForm_FormClosing(object sender, FormClosingEventArgs e) + { + if (timer != null) + { + if (timer.Enabled) + timer.Enabled = false; + timer.Dispose(); + } + } + + void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) + { + this.Invoke(new Action(() => + { + if (sec > 0) + { + this.okBtn.Text = string.Format("确定({0}秒)", sec); + sec--; + } + else + { + timer.Enabled = false; + this.Close(); + } + })); + } + + public static void ShowDialog(string msg, int closeSec = 0) + { + var d = new NMessageBox(msg, closeSec); + d.ShowDialog(); + } + + private void okBtn_Click(object sender, EventArgs e) + { + this.Close(); + } + } +} diff --git a/WinFormControl/NMessageBox.resx b/WinFormControl/NMessageBox.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/WinFormControl/NMessageBox.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/WinFormControl/WinFormControl.csproj b/WinFormControl/WinFormControl.csproj index 2a9c169..5004c46 100644 --- a/WinFormControl/WinFormControl.csproj +++ b/WinFormControl/WinFormControl.csproj @@ -48,6 +48,12 @@ Component + + Form + + + NMessageBox.cs + UserControl @@ -120,6 +126,9 @@ NetStateWatch.cs + + NMessageBox.cs + ResXFileCodeGenerator Resources.Designer.cs