Re: Messagebox in Validating cancels subsequent events
- From: "Kevin Spencer" <uce@xxxxxxx>
- Date: Fri, 11 Aug 2006 07:11:03 -0400
Hi Al,
I'm a bottom-line type of guy. Here's the bottom line. Regardless of whether
it's a bug or not, it's not likely to change any time soon. In the meantime,
you have a job to do. So, if you think you've got a lemon, make some
lemonade out of it!
--
HTH,
Kevin Spencer
Microsoft MVP
Chicken Salad Surgery
Orange you bland I stopped splaying bananas?
"Al Santino" <asantino@xxxxxxxxxx> wrote in message
news:u1%23zjuOvGHA.4612@xxxxxxxxxxxxxxxxxxxxxxx
Hi Kevin,
Well it's very nice of you to give them the benefit of the doubt. It's
curious, though, that the documentation doesn't shed any light on the
matter. In fact, it leads one to suspect (unkindly, I know) that this
behaviour is not quite orthogonal.
Al
In August of 2001, who expected the U.S. to invade Iraq?
"Kevin Spencer" <uce@xxxxxxx> wrote in message
news:eorizYLvGHA.4972@xxxxxxxxxxxxxxxxxxxxxxx
Hi Al,
I tend to avoid the term "bug," unless behavior is not expected by the
developer. I would think that Microsoft is well aware of this behavior,
and does not consider it to be errant.
--
HTH,
Kevin Spencer
Microsoft MVP
Chicken Salad Surgery
Accept the Unexpected.
"Al Santino" <asantino@xxxxxxxxxx> wrote in message
news:OvS%23ZLKvGHA.560@xxxxxxxxxxxxxxxxxxxxxxx
Hi Kevin,
Thanks for looking at it. I guess I'll give up on using the validating
event and try something else. Would you say this is a bug?
Al
"Kevin Spencer" <uce@xxxxxxx> wrote in message
news:OQjkp8JvGHA.4872@xxxxxxxxxxxxxxxxxxxxxxx
Hi Al,
I'm not completely sure what's happening. I tried out the code, and
mixed it around a bit, and then read the documentation on the
Control.Validating event. Control focus events happen in the following
order:
1. Enter
2. GotFocus
3. Leave
4. Validating
5. Validated
6. LostFocus
Note that the Validating event occurs prior to the LostFocus event. So,
when the Validating event occurs, the Control still has the focus. My
guess is that because of the event handler, the focus is not lost until
the MessageBox appears, and this causes the second button to not
receive the Click event unless clicked a second time.
--
HTH,
Kevin Spencer
Microsoft MVP
Chicken Salad Surgery
Accept the Unexpected.
"Al Santino" <asantino@xxxxxxxxxx> wrote in message
news:OB$yU5IvGHA.4972@xxxxxxxxxxxxxxxxxxxxxxx
Hi,
It appears displaying a messagebox in a validating event will cancel
subsequent events. I'm including a short program demonstrating the
behaviour in VB and C#.
The program creates a form, adds two buttons, a validating handler for
button one and a click handler for button two. Clicking on button two
when button one has the focus should cause button one's validating to
fire followed by button two's click handler. However, button two's
click handler doesn't fire.
Can someone explain what I'm doing wrong or suggest a workaround?
Thanks
Al
-----------------------------------------------
*** VB version:
Imports system
Imports system.windows.forms
Module ValidateTest
Sub Main()
Dim frm As New Form()
Dim btn As New Button
btn.Text = "One"
btn.Parent = frm
AddHandler btn.Validating, AddressOf BtnValidating
btn = New Button
btn.Left = btn.Width + 3
btn.Text = "Two"
btn.Parent = frm
AddHandler btn.Click, AddressOf BtnClick
Application.Run(frm)
End Sub
Private Sub BtnValidating(ByVal sender As Object,
ByVal e As System.ComponentModel.CancelEventArgs)
MessageBox.Show("BtnValidating event")
End Sub
Private Sub BtnClick(ByVal sender As Object, ByVal e As
System.EventArgs)
MessageBox.Show("BtnClick event")
End Sub
End Module
-----------------------------------------------
*** C# version:
using System;
using System.Windows.Forms;
class NoClickEvent: Form
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new NoClickEvent());
}
public NoClickEvent()
{
Button btn = new Button();
btn.Text = "One";
btn.Parent = this;
btn.Validating += BtnValidating;
btn = new Button();
btn.Text = "Two";
btn.Left = btn.Width + 3;
btn.Parent = this;
btn.Click += BtnClick;
}
void BtnValidating(Object sender,
System.ComponentModel.CancelEventArgs e)
{
MessageBox.Show("BtnValidating event");
}
void BtnClick(Object sender, System.EventArgs e)
{
MessageBox.Show("BtnClick event");
}
}
.
- References:
- Messagebox in Validating cancels subsequent events
- From: Al Santino
- Re: Messagebox in Validating cancels subsequent events
- From: Kevin Spencer
- Re: Messagebox in Validating cancels subsequent events
- From: Al Santino
- Re: Messagebox in Validating cancels subsequent events
- From: Kevin Spencer
- Re: Messagebox in Validating cancels subsequent events
- From: Al Santino
- Messagebox in Validating cancels subsequent events
- Prev by Date: RE: FK Constraint Raised for no reason I can find?
- Next by Date: Re: find Component's host ( Form ) PLEASE HELP
- Previous by thread: Re: Messagebox in Validating cancels subsequent events
- Next by thread: ToolStripControlHost & DateTimePicker
- Index(es):