Click ok to MessageBox in vb.net triggers form.activate in calling form

  • Thread starter Thread starter Ed.
  • Start date Start date
E

Ed.

Hey guys,
We're in the process of converting a vb6 app to vb.net 2008 and are having
some minor issues. One of these is that it appears that the form.activate
code is fired after clicking ok to any messageboxes that we display. Is
this normal? Is there any way to call a messagebox in a way that won't fire
the form.activate when clicking ok? We have much of our form setup code in
there which we don't want run again. Sure we can code around this with
flags but I thought maybe there's a way to call the msgbox with an optional
param or similar?

Thanks in Advance,
- L
 
Ed. said:
Hey guys,
We're in the process of converting a vb6 app to vb.net 2008 and are having
some minor issues. One of these is that it appears that the form.activate
code is fired after clicking ok to any messageboxes that we display. Is
this normal? Is there any way to call a messagebox in a way that won't fire
the form.activate when clicking ok? We have much of our form setup code in
there which we don't want run again. Sure we can code around this with
flags but I thought maybe there's a way to call the msgbox with an optional
param or similar?

Thanks in Advance,
- L

You should move the logic out of the activated event. No matter what
messagebox does, when the user switches from your app to another, then
back, you will get the Activated event.

Maybe in vb6 the activated event had different meaning? It seems that
you would have had issues in vb6 with the logic as well.
 
Hi Mike,
Thanks for the quick reply. Yes is vb6 it only fired if returning from
another vb5 FORM, not messagebox. This meant that you could put form setup
code in activate and not worry about it firing more than once if you only
displayed messageboxes. If opening another form from there and returning
then yes it fired, so you could code around that if required.

Thanks - L
 
Ed. said:
Hey guys,
We're in the process of converting a vb6 app to vb.net 2008 and are having
some minor issues. One of these is that it appears that the form.activate
code is fired after clicking ok to any messageboxes that we display. Is
this normal? Is there any way to call a messagebox in a way that won't fire
the form.activate when clicking ok? We have much of our form setup code in
there which we don't want run again. Sure we can code around this with
flags but I thought maybe there's a way to call the msgbox with an optional
param or similar?


http://msdn.microsoft.com/en-us/library/t98sy0cc.aspx

VB.Net's behavior is just the reaction to the WM_ACTIVATE message. VB6 swallows
it sometimes for which reason ever. Maybe the Activated event is not the right place
for your code. Either put it into the Shown event or execute the code right
after calling the Show method.
 
Hey guys,
We're in the process of converting a vb6 app to vb.net 2008 and are
having some minor issues. One of these is that it appears that the
form.activate code is fired after clicking ok to any messageboxes
that we display. Is this normal? Is there any way to call a
messagebox in a way that won't fire the form.activate when clicking
ok? We have much of our form setup code in there which we don't want
run again. Sure we can code around this with flags but I thought
maybe there's a way to call the msgbox with an optional param or
similar?

If it is form setup code, then shouldn't it be in New rather than Activate?

(And for VB6, shouldn't it have been in Load rather than Activate?)

Activate is for a specific event, not for the form setup.

Oh, and BTW, you will find that the process will be a rewrite, not a
conversion. .NET and Classic are completely different beasties with some
similarities in language...
 
Back
Top