我有一个布尔值,用于跟踪 FlowLayoutPanel 上的右键 MouseDown 事件和相应的后续 MouseUpEvent 之间的状态:
bool TextBoxesRespondingToMouseMoveEvents = false;
...这是 FlowLayoutPanel 的 MouseDown 和 MouseUp 事件中的代码,以及 FlowLayoutPanel 上的所有 TextBox 共享的共享 MouseHover 处理程序:
private void flowLayoutPanelGreatGooglyMooglyMain_MouseDown(object sender, MouseEventArgs e) {
if (e.Button == MouseButtons.Right) {
TextBoxesRespondingToMouseMoveEvents = true;
//MessageBox.Show("TextBoxesRespondingToMouseMoveEvents is now true");
selectionStart = PointToClient(MousePosition);
}
}
private void flowLayoutPanelGreatGooglyMooglyMain_MouseUp(object sender, MouseEventArgs e) {
if (e.Button == MouseButtons.Right) {
TextBoxesRespondingToMouseMoveEvents = false;
selectionEnd = PointToClient(MousePosition);
}
}
// This event is shared by all of the buttons on flowLayoutPanelGreatGooglyMooglyMain
private void textBoxQH1_MouseHover(object sender, EventArgs e) {
if (TextBoxesRespondingToMouseMoveEvents) {
TextBox tb = (TextBox)sender;
if (tb.BackColor.Equals(SystemColors.Window)) {
tb.BackColor = System.Drawing.Color.Gainsboro;
}
}
}
只要 MouseDown 事件中的 MessageBox.Show() 没有被注释掉,或者如果我在该事件中有断点,这就是有效的。但是,如果您只是让代码运行,同时注释掉 MessageBox.Show(),则 MouseHover() 事件永远不会触发。
为什么,我该如何解决?