如何创建屏幕键盘C#wpf

如何创建屏幕键盘C#wpf

本文介绍了如何创建屏幕键盘C#wpf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在为触摸应用程序实现屏幕键盘时遇到问题,我需要在wpf中使用usercontrol(用于拖拽目的),不会从其他输入中窃取焦点并保留它itselft总是排在最前面。



要做到这一点,我创建一个窗口白色{x:null}背景,我把usercontrol放在里面,然后我在开始时显示窗口应用程序和我可以查看顶部的键盘上的隐形窗口,我可以将键盘拖放到隐形窗口,唯一的问题是我不能防止从其他输入窃取焦点,所以我可以'使用键盘。



我希望你能帮助我。

抱歉我的英语不好。



谢谢!


$ b $bMatías



这是控件XAML,它只有3个按钮用于测试目的。

Hello everyone,
I have an issue implementing a screen keyboard for a touch app, i need an usercontrol (for dragabble purposes) in wpf that don't steal focus from others inputs and keep it itselft always on top.

To do that i create a window whit {x:null} background and i put the usercontrol inside, then i show the window in the start of the app and i can view the "invisible" window whit the keyboard allways on top, and i can drag and drop the keyboard over the invisible window, the only problem is that i cant prevent stealing focus from other inputs, so i can't use the keyboard.

I hope you can help me.
Sorry for my bad english.

Thanks!

Matías

Here is the control XAML, it only has 3 buttons for test purposes.

<UserControl x:Class="SuperCajero.TecladoCompleto"

             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" 

             mc:Ignorable="d"

             d:DesignHeight="200" d:DesignWidth="1024" Focusable="False">
    <Grid Width="1024" Height="200" removed="Green" Focusable="False">
        <Button Content="A" Height="35" HorizontalAlignment="Left" Margin="471,92,0,0" Name="btnA" VerticalAlignment="Top" Width="35"  Click="btnA_Click" Focusable="False"/>
        <Button Content="B" Height="35" HorizontalAlignment="Left" Margin="219,100,0,0" Name="btnB" VerticalAlignment="Top" Width="35"  Click="btnB_Click" Focusable="False"/>
        <Button Content="C" Height="35" HorizontalAlignment="Left" Margin="366,100,0,0" Name="btnC" VerticalAlignment="Top" Width="35"  Click="btnC_Click" Focusable="False"/>
    </Grid>
</UserControl>





以下是控件的C#代码,使其在辅助窗口内可拖动



Here is the C# code of the control that makes it draggable inside the auxiliar window

public partial class TecladoCompleto : UserControl
    {
        public TecladoCompleto()
        {
            InitializeComponent();
            MakeDraggable(this, this);
        }

        public void MakeDraggable(System.Windows.UIElement moveThisElement, System.Windows.UIElement movedByElement)
        {
            bool isMousePressed = false;
            System.Windows.Media.TranslateTransform transform = new System.Windows.Media.TranslateTransform(0, 0);
            moveThisElement.RenderTransform = transform;
            System.Windows.Point originalPoint = new System.Windows.Point(0, 0), currentPoint;

            movedByElement.MouseLeftButtonDown += (a, b) =>
            {
                isMousePressed = true;
                originalPoint = ((System.Windows.Input.MouseEventArgs)b).GetPosition(moveThisElement);
            };

            movedByElement.MouseLeftButtonUp += (a, b) => isMousePressed = false;
            movedByElement.MouseLeave += (a, b) => isMousePressed = false;
            movedByElement.MouseMove += (a, b) =>
            {
                if (!isMousePressed) return;

                currentPoint = ((System.Windows.Input.MouseEventArgs)b).GetPosition(moveThisElement);

                transform.X += currentPoint.X - originalPoint.X;
                transform.Y += currentPoint.Y - originalPoint.Y;
            };
        }

        private void btnA_Click(object sender, RoutedEventArgs e)
        {
            WindowsInput.InputSimulator.SimulateKeyDown(WindowsInput.VirtualKeyCode.VK_A);
        }

        private void btnB_Click(object sender, RoutedEventArgs e)
        {
            WindowsInput.InputSimulator.SimulateKeyDown(WindowsInput.VirtualKeyCode.VK_B);
        }

        private void btnC_Click(object sender, RoutedEventArgs e)
        {
            WindowsInput.InputSimulator.SimulateKeyDown(WindowsInput.VirtualKeyCode.VK_C);
        }
    }





这是拥有用户控件的辅助透明窗口



Here is the auxiliar transparent window that owns the usercontrol

<Window x:Class="SuperCajero.AuxWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        xmlns:controls="clr-namespace:SuperCajero"

        Title="AuxWindow" WindowStyle="None" Topmost="True" AllowsTransparency="True" removed="{x:Null}" Focusable="False" >
    <Grid>
        <controls:TecladoCompleto HorizontalAlignment="Center" VerticalAlignment="Bottom" Focusable="False"/>
    </Grid>
</Window>

推荐答案


这篇关于如何创建屏幕键盘C#wpf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 02:55