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.Navigation;
using System.Windows.Shapes;
namespace clipper
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
public void HandleKeyDownEvent(object sender, KeyEventArgs e)
{
MessageBox.Show("It came here");
if (e.Key == Key.LeftCtrl && e.Key == Key.C)
{
MessageBox.Show("You have pressed control + c");
}
}
}
}
Donc c'est mon code. J'ai essayé de googler la solution pour l'événement KeyPress et je l'ai implémenté ici. Mais comme je suis nouveau à C#, je ne suis pas sûr de ce qui s'est mal passé. Guidez-moi s'il-vous-plaît.J'essaye d'avoir une frappe en C# wpf mais ça ne marche pas. Mon code est-il faux?
Je n'utilise pas de formulaire .. J'utilise wpf, et peut-être à cause de cela, je reçois une erreur pour KeyPreview = ture; – laslavinco
Non seulement cela, vous avez oublié d'attacher l'événement: 'this.KeyPreview = true; this.KeyPress + = nouveau KeyPressEventHandler (HandleKeyDownEvent); ' – SilentStorm