diff --git a/WinFormControl/ControlUtil.cs b/WinFormControl/ControlUtil.cs index 8947573..c59f0df 100644 --- a/WinFormControl/ControlUtil.cs +++ b/WinFormControl/ControlUtil.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Data; +using System.Windows.Forms; namespace WinFormControl.Converter { @@ -21,4 +22,23 @@ namespace WinFormControl.Converter throw new NotImplementedException(); } } + + static class ControlUtil + { + public static Form GetParentFormm(Control control) + { + if (control.Parent != null) + { + if (control.Parent is Form) + { + return control.Parent as Form; ; + } + else + { + return GetParentFormm(control.Parent); + } + } + return control as Form; + } + } } diff --git a/WinFormControl/Properties/Resources.Designer.cs b/WinFormControl/Properties/Resources.Designer.cs new file mode 100644 index 0000000..b681aba --- /dev/null +++ b/WinFormControl/Properties/Resources.Designer.cs @@ -0,0 +1,83 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本:4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace WinFormControl.Properties { + using System; + + + /// + /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// 返回此类使用的缓存的 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WinFormControl.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 使用此强类型资源类,为所有资源查找 + /// 重写当前线程的 CurrentUICulture 属性。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap onclickBtn { + get { + object obj = ResourceManager.GetObject("onclickBtn", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap simpleBtn { + get { + object obj = ResourceManager.GetObject("simpleBtn", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/WinFormControl/Properties/Resources.resx b/WinFormControl/Properties/Resources.resx new file mode 100644 index 0000000..73d94a9 --- /dev/null +++ b/WinFormControl/Properties/Resources.resx @@ -0,0 +1,127 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + + ..\Resources\onclickBtn.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\simpleBtn.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file diff --git a/WinFormControl/Resources/onclickBtn.png b/WinFormControl/Resources/onclickBtn.png new file mode 100644 index 0000000..504e15a Binary files /dev/null and b/WinFormControl/Resources/onclickBtn.png differ diff --git a/WinFormControl/Resources/simpleBtn.png b/WinFormControl/Resources/simpleBtn.png new file mode 100644 index 0000000..b1b8ba9 Binary files /dev/null and b/WinFormControl/Resources/simpleBtn.png differ diff --git a/WinFormControl/UButton.cs b/WinFormControl/UButton.cs new file mode 100644 index 0000000..36072d9 --- /dev/null +++ b/WinFormControl/UButton.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using WinFormControl.Properties; + +namespace WinFormControl +{ + public class UButton : Button + { + protected override void InitLayout() + { + base.InitLayout(); + this.BackgroundImage = Resources.simpleBtn; + this.ForeColor = Color.Black; + this.BackColor = Color.Transparent; + this.FlatStyle = FlatStyle.Flat; + this.FlatAppearance.BorderSize = 0; + } + + protected override void OnClick(EventArgs e) + { + this.BackgroundImage = Resources.onclickBtn; + this.ForeColor = Color.White; + this.Refresh(); + try + { + base.OnClick(e); + } + finally + { + System.Threading.Thread.Sleep(200); + this.BackgroundImage = Resources.simpleBtn; + this.ForeColor = Color.Black; + this.Refresh(); + } + } + } +} diff --git a/WinFormControl/ULabel.cs b/WinFormControl/ULabel.cs new file mode 100644 index 0000000..fdd2dca --- /dev/null +++ b/WinFormControl/ULabel.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace WinFormControl +{ + public class ULabel : Label + { + protected override void InitLayout() + { + base.InitLayout(); + this.BackColor = Color.Transparent; + } + } +} diff --git a/WinFormControl/UMessageBox.Designer.cs b/WinFormControl/UMessageBox.Designer.cs new file mode 100644 index 0000000..686fc5b --- /dev/null +++ b/WinFormControl/UMessageBox.Designer.cs @@ -0,0 +1,87 @@ +namespace WinFormControl +{ + partial class UMessageBox + { + /// + /// 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() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(UMessageBox)); + this.uButton1 = new WinFormControl.UButton(); + this.label1 = new WinFormControl.ULabel(); + this.SuspendLayout(); + // + // uButton1 + // + this.uButton1.BackColor = System.Drawing.Color.Transparent; + this.uButton1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("uButton1.BackgroundImage"))); + this.uButton1.FlatAppearance.BorderSize = 0; + this.uButton1.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.uButton1.Font = new System.Drawing.Font("宋体", 18F); + this.uButton1.ForeColor = System.Drawing.Color.Black; + this.uButton1.Location = new System.Drawing.Point(114, 127); + this.uButton1.Name = "uButton1"; + this.uButton1.Size = new System.Drawing.Size(123, 49); + this.uButton1.TabIndex = 0; + this.uButton1.Text = "确 定"; + this.uButton1.UseVisualStyleBackColor = false; + this.uButton1.Click += new System.EventHandler(this.uButton1_Click); + // + // label1 + // + this.label1.BackColor = System.Drawing.Color.Transparent; + this.label1.Font = new System.Drawing.Font("宋体", 15F); + this.label1.Location = new System.Drawing.Point(28, 29); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(296, 82); + this.label1.TabIndex = 1; + this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // UMessageBox + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackColor = System.Drawing.SystemColors.ControlLightLight; + this.ClientSize = new System.Drawing.Size(352, 197); + this.Controls.Add(this.label1); + this.Controls.Add(this.uButton1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "UMessageBox"; + this.ShowIcon = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "消息"; + this.ResumeLayout(false); + + } + + #endregion + + private UButton uButton1; + private ULabel label1; + + } +} \ No newline at end of file diff --git a/WinFormControl/UMessageBox.cs b/WinFormControl/UMessageBox.cs new file mode 100644 index 0000000..48004ec --- /dev/null +++ b/WinFormControl/UMessageBox.cs @@ -0,0 +1,44 @@ +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 UMessageBox : Form + { + public UMessageBox() + { + InitializeComponent(); + } + + static UMessageBox messageBox; + public static void Show(string message) + { + if (messageBox == null) + messageBox = new UMessageBox(); + if (message.Length >= 50) + message = message.Substring(0, 50) + "……"; + messageBox.label1.Text = message; + messageBox.ShowDialog(); + } + + public static void Show(string message, string title) + { + if (messageBox == null) + messageBox = new UMessageBox(); + messageBox.Text = title; + Show(message); + } + + private void uButton1_Click(object sender, EventArgs e) + { + this.Close(); + } + } +} diff --git a/WinFormControl/UMessageBox.resx b/WinFormControl/UMessageBox.resx new file mode 100644 index 0000000..681c9a5 --- /dev/null +++ b/WinFormControl/UMessageBox.resx @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + + + iVBORw0KGgoAAAANSUhEUgAAAGAAAAAwCAIAAABhdOiYAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO + wwAADsMBx2+oZAAAAHNJREFUaEPt0AENACAMwDAkowVB14aDz0CTKui5b1gICoKCoCAoCAqCgqAgKAgK + goKgICgICoKCoCAoCAqCgqAgKAgKgoKgICgICoKCoCAoCAqCgqAgKAgKgoKgICgICoKCoCAoCAqCgqAg + KAgKgoKg1ZsPvpCB0hBohjQAAAAASUVORK5CYII= + + + \ No newline at end of file diff --git a/WinFormControl/UTextBoxWithPad.cs b/WinFormControl/UTextBoxWithPad.cs new file mode 100644 index 0000000..85deb74 --- /dev/null +++ b/WinFormControl/UTextBoxWithPad.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using WinFormControl.Converter; + +namespace WinFormControl +{ + public class UTextBoxWithPad : TextBox + { + public enum TextBoxType + { + Normal, + Number + } + public UTextBoxWithPad() + { + this.Font = new Font("宋体", 20); + } + + public TextBoxType Type { get; set; } + + protected override void OnClick(EventArgs e) + { + if (this.Type == TextBoxType.Normal) + { + var keyBoard = new VirtualKeyPad(); + if (keyBoard.ShowDialog() == true) + this.Text = keyBoard.Result; + } + else + { + var keyBoard = new NumberPad(); + if (keyBoard.ShowDialog() == true) + this.Text = keyBoard.Result; + } + base.OnClick(e); + + var form = ControlUtil.GetParentFormm(this); + form.Activate(); + this.Focus(); + + } + } +} diff --git a/WinFormControl/WinFormControl.csproj b/WinFormControl/WinFormControl.csproj index 6cc0c1c..e336ccb 100644 --- a/WinFormControl/WinFormControl.csproj +++ b/WinFormControl/WinFormControl.csproj @@ -34,7 +34,9 @@ + + @@ -49,12 +51,32 @@ NumberPad.xaml + + True + True + Resources.resx + + + Component + + + Component + + + Form + + + UMessageBox.cs + + + Component + VirtualKeyPad.xaml - + @@ -66,6 +88,18 @@ MSBuild:Compile + + + ResXFileCodeGenerator + Resources.Designer.cs + + + UMessageBox.cs + + + + +