C# 为什么MouseHover事件只有在messagebox.show()或断点出现之前才会被调用?
我有一个布尔值,它跟踪FlowLayoutPanel上的右键MouseDown事件和相应的后续MouseUpEvent之间的状态:C# 为什么MouseHover事件只有在messagebox.show()或断点出现之前才会被调用?,c#,winforms,mouseevent,mouseover,C#,Winforms,Mouseevent,Mouseover,我有一个布尔值,它跟踪FlowLayoutPanel上的右键MouseDown事件和相应的后续MouseUpEvent之间的状态: bool TextBoxesRespondingToMouseMoveEvents = false; …以下是FlowLayoutPanel的MouseDown和MouseUp事件中的代码,以及FlowLayoutPanel上所有文本框共享的共享MouseOver处理程序: private void flowLayoutPanelGreatGoog
bool TextBoxesRespondingToMouseMoveEvents = false;
…以下是FlowLayoutPanel的MouseDown和MouseUp事件中的代码,以及FlowLayoutPanel上所有文本框共享的共享MouseOver处理程序:
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()事件永远不会触发
为什么,我怎样才能解决它呢?看一看问题的答案;虽然它们没有直接解释没有/没有MessageBox(或断点)之间的行为差异,但它开始解释textbox将吞噬鼠标事件,而您应该钩住PreviewXXX事件 我看到的FlowLayoutPanel或其文本框的唯一预览事件是KeyPreview。