Browse Source

Init

master
yibo 7 years ago
commit
2e5c80acf5
9 changed files with 756 additions and 0 deletions
  1. +6
    -0
      .gitignore
  2. +22
    -0
      WinFormControl.sln
  3. +24
    -0
      WinFormControl/ControlUtil.cs
  4. +63
    -0
      WinFormControl/NumberPad.xaml
  5. +69
    -0
      WinFormControl/NumberPad.xaml.cs
  6. +36
    -0
      WinFormControl/Properties/AssemblyInfo.cs
  7. +355
    -0
      WinFormControl/VirtualKeyPad.xaml
  8. +104
    -0
      WinFormControl/VirtualKeyPad.xaml.cs
  9. +77
    -0
      WinFormControl/WinFormControl.csproj

+ 6
- 0
.gitignore View File

@ -0,0 +1,6 @@
*.suo
bin
obj
.vs
*.user
_ReSharper.WinFormControl

+ 22
- 0
WinFormControl.sln View File

@ -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

+ 24
- 0
WinFormControl/ControlUtil.cs View File

@ -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();
}
}
}

+ 63
- 0
WinFormControl/NumberPad.xaml View File

@ -0,0 +1,63 @@
<Window x:Class="WinFormControl.NumberPad"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="数字键盘" Height="313" Width="299" ShowInTaskbar="False" WindowStartupLocation="CenterScreen" ResizeMode="NoResize" >
<Window.Resources>
<DropShadowEffect x:Key="DropShadowEffect" ShadowDepth="1" Direction="-90" BlurRadius="3" />
<Style TargetType="Label">
<Setter Property="FontSize" Value="22"/>
<Setter Property="Label.Effect" Value="{StaticResource DropShadowEffect}"/>
</Style>
<LinearGradientBrush x:Key="IPhoneSteelBackground" EndPoint="0.5,1.272" StartPoint="0.5,0">
<GradientStop Color="#FF9097A3" Offset="0"/>
<GradientStop Color="#FF444D5B" Offset="1"/>
</LinearGradientBrush>
<Style TargetType="Button">
<EventSetter Event="Click" Handler="button_Click" />
<Setter Property="Margin" Value="4"/>
<Setter Property="Button.Effect" Value="{StaticResource DropShadowEffect}"/>
<Setter Property="FontSize" Value="22"/>
<Setter Property="Background" Value="WhiteSmoke"/>
<Setter Property="RenderTransform">
<Setter.Value>
<!-- Workaround for ATI video cards that don't render good with dropshadoweffect-->
<RotateTransform Angle="0.00000000001"/>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid Background="{DynamicResource IPhoneSteelBackground}">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Button Grid.Row="1" Grid.Column="0" BorderThickness="1" BorderBrush="Gray" CommandParameter="NUMPAD7" >7</Button>
<Button Grid.Row="1" Grid.Column="1" CommandParameter="NUMPAD8" BorderThickness="1" Content="8" />
<Button Grid.Row="1" Grid.Column="2" CommandParameter="NUMPAD9" Content="9" />
<Button Grid.Row="1" Grid.Column="3" CommandParameter="BACK" >
<Path Stretch="Fill" Width="36" Height="24" Data="F1M555.0371,274.4893L552.7871,276.7383L549.9861,273.9373L547.1991,276.7243L545.1131,274.6393L547.9001,271.8523L545.0101,268.9603L547.2601,266.7113L550.1501,269.6023L552.8921,266.8613L554.9761,268.9463L552.2361,271.6883z M555.3751,264.0003L544.8751,264.0003C543.1251,264.1253,535.0001,270.7503,535.0001,272.2503C535.0001,273.7503,543.1251,279.3753,544.8751,279.5003L555.3751,279.5003C558.8751,279.5003,559.3751,277.7093,559.3751,275.5003L559.3751,268.0003C559.3751,265.7913,558.7501,264.0003,555.3751,264.0003" Fill="#FF333333"/>
</Button>
<Button Grid.Row="2" Grid.Column="0" x:Name="button9" CommandParameter="NUMPAD4" Content="4"/>
<Button Grid.Row="2" Grid.Column="1" CommandParameter="NUMPAD5" Content="5" />
<Button Grid.Row="2" Grid.Column="2" CommandParameter="NUMPAD6" Content="6" />
<Button Grid.Row="3" Grid.Column="0" CommandParameter="NUMPAD1" Content="1"/>
<Button Grid.Row="3" Grid.Column="1" CommandParameter="NUMPAD2" Content="2"/>
<Button Grid.Row="3" Grid.Column="2" CommandParameter="NUMPAD3" Content="3" />
<Button Grid.Row="2" Grid.Column="3" Grid.RowSpan="3" CommandParameter="RETURN" Content="Enter"/>
<Button Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2" CommandParameter="NUMPAD0" Content="0" />
<Button Grid.Row="4" Grid.Column="2" CommandParameter="DECIMAL" Content="." />
<Label Grid.Column="0" Grid.ColumnSpan="4" Content="{Binding Result}" HorizontalContentAlignment="Right" Background="WhiteSmoke" Margin="4"/>
</Grid>
</Window>

