我正在研究一个问题,其中触摸屏控件在自制数字键盘上的行为异常。此数字键盘有两种变体,一种是密码框,另一种是用于普通(可见)数字输入的。
该项目本身非常复杂,正在使用许多不同的窗口。
从主窗口中调用密码窗口和数字窗口时,它们的功能都很好,但是,从程序下方的窗口中调用数字键盘(或密码框,我尝试过两者)时,情况会有所改善。 。
在Windows 10(开发PC)和Windows 7(活动PC)上会出现问题。
问题描述:
当尝试按下按钮时,按钮单击事件似乎没有响应。 反复点击它们后,这些按钮最终将开始按预期起作用。一旦按钮起作用,它们将保持起作用,直到关闭窗口。由于时间,动作,...
使用鼠标时,窗口运行良好。
我需要使用触摸板和鼠标才能使程序正常运行(当然,不能同时使用)。
我尝试过的方法:
这有效,但对于触摸屏仅。按钮仍然没有积极反应,但是触地事件背后的代码按预期运行。
但是,这会中断鼠标的使用。
非常适合鼠标,适用于触摸屏... 直到触摸屏在每个按下的按钮上触发两次为止。然后,触摸屏既触发TouchDown事件,又触发MouseLeftButtonDown事件。与以前相同,一旦开始触发两次,它将继续触发两次。
与默认的Button单击事件完全相同。触摸屏只有在正常工作后才能正常工作,一旦正常工作就可以正常工作。
将此视为解决类似问题(尽管问题不同)的解决方案,但最终没有解决任何事情。
与原始情况相同。
什么都没改变。
代码:
设计器:
<Window x:Class="NumericKeyPad"
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:REDACTEDNAME"
mc:Ignorable="d"
Title="NumericKeyPad" Height="400" Width="400">
<DockPanel Name="DockPanel" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" PreviewMouseLeftButtonDown="NumericKeyPad_MouseLeftButtonDown">
<Grid>
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
<Grid.RowDefinitions>
<RowDefinition Height="10*"></RowDefinition>
<RowDefinition Height="10*"></RowDefinition>
<RowDefinition Height="10*"></RowDefinition>
<RowDefinition Height="10*"></RowDefinition>
<RowDefinition Height="10*"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="73*"></ColumnDefinition>
<ColumnDefinition Width="7*"></ColumnDefinition>
<ColumnDefinition Width="66*"/>
<ColumnDefinition Width="73*"></ColumnDefinition>
<ColumnDefinition Width="73*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Name="Textblock" FontSize="24" HorizontalAlignment="Stretch" VerticalAlignment="Center" TextWrapping="Wrap" Text="" Margin="10,10,30,0" TextAlignment="Center" Grid.ColumnSpan="5"/>
<Button Content="1" FontSize="20" HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Grid.Row="1" Grid.Column="0" />
<Button Content="2" FontSize="20" HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2"/>
<Button Content="3" FontSize="20" HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Grid.Row="1" Grid.Column="3" />
<Button Content="4" FontSize="20" HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Grid.Row="2" Grid.Column="0" />
<Button Content="5" FontSize="20" HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2"/>
<Button Content="6" FontSize="20" HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Grid.Row="2" Grid.Column="3" />
<Button Content="7" FontSize="20" HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Grid.Row="3" Grid.Column="0" />
<Button Content="8" FontSize="20" HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="2"/>
<Button Content="9" FontSize="20" HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Grid.Row="3" Grid.Column="3" />
<Button Content="0" FontSize="20" HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="3" />
<Button Content="," FontSize="20" HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Grid.Row="4" Grid.Column="3" />
<Button Content="Back" FontSize="16" HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Grid.Row="1" Grid.Column="4" Grid.RowSpan="2" />
<Button Content="Enter" FontSize="16" HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Grid.Row="3" Grid.Column="4" Grid.RowSpan="2" />
</Grid>
</Grid>
</DockPanel>
代码:
Public Class NumericKeyPad
Public Property NewValue As String
Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
Try
Dim btn As Button = CType(sender, Button)
NewValue = NewValue + btn.Content.ToString()
Textblock.Text = NewValue
Catch ex As Exception
Worker.WriteLog("NumericKeyPad : Button_Click : " & ex.ToString(), "erro")
End Try
End Sub
Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs)
Try
Textblock.Text = NewValue
Catch ex As Exception
Worker.WriteLog("NumericKeyPad : Window_Loaded : " & ex.ToString(), "erro")
End Try
End Sub
Private Sub ButtonBack_Click(sender As Object, e As RoutedEventArgs)
Try
If (NewValue.Length > 0) Then
NewValue = NewValue.Substring(0, NewValue.Length - 1)
Textblock.Text = NewValue
End If
Catch ex As Exception
Worker.WriteLog("NumericKeyPad : ButtonBack_Click : " & ex.ToString(), "erro")
End Try
End Sub
Private Sub ButtonEnter_Click(sender As Object, e As RoutedEventArgs)
Try
Me.Close()
Catch ex As Exception
Worker.WriteLog("NumericKeyPad : ButtonEnter_Click : " & ex.ToString(), "erro")
End Try
End Sub
Private Sub Textblock_IsVisibleChanged(sender As Object, e As DependencyPropertyChangedEventArgs) Handles Textblock.IsVisibleChanged
Try
Textblock.Text = NewValue
Catch ex As Exception
Worker.WriteLog("NumericKeyPad : Textblock_IsVisibleChanged : " & ex.ToString(), "erro")
End Try
End Sub
Private Sub NumericKeyPad_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
Try
Me.Focus()
Catch ex As Exception
Worker.WriteLog("NumericKeyPad : NumericKeyPad_Loaded : " & ex.ToString(), "erro")
End Try
End Sub
Private Sub NumericKeyPad_TouchDown(sender As Object, e As TouchEventArgs) Handles Me.TouchDown
Try
Dim position As Point = e.GetTouchPoint(Me.DockPanel).Position
HandlePoint(position)
Catch ex As Exception
Worker.WriteLog("NumericKeyPad : NumericKeyPad_TouchDown : " & ex.ToString(), "erro")
End Try
End Sub
Private Sub NumericKeyPad_MouseLeftButtonDown(sender As Object, e As MouseButtonEventArgs)
'Try
' Dim position As Point = e.GetPosition(Me.DockPanel)
' HandlePoint(position)
'Catch ex As Exception
' Worker.WriteLog("NumericKeyPad : NumericKeyPad_MouseLeftButtonDown : " & ex.ToString(), "erro")
'End Try
End Sub
Private Sub HandlePoint(position As Point)
Try
Debug.WriteLine("position : " & position.X & " , " & position.Y)
'determine where the touch event happened
Dim place As String = ""
Dim width As Double = Me.DockPanel.ActualWidth
Dim height As Double = Me.DockPanel.ActualHeight
'determine row
Dim section As Double = height / 5.0
Dim sectionCol As Double = width / 4.0
Select Case True
Case position.Y >= 0 And position.Y <= section 'Row 0
place = "textfield"
Case position.Y > section And position.Y <= section * 2 '1-2-3-BACK
Select Case True
Case position.X >= 0 And position.X <= sectionCol 'Col 0
place = "1"
Case position.X > sectionCol And position.X <= sectionCol * 2 'Col 1
place = "2"
Case position.X > sectionCol * 2 And position.X <= sectionCol * 3 'Col 2
place = "3"
Case position.X > sectionCol * 3 And position.X <= sectionCol * 4 'Col 3
place = "bckspce"
End Select
Case position.Y > section * 2 And position.Y <= section * 3 '4-5-6-BACK
Select Case True
Case position.X >= 0 And position.X <= sectionCol
place = "4"
Case position.X > sectionCol And position.X <= sectionCol * 2
place = "5"
Case position.X > sectionCol * 2 And position.X <= sectionCol * 3
place = "6"
Case position.X > sectionCol * 3 And position.X <= sectionCol * 4
place = "bckspce"
End Select
Case position.Y > section * 3 And position.Y <= section * 4 '7-8-9-Ent
Select Case True
Case position.X >= 0 And position.X <= sectionCol
place = "7"
Case position.X > sectionCol And position.X <= sectionCol * 2
place = "8"
Case position.X > sectionCol * 2 And position.X <= sectionCol * 3
place = "9"
Case position.X > sectionCol * 3 And position.X <= sectionCol * 4
place = "entr"
End Select
Case position.Y > section * 4 And position.Y <= section * 5 'NULL-cma-Ent
Select Case True
Case position.X >= 0 And position.X <= sectionCol
place = "0"
Case position.X > sectionCol And position.X <= sectionCol * 2
place = "0"
Case position.X > sectionCol * 2 And position.X <= sectionCol * 3
place = "cmma"
Case position.X > sectionCol * 3 And position.X <= sectionCol * 4
place = "entr"
End Select
End Select
Select Case place
Case "0"
NewValue = NewValue + "0"
Textblock.Text = NewValue
Case "1"
NewValue = NewValue + "1"
Textblock.Text = NewValue
Case "2"
NewValue = NewValue + "2"
Textblock.Text = NewValue
Case "3"
NewValue = NewValue + "3"
Textblock.Text = NewValue
Case "4"
NewValue = NewValue + "4"
Textblock.Text = NewValue
Case "5"
NewValue = NewValue + "5"
Textblock.Text = NewValue
Case "6"
NewValue = NewValue + "6"
Textblock.Text = NewValue
Case "7"
NewValue = NewValue + "7"
Textblock.Text = NewValue
Case "8"
NewValue = NewValue + "8"
Textblock.Text = NewValue
Case "9"
NewValue = NewValue + "9"
Textblock.Text = NewValue
Case "entr"
Me.Close()
Case "bckspce"
If (NewValue.Length > 0) Then
NewValue = NewValue.Substring(0, NewValue.Length - 1)
Textblock.Text = NewValue
End If
Case "cmma"
NewValue = NewValue + ","
Textblock.Text = NewValue
Case Else
'Do nothing
End Select
Catch ex As Exception
Worker.WriteLog("NumericKeyPad : HandlePoint : " & ex.ToString(), "erro")
End Try
End Sub
有人对导致此问题的原因以及如何解决有任何线索吗?
预先感谢