6 changed files with 419 additions and 0 deletions
@ -0,0 +1,132 @@ |
|||
<Window x:Class="DyeingComputer.Windows.TouchKeyboard" |
|||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
|||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
|||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
|||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
|||
xmlns:local="clr-namespace:DyeingComputer.Windows" |
|||
mc:Ignorable="d" WindowStyle="None" ResizeMode="NoResize" Topmost="True" |
|||
WindowStartupLocation="CenterScreen" |
|||
Title="TouchKeyboard" Height="500" Width="750"> |
|||
<Window.Resources> |
|||
<Style x:Key="KeyButtonStyle" TargetType="Button"> |
|||
<Setter Property="Background" Value="#FFF0F0F0"/> |
|||
<Setter Property="BorderBrush" Value="#FFCCCCCC"/> |
|||
<Setter Property="BorderThickness" Value="1"/> |
|||
<Setter Property="FontSize" Value="20"/> |
|||
<Setter Property="FontWeight" Value="Bold"/> |
|||
<Setter Property="Margin" Value="2"/> |
|||
<Setter Property="MinWidth" Value="60"/> |
|||
<Setter Property="MinHeight" Value="40"/> |
|||
<Setter Property="Template"> |
|||
<Setter.Value> |
|||
<ControlTemplate TargetType="Button"> |
|||
<Border x:Name="border" |
|||
Background="{TemplateBinding Background}" |
|||
BorderBrush="{TemplateBinding BorderBrush}" |
|||
BorderThickness="{TemplateBinding BorderThickness}" |
|||
CornerRadius="4"> |
|||
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/> |
|||
</Border> |
|||
<ControlTemplate.Triggers> |
|||
<Trigger Property="IsPressed" Value="True"> |
|||
<Setter Property="Background" Value="#FFDDDDDD"/> |
|||
</Trigger> |
|||
</ControlTemplate.Triggers> |
|||
</ControlTemplate> |
|||
</Setter.Value> |
|||
</Setter> |
|||
</Style> |
|||
|
|||
<Style x:Key="SpecialKeyButtonStyle" BasedOn="{StaticResource KeyButtonStyle}" TargetType="Button"> |
|||
<Setter Property="Background" Value="#FFE0E0E0"/> |
|||
<Setter Property="FontSize" Value="16"/> |
|||
</Style> |
|||
</Window.Resources> |
|||
|
|||
<Grid> |
|||
<Grid.RowDefinitions> |
|||
<RowDefinition Height="Auto"/> |
|||
<RowDefinition Height="*"/> |
|||
<RowDefinition Height="Auto"/> |
|||
</Grid.RowDefinitions> |
|||
|
|||
<!-- 预览区域 --> |
|||
<TextBox x:Name="PreviewTextBox" Grid.Row="0" Height="60" Margin="10" |
|||
FontSize="24" VerticalContentAlignment="Center" IsReadOnly="False"/> |
|||
|
|||
<!-- 键盘主体区域 --> |
|||
<Grid Grid.Row="1" Margin="10"> |
|||
<Grid.RowDefinitions> |
|||
<RowDefinition Height="*"/> |
|||
<RowDefinition Height="*"/> |
|||
<RowDefinition Height="*"/> |
|||
<RowDefinition Height="*"/> |
|||
</Grid.RowDefinitions> |
|||
|
|||
<!-- 数字行 --> |
|||
<StackPanel Orientation="Horizontal" Grid.Row="0" HorizontalAlignment="Center"> |
|||
<Button Content="1" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="2" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="3" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="4" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="5" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="6" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="7" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="8" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="9" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="0" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="DEL" Style="{StaticResource SpecialKeyButtonStyle}" Click="Backspace_Click" Width="60"/> |
|||
</StackPanel> |
|||
|
|||
<!-- 第一行字母 --> |
|||
<StackPanel Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Center"> |
|||
<Button Content="Q" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="W" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="E" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="R" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="T" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="Y" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="U" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="I" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="O" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="P" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
</StackPanel> |
|||
|
|||
<!-- 第二行字母 --> |
|||
<StackPanel Orientation="Horizontal" Grid.Row="2" HorizontalAlignment="Center"> |
|||
<Button Content="A" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="S" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="D" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="F" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="G" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="H" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="J" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="K" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="L" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="/" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="HIDE" Style="{StaticResource SpecialKeyButtonStyle}" Click="Hide_Click" Width="60"/> |
|||
</StackPanel> |
|||
|
|||
<!-- 第三行字母 --> |
|||
<StackPanel Orientation="Horizontal" Grid.Row="3" HorizontalAlignment="Center"> |
|||
<Button x:Name="ShiftButton" Content="⇧" Style="{StaticResource SpecialKeyButtonStyle}" Click="Shift_Click" Width="60"/> |
|||
<Button Content="Z" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="X" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="C" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="V" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="B" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="N" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="M" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="." Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="ENTER" Style="{StaticResource SpecialKeyButtonStyle}" Click="Enter_Click" Width="120"/> |
|||
</StackPanel> |
|||
</Grid> |
|||
|
|||
<!-- 状态栏 --> |
|||
<StatusBar Grid.Row="2"> |
|||
<StatusBarItem> |
|||
<TextBlock x:Name="StatusTextBlock" Text="就绪"/> |
|||
</StatusBarItem> |
|||
</StatusBar> |
|||
</Grid> |
|||
</Window> |
@ -0,0 +1,105 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
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.Shapes; |
|||
|
|||
namespace DyeingComputer.Windows |
|||
{ |
|||
/// <summary>
|
|||
/// TouchKeyboard.xaml 的交互逻辑
|
|||
/// </summary>
|
|||
public partial class TouchKeyboard : Window |
|||
{ |
|||
private bool isShiftActive = false; |
|||
private bool isSymbolActive = false; |
|||
public string KeyValue; |
|||
|
|||
public TouchKeyboard() |
|||
{ |
|||
InitializeComponent(); |
|||
} |
|||
|
|||
private void KeyButton_Click(object sender, RoutedEventArgs e) |
|||
{ |
|||
Button button = sender as Button; |
|||
if (button != null) |
|||
{ |
|||
string key = button.Content.ToString(); |
|||
|
|||
if (key.Length == 1 && char.IsLetter(key[0])) |
|||
{ |
|||
key = isShiftActive ? key.ToUpper() : key.ToLower(); |
|||
} |
|||
|
|||
PreviewTextBox.Text += key; |
|||
|
|||
// 输入后关闭Shift状态
|
|||
if (isShiftActive) |
|||
{ |
|||
isShiftActive = false; |
|||
UpdateButtonAppearance(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
private void Shift_Click(object sender, RoutedEventArgs e) |
|||
{ |
|||
isShiftActive = !isShiftActive; |
|||
UpdateButtonAppearance(); |
|||
} |
|||
|
|||
private void Symbol_Click(object sender, RoutedEventArgs e) |
|||
{ |
|||
isSymbolActive = !isSymbolActive; |
|||
// 这里可以添加切换符号键盘的逻辑
|
|||
StatusTextBlock.Text = isSymbolActive ? "符号模式" : "字母模式"; |
|||
} |
|||
|
|||
private void Space_Click(object sender, RoutedEventArgs e) |
|||
{ |
|||
PreviewTextBox.Text += " "; |
|||
} |
|||
|
|||
private void Backspace_Click(object sender, RoutedEventArgs e) |
|||
{ |
|||
if (!string.IsNullOrEmpty(PreviewTextBox.Text)) |
|||
{ |
|||
PreviewTextBox.Text = PreviewTextBox.Text.Substring(0, PreviewTextBox.Text.Length - 1); |
|||
} |
|||
} |
|||
|
|||
private void Enter_Click(object sender, RoutedEventArgs e) |
|||
{ |
|||
KeyValue = PreviewTextBox.Text; |
|||
this.Close(); |
|||
// PreviewTextBox.Text += Environment.NewLine;
|
|||
} |
|||
|
|||
private void Hide_Click(object sender, RoutedEventArgs e) |
|||
{ |
|||
this.Close(); |
|||
} |
|||
|
|||
private void UpdateButtonAppearance() |
|||
{ |
|||
// 更新Shift按钮的外观以反映当前状态
|
|||
if (isShiftActive) |
|||
{ |
|||
ShiftButton.Background = new SolidColorBrush(Colors.LightBlue); |
|||
} |
|||
else |
|||
{ |
|||
ShiftButton.Background = new SolidColorBrush(Color.FromRgb(224, 224, 224)); |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,99 @@ |
|||
<Window x:Class="DyeingComputer.Windows.TouchKeyboardNumeral" |
|||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
|||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
|||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
|||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
|||
xmlns:local="clr-namespace:DyeingComputer.Windows" |
|||
mc:Ignorable="d" WindowStyle="None" ResizeMode="NoResize" Topmost="True" |
|||
WindowStartupLocation="CenterScreen" |
|||
Title="TouchKeyboardNumeral" Height="500" Width="550"> |
|||
<Window.Resources> |
|||
<Style x:Key="KeyButtonStyle" TargetType="Button"> |
|||
<Setter Property="Background" Value="#FFF0F0F0"/> |
|||
<Setter Property="BorderBrush" Value="#FFCCCCCC"/> |
|||
<Setter Property="BorderThickness" Value="1"/> |
|||
<Setter Property="FontSize" Value="20"/> |
|||
<Setter Property="FontWeight" Value="Bold"/> |
|||
<Setter Property="Margin" Value="2"/> |
|||
<Setter Property="MinWidth" Value="100"/> |
|||
<Setter Property="MinHeight" Value="40"/> |
|||
<Setter Property="Template"> |
|||
<Setter.Value> |
|||
<ControlTemplate TargetType="Button"> |
|||
<Border x:Name="border" |
|||
Background="{TemplateBinding Background}" |
|||
BorderBrush="{TemplateBinding BorderBrush}" |
|||
BorderThickness="{TemplateBinding BorderThickness}" |
|||
CornerRadius="4"> |
|||
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/> |
|||
</Border> |
|||
<ControlTemplate.Triggers> |
|||
<Trigger Property="IsPressed" Value="True"> |
|||
<Setter Property="Background" Value="#FFDDDDDD"/> |
|||
</Trigger> |
|||
</ControlTemplate.Triggers> |
|||
</ControlTemplate> |
|||
</Setter.Value> |
|||
</Setter> |
|||
</Style> |
|||
|
|||
<Style x:Key="SpecialKeyButtonStyle" BasedOn="{StaticResource KeyButtonStyle}" TargetType="Button"> |
|||
<Setter Property="Background" Value="#FFE0E0E0"/> |
|||
<Setter Property="FontSize" Value="16"/> |
|||
</Style> |
|||
</Window.Resources> |
|||
|
|||
<Grid> |
|||
<Grid.RowDefinitions> |
|||
<RowDefinition Height="Auto"/> |
|||
<RowDefinition Height="*"/> |
|||
<RowDefinition Height="Auto"/> |
|||
</Grid.RowDefinitions> |
|||
|
|||
<!-- 预览区域 --> |
|||
<TextBox x:Name="PreviewTextBox" Grid.Row="0" Height="60" Margin="10" |
|||
FontSize="24" VerticalContentAlignment="Center" IsReadOnly="False"/> |
|||
|
|||
<!-- 键盘主体区域 --> |
|||
<Grid Grid.Row="1" Margin="10"> |
|||
<Grid.RowDefinitions> |
|||
<RowDefinition Height="*"/> |
|||
<RowDefinition Height="*"/> |
|||
<RowDefinition Height="*"/> |
|||
</Grid.RowDefinitions> |
|||
|
|||
<!-- 数字行 --> |
|||
<StackPanel Orientation="Horizontal" Grid.Row="0" HorizontalAlignment="Center"> |
|||
<Button Content="7" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="8" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="9" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="0" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="DEL" Style="{StaticResource SpecialKeyButtonStyle}" Click="Backspace_Click" Width="60"/> |
|||
</StackPanel> |
|||
|
|||
<!-- 第一行字母 --> |
|||
<StackPanel Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Center"> |
|||
<Button Content="4" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="5" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="6" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="." Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="HIDE" Style="{StaticResource SpecialKeyButtonStyle}" Click="Hide_Click" Width="60"/> |
|||
</StackPanel> |
|||
|
|||
<!-- 第二行字母 --> |
|||
<StackPanel Orientation="Horizontal" Grid.Row="2" HorizontalAlignment="Center"> |
|||
<Button Content="1" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="2" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="3" Style="{StaticResource KeyButtonStyle}" Click="KeyButton_Click"/> |
|||
<Button Content="ENTER" Style="{StaticResource SpecialKeyButtonStyle}" Click="Enter_Click" Width="200"/> |
|||
</StackPanel> |
|||
</Grid> |
|||
|
|||
<!-- 状态栏 --> |
|||
<StatusBar Grid.Row="2"> |
|||
<StatusBarItem> |
|||
<TextBlock x:Name="StatusTextBlock" Text="就绪"/> |
|||
</StatusBarItem> |
|||
</StatusBar> |
|||
</Grid> |
|||
</Window> |
@ -0,0 +1,68 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
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.Shapes; |
|||
|
|||
namespace DyeingComputer.Windows |
|||
{ |
|||
/// <summary>
|
|||
/// TouchKeyboard.xaml 的交互逻辑
|
|||
/// </summary>
|
|||
public partial class TouchKeyboardNumeral : Window |
|||
{ |
|||
private bool isShiftActive = false; |
|||
private bool isSymbolActive = false; |
|||
public string KeyValue; |
|||
|
|||
public TouchKeyboardNumeral() |
|||
{ |
|||
InitializeComponent(); |
|||
} |
|||
|
|||
private void KeyButton_Click(object sender, RoutedEventArgs e) |
|||
{ |
|||
Button button = sender as Button; |
|||
if (button != null) |
|||
{ |
|||
string key = button.Content.ToString(); |
|||
|
|||
if (key.Length == 1 && char.IsLetter(key[0])) |
|||
{ |
|||
key = isShiftActive ? key.ToUpper() : key.ToLower(); |
|||
} |
|||
|
|||
PreviewTextBox.Text += key; |
|||
} |
|||
} |
|||
|
|||
private void Backspace_Click(object sender, RoutedEventArgs e) |
|||
{ |
|||
if (!string.IsNullOrEmpty(PreviewTextBox.Text)) |
|||
{ |
|||
PreviewTextBox.Text = PreviewTextBox.Text.Substring(0, PreviewTextBox.Text.Length - 1); |
|||
} |
|||
} |
|||
|
|||
private void Enter_Click(object sender, RoutedEventArgs e) |
|||
{ |
|||
KeyValue = PreviewTextBox.Text; |
|||
this.Close(); |
|||
// PreviewTextBox.Text += Environment.NewLine;
|
|||
} |
|||
|
|||
private void Hide_Click(object sender, RoutedEventArgs e) |
|||
{ |
|||
this.Close(); |
|||
} |
|||
|
|||
} |
|||
} |
Loading…
Reference in new issue