From 2e5c80acf5dd9a7996e5a1c9ec563d7ac6e0f688 Mon Sep 17 00:00:00 2001
From: yibo <361071264@qq.com>
Date: Tue, 27 Mar 2018 10:25:12 +0800
Subject: [PATCH] Init
---
.gitignore | 6 +
WinFormControl.sln | 22 ++
WinFormControl/ControlUtil.cs | 24 ++
WinFormControl/NumberPad.xaml | 63 ++++
WinFormControl/NumberPad.xaml.cs | 69 +++++
WinFormControl/Properties/AssemblyInfo.cs | 36 +++
WinFormControl/VirtualKeyPad.xaml | 355 ++++++++++++++++++++++
WinFormControl/VirtualKeyPad.xaml.cs | 104 +++++++
WinFormControl/WinFormControl.csproj | 77 +++++
9 files changed, 756 insertions(+)
create mode 100644 .gitignore
create mode 100644 WinFormControl.sln
create mode 100644 WinFormControl/ControlUtil.cs
create mode 100644 WinFormControl/NumberPad.xaml
create mode 100644 WinFormControl/NumberPad.xaml.cs
create mode 100644 WinFormControl/Properties/AssemblyInfo.cs
create mode 100644 WinFormControl/VirtualKeyPad.xaml
create mode 100644 WinFormControl/VirtualKeyPad.xaml.cs
create mode 100644 WinFormControl/WinFormControl.csproj
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..55aea87
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,6 @@
+*.suo
+bin
+obj
+.vs
+*.user
+_ReSharper.WinFormControl
diff --git a/WinFormControl.sln b/WinFormControl.sln
new file mode 100644
index 0000000..8597204
--- /dev/null
+++ b/WinFormControl.sln
@@ -0,0 +1,22 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 2013
+VisualStudioVersion = 12.0.40629.0
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormControl", "WinFormControl\WinFormControl.csproj", "{45A6C56B-C815-4AEA-B0C4-68C122FD3139}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {45A6C56B-C815-4AEA-B0C4-68C122FD3139}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {45A6C56B-C815-4AEA-B0C4-68C122FD3139}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {45A6C56B-C815-4AEA-B0C4-68C122FD3139}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {45A6C56B-C815-4AEA-B0C4-68C122FD3139}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
diff --git a/WinFormControl/ControlUtil.cs b/WinFormControl/ControlUtil.cs
new file mode 100644
index 0000000..8947573
--- /dev/null
+++ b/WinFormControl/ControlUtil.cs
@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Data;
+
+namespace WinFormControl.Converter
+{
+ class BoolToVisibilityConverter : IValueConverter
+ {
+ public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
+ {
+ if ((bool?)value == true)
+ return System.Windows.Visibility.Visible;
+ return System.Windows.Visibility.Collapsed;
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
diff --git a/WinFormControl/NumberPad.xaml b/WinFormControl/NumberPad.xaml
new file mode 100644
index 0000000..877371b
--- /dev/null
+++ b/WinFormControl/NumberPad.xaml
@@ -0,0 +1,63 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/WinFormControl/NumberPad.xaml.cs b/WinFormControl/NumberPad.xaml.cs
new file mode 100644
index 0000000..aa1994b
--- /dev/null
+++ b/WinFormControl/NumberPad.xaml.cs
@@ -0,0 +1,69 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace WinFormControl
+{
+ public partial class NumberPad : INotifyPropertyChanged
+ {
+ private string _result;
+ public string Result
+ {
+ get { return _result; }
+ private set { _result = value; OnPropertyChanged("Result"); }
+ }
+
+ public NumberPad()
+ {
+ InitializeComponent();
+ DataContext = this;
+ Result = string.Empty;
+ }
+
+ private void button_Click(object sender, RoutedEventArgs e)
+ {
+ var button = sender as Button;
+ if (button != null)
+ switch (button.CommandParameter.ToString())
+ {
+ case "ESC":
+ Close();
+ break;
+
+ case "RETURN":
+ DialogResult = true;
+ break;
+
+ case "BACK":
+ if (Result.Length > 0)
+ Result = Result.Remove(Result.Length - 1);
+ break;
+
+ default:
+ Result += button.Content.ToString();
+ break;
+ }
+ }
+
+ public event PropertyChangedEventHandler PropertyChanged;
+ private void OnPropertyChanged(String info)
+ {
+ if (PropertyChanged != null)
+ {
+ PropertyChanged(this, new PropertyChangedEventArgs(info));
+ }
+ }
+ }
+}
diff --git a/WinFormControl/Properties/AssemblyInfo.cs b/WinFormControl/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..828d9b8
--- /dev/null
+++ b/WinFormControl/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// 有关程序集的常规信息通过以下
+// 特性集控制。更改这些特性值可修改
+// 与程序集关联的信息。
+[assembly: AssemblyTitle("WinFormControl")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("WinFormControl")]
+[assembly: AssemblyCopyright("Copyright © 2018")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// 将 ComVisible 设置为 false 使此程序集中的类型
+// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
+// 则将该类型上的 ComVisible 特性设置为 true。
+[assembly: ComVisible(false)]
+
+// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
+[assembly: Guid("747dea7e-a712-427e-ac75-fe1b69ec9b42")]
+
+// 程序集的版本信息由下面四个值组成:
+//
+// 主版本
+// 次版本
+// 生成号
+// 修订号
+//
+// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
+// 方法是按如下所示使用“*”:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/WinFormControl/VirtualKeyPad.xaml b/WinFormControl/VirtualKeyPad.xaml
new file mode 100644
index 0000000..d1d6e49
--- /dev/null
+++ b/WinFormControl/VirtualKeyPad.xaml
@@ -0,0 +1,355 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/WinFormControl/VirtualKeyPad.xaml.cs b/WinFormControl/VirtualKeyPad.xaml.cs
new file mode 100644
index 0000000..18f4c13
--- /dev/null
+++ b/WinFormControl/VirtualKeyPad.xaml.cs
@@ -0,0 +1,104 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Text.RegularExpressions;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace WinFormControl
+{
+ ///
+ /// VirtualKeyPad.xaml 的交互逻辑
+ ///
+ public partial class VirtualKeyPad : INotifyPropertyChanged
+ {
+ private bool _showNumericKeyboard;
+ public bool ShowNumericKeyboard
+ {
+ get { return _showNumericKeyboard; }
+ set { _showNumericKeyboard = value; OnPropertyChanged("ShowNumericKeyboard"); }
+ }
+
+ private string _result;
+ public string Result
+ {
+ get { return _result; }
+ private set { _result = value; OnPropertyChanged("Result"); }
+ }
+
+ public VirtualKeyPad()
+ {
+ InitializeComponent();
+ DataContext = this;
+ Result = "";
+ }
+
+ private void button_Click(object sender, RoutedEventArgs e)
+ {
+ var button = sender as Button;
+ if (button != null)
+ {
+ switch (button.CommandParameter.ToString())
+ {
+ case "LSHIFT":
+ var upperCaseRegex = new Regex("[A-Z]");
+ var lowerCaseRegex = new Regex("[a-z]");
+ Button btn;
+ foreach (UIElement elem in AlfaKeyboard.Children) //iterate the main grid
+ {
+ var grid = elem as Grid;
+ if (grid != null)
+ {
+ foreach (UIElement uiElement in grid.Children) //iterate the single rows
+ {
+ btn = uiElement as Button;
+ if (btn != null) // if button contains only 1 character
+ {
+ if (btn.Content.ToString().Length == 1)
+ {
+ if (upperCaseRegex.Match(btn.Content.ToString()).Success) // if the char is a letter and uppercase
+ btn.Content = btn.Content.ToString().ToLower();
+ else if (lowerCaseRegex.Match(button.Content.ToString()).Success) // if the char is a letter and lower case
+ btn.Content = btn.Content.ToString().ToUpper();
+ }
+ }
+ }
+ }
+ }
+ break;
+
+ case "ALT":
+ case "CTRL":
+ break;
+ case "RETURN":
+ DialogResult = true;
+ break;
+ case "BACK":
+ if (Result.Length > 0)
+ Result = Result.Remove(Result.Length - 1);
+ break;
+ default:
+ Result += button.Content.ToString();
+ break;
+ }
+ }
+ }
+
+ public event PropertyChangedEventHandler PropertyChanged;
+ protected void OnPropertyChanged(string propertyName)
+ {
+ if (PropertyChanged != null)
+ PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
+ }
+ }
+}
diff --git a/WinFormControl/WinFormControl.csproj b/WinFormControl/WinFormControl.csproj
new file mode 100644
index 0000000..6cc0c1c
--- /dev/null
+++ b/WinFormControl/WinFormControl.csproj
@@ -0,0 +1,77 @@
+
+
+
+
+ Debug
+ AnyCPU
+ {45A6C56B-C815-4AEA-B0C4-68C122FD3139}
+ Library
+ Properties
+ WinFormControl
+ WinFormControl
+ v4.5
+ 512
+
+
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ NumberPad.xaml
+
+
+
+ VirtualKeyPad.xaml
+
+
+
+
+
+
+
+ Designer
+ MSBuild:Compile
+
+
+ Designer
+ MSBuild:Compile
+
+
+
+
+
\ No newline at end of file