+ 69
- 0
WinFormControl/NumberPad.xaml.cs View File

@ -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));
}
}
}
}

+ 36
- 0
WinFormControl/Properties/AssemblyInfo.cs View File

@ -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")]

+ 355
- 0
WinFormControl/VirtualKeyPad.xaml View File

@ -0,0 +1,355 @@
<Window x:Class="WinFormControl.VirtualKeyPad"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:converter="clr-namespace:WinFormControl.Converter"
Height="350" Width="1000" x:Name="Keyboard" WindowStartupLocation="CenterScreen" ShowInTaskbar="False" Title="键盘">
<Window.Resources>
<converter:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter"/>
<LinearGradientBrush x:Key="IPhoneSteelBackground" EndPoint="0.5,1.272" StartPoint="0.5,0">
<GradientStop Color="#FF9097A3" Offset="0"/>
<GradientStop Color="#FF444D5B" Offset="1"/>
</LinearGradientBrush>
<DropShadowEffect x:Key="DropShadowEffect" ShadowDepth="1" Direction="-90" BlurRadius="3" />
<Style TargetType="Button">
<EventSetter Event="Click" Handler="button_Click" />
<Setter Property="Margin" Value="4"/>
<Setter Property="Button.Effect" Value="{StaticResource DropShadowEffect}"/>
<Setter Property="FontSize" Value="22"/>
<Setter Property="Background" Value="WhiteSmoke"/>
<Setter Property="RenderTransform">
<Setter.Value>
<!-- Workaround for ATI video cards that don't render good with dropshadoweffect-->
<RotateTransform Angle="0.00000000001"/>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="ToggleButton">
<Setter Property="ClickMode" Value="Press"/>
<Setter Property="Margin" Value="4"/>
<Setter Property="Background" Value="WhiteSmoke"/>
<Setter Property="Button.Effect" Value="{StaticResource DropShadowEffect}"/>
<Setter Property="FontSize" Value="22"/>
<Setter Property="RenderTransform">
<Setter.Value>
<!-- Workaround for ATI video cards that don't render good with dropshadoweffect-->
<RotateTransform Angle="0.00000000001"/>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="Label">
<Setter Property="Label.Effect" Value="{StaticResource DropShadowEffect}"/>
<Setter Property="FontSize" Value="22"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="RenderTransform">
<Setter.Value>
<!-- Workaround for ATI video cards that don't render good with dropshadoweffect-->
<RotateTransform Angle="0.00000000001"/>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="{DynamicResource IPhoneSteelBackground}" >
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Button Grid.Column="0" CommandParameter="ESC" Content="Esc" Height="50" Width="80" IsCancel="True"/>
<Label Content="{Binding Result, ElementName=Keyboard }" Background="WhiteSmoke" BorderBrush="Gray" BorderThickness="1" Grid.Column="1" Margin="5,5,5,5" FontSize="18" HorizontalAlignment="Stretch"/>
</Grid>
<Grid Grid.Row="1" VerticalAlignment="Stretch" x:Name="AlfaKeyboard" Background="{DynamicResource IPhoneSteelBackground}" >
<Grid.RowDefinitions>
<RowDefinition Height="0" />
<RowDefinition x:Name="NumberKeys" Height="0"/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0"/>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition Width="0"/>
<ColumnDefinition Width="0"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Button Grid.Column="1" CommandParameter="q" Content="q"/>
<Button Grid.Column="2" CommandParameter="w" Content="w"/>
<Button Grid.Column="3" CommandParameter="e" Content="e"/>
<Button Grid.Column="4" CommandParameter="r" Content="r"/>
<Button Grid.Column="5" CommandParameter="t" Content="t"/>
<Button Grid.Column="6" CommandParameter="y" Content="y"/>
<Button Grid.Column="7" CommandParameter="u" Content="u"/>
<Button Grid.Column="8" CommandParameter="i" Content="i"/>
<Button Grid.Column="9" CommandParameter="o" Content="o"/>
<Button Grid.Column="10" CommandParameter="p" Content="p"/>
<Button Grid.Column="13" CommandParameter="BACK">
<Path Stretch="Fill" Width="36" Height="24" Data="F1M555.0371,274.4893L552.7871,276.7383L549.9861,273.9373L547.1991,276.7243L545.1131,274.6393L547.9001,271.8523L545.0101,268.9603L547.2601,266.7113L550.1501,269.6023L552.8921,266.8613L554.9761,268.9463L552.2361,271.6883z M555.3751,264.0003L544.8751,264.0003C543.1251,264.1253,535.0001,270.7503,535.0001,272.2503C535.0001,273.7503,543.1251,279.3753,544.8751,279.5003L555.3751,279.5003C558.8751,279.5003,559.3751,277.7093,559.3751,275.5003L559.3751,268.0003C559.3751,265.7913,558.7501,264.0003,555.3751,264.0003" Fill="#FF333333"></Path>
</Button>
</Grid>
<Grid Grid.Row="3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.3*"/>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition Width="0"/>
<ColumnDefinition Width="0"/>
<ColumnDefinition Width="1.55*"/>
</Grid.ColumnDefinitions>
<Button Grid.Column="1" CommandParameter="a" Content="a"/>
<Button Grid.Column="2" CommandParameter="s" Content="s"/>
<Button Grid.Column="3" CommandParameter="d" Content="d"/>
<Button Grid.Column="4" CommandParameter="f" Content="f"/>
<Button Grid.Column="5" CommandParameter="g" Content="g"/>
<Button Grid.Column="6" CommandParameter="h" Content="h"/>
<Button Grid.Column="7" CommandParameter="j" Content="j"/>
<Button Grid.Column="8" CommandParameter="k" Content="k"/>
<Button Grid.Column="9" CommandParameter="l" Content="l"/>
<Button Grid.Column="12" CommandParameter="RETURN" HorizontalContentAlignment="Right" Padding="10">
<StackPanel Orientation="Horizontal">
<TextBlock Text="Return "/>
<TextBlock Text="8 " FontFamily="Wingdings 3" TextAlignment="Center" />
</StackPanel>
</Button>
</Grid>
<Grid Grid.Row="4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="0"/>
<ColumnDefinition Width="1.1*"/>
</Grid.ColumnDefinitions>
<Button Grid.Column="0" CommandParameter="LSHIFT">
<Path Fill="#FF333333" Stretch="Fill" Width="28" Height="24" Data="F1M269.5,262C269.026,262,268.552,262.168,268.171,262.505L259.671,270.505C259.05,271.057,258.835,271.935,259.131,272.71C259.425,273.487,260.169,274,261,274L265,274L265,278C265,279.104,265.896,280,267,280L272,280C273.104,280,274,279.104,274,278L274,274L278,274C278.81,274,279.538,273.513,279.849,272.766C280.157,272.018,279.986,271.158,279.415,270.585L270.914,262.586C270.524,262.197,270.013,262,269.5,262 M269.5,264L278,272L272,272L272,278L267,278L267,272L261,272L269.5,264"/>
</Button>
<Button Grid.Column="1" CommandParameter="z" Content="z"/>
<Button Grid.Column="2" CommandParameter="x" Content="x"/>
<Button Grid.Column="3" CommandParameter="c" Content="c"/>
<Button Grid.Column="4" CommandParameter="v" Content="v"/>
<Button Grid.Column="5" CommandParameter="b" Content="b"/>
<Button Grid.Column="6" CommandParameter="n" Content="n"/>
<Button Grid.Column="7" CommandParameter="m" Content="m"/>
<Button Grid.Column="8" CommandParameter="," Content=","/>
<Button Grid.Column="9" CommandParameter="." Content="."/>
<Button Grid.Column="11" CommandParameter="-" Content="-"/>
</Grid>
<Grid Grid.Row="5">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition Width="5*" />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<ToggleButton IsChecked="{Binding ShowNumericKeyboard, ElementName=Keyboard}" Grid.Column="0" Grid.ColumnSpan="2" ClickMode="Press" Content=".?123" />
<Button Grid.Column="2" CommandParameter="CTRL" Content="Ctrl" />
<!-- wingdings Windows Logo: ÿ -->
<!-- wingdings apple cmd key: z -->
<Button Grid.Column="3" CommandParameter="SPACE" Content=" "/>
<Button Grid.Column="4" CommandParameter="ALT" Content="Alt" />
<ToggleButton IsChecked="{Binding ShowNumericKeyboard, ElementName=Keyboard}" Grid.Column="5" Grid.ColumnSpan="2" Command="{Binding Path=PressAndHold}" CommandParameter="IGNORE" Content=".?123" />
</Grid>
</Grid>
<!--<Grid Grid.Row="1" x:Name="NumKeyboard" Background="{DynamicResource IPhoneSteelBackground}" Margin="0,0,0,0" Visibility="Collapsed" >-->
<Grid Grid.Row="1" x:Name="NumKeyboard" Background="{DynamicResource IPhoneSteelBackground}" Margin="0,0,0,0" Visibility="{Binding ShowNumericKeyboard, ElementName=Keyboard, Converter={StaticResource BoolToVisibilityConverter}}" >
<Grid.RowDefinitions>
<RowDefinition Height="0"/>
<RowDefinition />
<RowDefinition/>
<RowDefinition Height="0"/>
<RowDefinition/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition Width="0"/>
<ColumnDefinition Width="0"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Button Grid.Column="0" CommandParameter="_1" Content="1"/>
<Button Grid.Column="1" CommandParameter="_2" Content="2"/>
<Button Grid.Column="2" CommandParameter="_3" Content="3"/>
<Button Grid.Column="3" CommandParameter="_4" Content="4"/>
<Button Grid.Column="4" CommandParameter="_5" Content="5"/>
<Button Grid.Column="5" CommandParameter="_6" Content="6"/>
<Button Grid.Column="6" CommandParameter="_7" Content="7"/>
<Button Grid.Column="7" CommandParameter="_8" Content="8" />
<Button Grid.Column="8" CommandParameter="_9" Content="9"/>
<Button Grid.Column="9" CommandParameter="_0" Content="0"/>
<Button Grid.Column="13" CommandParameter="BACK" >
<Path Stretch="Fill" Width="36" Height="24" Data="F1M555.0371,274.4893L552.7871,276.7383L549.9861,273.9373L547.1991,276.7243L545.1131,274.6393L547.9001,271.8523L545.0101,268.9603L547.2601,266.7113L550.1501,269.6023L552.8921,266.8613L554.9761,268.9463L552.2361,271.6883z M555.3751,264.0003L544.8751,264.0003C543.1251,264.1253,535.0001,270.7503,535.0001,272.2503C535.0001,273.7503,543.1251,279.3753,544.8751,279.5003L555.3751,279.5003C558.8751,279.5003,559.3751,277.7093,559.3751,275.5003L559.3751,268.0003C559.3751,265.7913,558.7501,264.0003,555.3751,264.0003" Fill="#FF333333"/>
</Button>
</Grid>
<Grid Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.3*"/>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition Width="0"/>
<ColumnDefinition Width="0"/>
<ColumnDefinition Width="1.55*"/>
</Grid.ColumnDefinitions>
<Button Grid.Column="1" CommandParameter="Q" Content="-"/>
<Button Grid.Column="2" CommandParameter="W" Content="/"/>
<Button Grid.Column="3" CommandParameter="E" Content=":"/>
<Button Grid.Column="4" CommandParameter="R" Content=";"/>
<Button Grid.Column="5" CommandParameter="T" Content="(" />
<Button Grid.Column="6" CommandParameter="Y" Content=")"/>
<Button Grid.Column="7" CommandParameter="U" Content="$"/>
<Button Grid.Column="8" CommandParameter="I" Content="&amp;"/>
<Button Grid.Column="9" CommandParameter="O" Content="@"/>
<Button Grid.Column="10" CommandParameter="P" Content="&quot;"/>
<Button Grid.Column="12" CommandParameter="RETURN" HorizontalContentAlignment="Right" Padding="10">
<StackPanel Orientation="Horizontal">
<TextBlock Text="Return "/>
<TextBlock Text="8 " FontFamily="Wingdings 3" TextAlignment="Center" />
</StackPanel>
</Button>
</Grid>
<!--<Grid Grid.Row="3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.3*"/>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition Width="0"/>
<ColumnDefinition Width="0"/>
<ColumnDefinition Width="1.55*"/>
</Grid.ColumnDefinitions>
<Button Grid.Column="1" CommandParameter="A" Content="A"/>
<Button Grid.Column="2" CommandParameter="S" Content="S"/>
<Button Grid.Column="3" CommandParameter="D" Content="D"/>
<Button Grid.Column="4" CommandParameter="F" Content="F"/>
<Button Grid.Column="5" CommandParameter="G" Content="G"/>
<Button Grid.Column="6" CommandParameter="H" Content="H"/>
<Button Grid.Column="7" CommandParameter="J" Content="J"/>
<Button Grid.Column="8" CommandParameter="K" Content="K"/>
<Button Grid.Column="9" CommandParameter="L" Content="L"/>
<Button Grid.Column="12" CommandParameter="RETURN" Content="return" HorizontalContentAlignment="Right" Padding="10"/>-->
<!--</Grid>-->
<Grid Grid.Row="4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="0"/>
<ColumnDefinition Width="1.1*"/>
</Grid.ColumnDefinitions>
<Button Grid.Column="0" Command="{Binding Path=PressAndHold}" CommandParameter="LSHIFT">
<Path Fill="#FF333333" Stretch="Fill" Width="28" Height="24" Data="F1M269.5,262C269.026,262,268.552,262.168,268.171,262.505L259.671,270.505C259.05,271.057,258.835,271.935,259.131,272.71C259.425,273.487,260.169,274,261,274L265,274L265,278C265,279.104,265.896,280,267,280L272,280C273.104,280,274,279.104,274,278L274,274L278,274C278.81,274,279.538,273.513,279.849,272.766C280.157,272.018,279.986,271.158,279.415,270.585L270.914,262.586C270.524,262.197,270.013,262,269.5,262 M269.5,264L278,272L272,272L272,278L267,278L267,272L261,272L269.5,264"/>
</Button>
<Button Grid.Column="1" CommandParameter="Z" Content="."/>
<Button Grid.Column="2" CommandParameter="X" Content=","/>
<Button Grid.Column="3" CommandParameter="C" Content="?"/>
<Button Grid.Column="4" CommandParameter="B" Content="'"/>
<Button Grid.Column="5" CommandParameter="N" Content="="/>
<Button Grid.Column="6" CommandParameter="M" Content="+"/>
<Button Grid.Column="7" CommandParameter="OEM_COMMA" >*</Button>
<Button Grid.Column="8" CommandParameter="OEM_PERIOD" >\</Button>
<Button Grid.Column="9" CommandParameter="OEM_PERIOD" >[</Button>
<Button Grid.Column="11" CommandParameter="OEM_PERIOD" >]</Button>
</Grid>
<Grid Grid.Row="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="0"/>
<ColumnDefinition Width="0"/>
<ColumnDefinition Width="5*" />
<ColumnDefinition Width="0"/>
<ColumnDefinition Width="0"/>
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>
<Button Grid.Column="0" CommandParameter="RSHIFT" Content=".?123" />
<Button Grid.Column="1" CommandParameter="LCONTROL" Content="Ctrl" />
<Button Grid.Column="2" CommandParameter="LWIN" FontFamily="WingDings">
z</Button>
<!-- wingdings Windows Logo: ÿ -->
<!-- wingdings apple cmd key: z -->
<ToggleButton IsChecked="{Binding ShowNumericKeyboard, ElementName=Keyboard}" CommandParameter="IGNORE" Grid.Column="0" ClickMode="Press" Content="ABC" />
<Button Grid.Column="3" CommandParameter="SPACE" Content=" "/>
<Button Grid.Column="4" CommandParameter="MENU" Content="Alt" />
<Button Grid.Column="5" CommandParameter="LMENU" Content="Menu" />
<ToggleButton IsChecked="{Binding ShowNumericKeyboard, ElementName=Keyboard}" CommandParameter="IGNORE" Grid.Column="6" ClickMode="Press" Content="ABC" />
</Grid>
</Grid>
<!--<Image HorizontalAlignment="Left" Margin="-450,0,0,-377" Width="163" Stretch="Fill" VerticalAlignment="Bottom" Height="342" Grid.Row="1"/>-->
</Grid>
<!--<CheckBox Canvas.Left="894.223" Canvas.Top="17.02" Height="16.665" Name="checkBox1" Width="17.845" IsChecked="{Binding Source={DynamicResource virtualKeyboard}, Path=Shift, Mode=TwoWay, NotifyOnTargetUpdated=True}"></CheckBox>-->
</Window>

+ 104
- 0
WinFormControl/VirtualKeyPad.xaml.cs View File

@ -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
{
/// <summary>
/// VirtualKeyPad.xaml 的交互逻辑
/// </summary>
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));
}
}
}

+ 77
- 0
WinFormControl/WinFormControl.csproj View File

@ -0,0 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{45A6C56B-C815-4AEA-B0C4-68C122FD3139}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>WinFormControl</RootNamespace>
<AssemblyName>WinFormControl</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Windows" />
<Reference Include="System.Xaml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="ControlUtil.cs" />
<Compile Include="NumberPad.xaml.cs">
<DependentUpon>NumberPad.xaml</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="VirtualKeyPad.xaml.cs">
<DependentUpon>VirtualKeyPad.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<Folder Include="Images\" />
</ItemGroup>
<ItemGroup>
<Page Include="NumberPad.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="VirtualKeyPad.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

Loading…
Cancel
Save