question

58901228 avatar image
0 Votes"
58901228 asked 58901228 commented

How to create a custom mouse keyboard event?

I want to define an event for an image object. When I place the mouse on the image, I start an event by pressing the left mouse button and pressing Ctrl. How can I achieve this?

windows-wpf
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Castorix31 avatar image
0 Votes"
Castorix31 answered 58901228 commented

A way =>

 Image img = new Image();
 img.Width = 300;
 BitmapImage bmpImg = new BitmapImage();
 bmpImg.BeginInit();
 bmpImg.UriSource = new Uri(@"https://i.ibb.co/BBQ64wy/Flower-Butterfly.jpg", UriKind.RelativeOrAbsolute);
 bmpImg.DecodePixelWidth = 300;
 bmpImg.EndInit();
 img.Source = bmpImg;
 img.MouseLeftButtonDown += new MouseButtonEventHandler(img_LeftButtonDown);
 (this.Content as Grid).Children.Add(img);

//

     private void img_LeftButtonDown(object sender, RoutedEventArgs e)
     {
         if (Keyboard.IsKeyDown(Key.LeftCtrl))
         {
             MessageBox.Show("Test", "Information");
         }
     }


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Is the reverse possible?
for example first press keyboard and last press mouse?

0 Votes 0 ·