I want to make a zoom panel on the clamped combination ... How to track the key combination Ctrl + MouseWheel? I do not understand how to simultaneously work with the event of rotating the mouse wheel and pressing Ctrl. Here is what is at the moment:

private void MainForm_KeyPress(object sender, KeyPressEventArgs e) { if (ModifierKeys.HasFlag(Keys.Control) & колесо мыши активно) { //####работает для MouseWheel#### //if (e.Delta > 0) //zoom + //{ // canvas.Width += e.Delta / 5; // canvas.Height += e.Delta / 5; // canvas.Location = new Point(canvas.Location.X - e.Delta / 10, canvas.Location.Y - e.Delta / 10); //} //else if (e.Delta < 0) //zoom - //{ // canvas.Width += e.Delta / 5; // canvas.Height += e.Delta / 5; // canvas.Location = new Point(canvas.Location.X - e.Delta / 10, canvas.Location.Y - e.Delta / 10); //} } } 

thank

1 answer 1

It works O_o

 private void this_MouseWheel(object sender, MouseEventArgs e) { if(ModifierKeys == Keys.Control) { if (e.Delta > 0) //zoom + { canvas.Width += e.Delta / 5; canvas.Height += e.Delta / 5; canvas.Location = new Point(canvas.Location.X - e.Delta / 10, canvas.Location.Y - e.Delta / 10); } else if (e.Delta < 0) //zoom - { canvas.Width += e.Delta / 5; canvas.Height += e.Delta / 5; canvas.Location = new Point(canvas.Location.X - e.Delta / 10, canvas.Location.Y - e.Delta / 10); } } } 
  • Note that this method of comparison will not work if you simultaneously hold down Alt and / or Shift along with Control . - Alexander Petrov
  • @AlexanderPetrov, well, I only need it with ctrl, when you change the zoom, hold down ctrl + '+' for example) - Xambey