I'm adding some functionality to the scrollwheel event on a Chart control and I was curious about the bitwise AND that is present in most documentation when determining which modifier key was pressed (e.g. https://msdn.microsoft.com/en-us/library/yazd4ct6(v=vs.110).aspx)
void Chart_MouseWheel(object sender, MouseEventArgs e)
{
//if ((ModifierKeys & (Keys.Shift | Keys.Control)) == (Keys.Shift | Keys.Control))
if(ModifierKeys == (Keys.Shift | Keys.Control))
{
//+/- 5 chart threshold with control and shift held
Threshold += (decimal)(e.Delta / 24m / 100m);
}
//else if ((ModifierKeys & Keys.Shift) == Keys.Shift)
else if(ModifierKeys == Keys.Shift)
{
//+/- 1 chart threshold change with shift held
Threshold += (decimal)(e.Delta / 120m / 100m);
}
//else if ((ModifierKeys & Keys.Control) == Keys.Control)
else if(ModifierKeys == Keys.Control)
{
var selectedIndex = styledComboBox1.SelectedIndex;
selectedIndex += -1*(e.Delta / 120);
if (selectedIndex < 0) selectedIndex = 0;
if (selectedIndex > (styledComboBox1.Items.Count - 1)) selectedIndex = styledComboBox1.Items.Count - 1;
styledComboBox1.SelectedIndex = selectedIndex;
}
else
{
AxisMax += 0.02 * e.Delta / 120;
}
}
Both the commented and uncommented if/else if lines produce the same result with each of the three combinations (Shift+Control, Shift, Control) producing the desired effects so I'm just wondering why it works in the uncommented scenario.
Additionally, when I wasn't checking for Shift+Control as the first condition, it would just fall into the Shift block - why is that?