-
Feb 23rd, 2018, 10:11 AM
#1
Thread Starter
Addicted Member
form shown event not firing
I have a windows form project and would like to put some stuff in the Shown event handler instead of Load. I've done this before, you go to properties events and double click on Shown. The IDE generates the event handler for me. OK so far, but the event never fires. I've put a breakpoint in there and it never gets triggered. Is there something else that needs to be there?
Visual Studio 2013.
Thanks
-
Feb 23rd, 2018, 11:13 AM
#2
Re: form shown event not firing
If it's C#:
Open the .designer.cs file for the appropriate Form and see if there is a line that associates the Shown event with your handler. It'd look like:
Code:
this.Shown += My_Shown_Handler;
If it's VB:
Is there a "Handles" clause as part of your handler's declaration?
This answer is wrong. You should be using TableAdapter and Dictionaries instead.
-
Feb 23rd, 2018, 07:54 PM
#3
Re: form shown event not firing
If you go back to the Properties window, does it show your method next to the Shown event? If not, try selecting it from the drop-down. That should automatically generate the code that Sitten Spynne showed that you can add manually. Of course, that should have been generated when you double-clicked the event in the first place but VS, like any other software, doesn't always behave as it is supposed to.
-
Mar 26th, 2018, 12:20 AM
#4
Junior Member
Re: form shown event not firing
I was having this same problem and found it was due to my form being an MDI child form. when I removed the MDI child status, the form went through the Shown event code.
-
Mar 26th, 2018, 12:29 AM
#5
Re: form shown event not firing
Originally Posted by Greydog1
I was having this same problem and found it was due to my form being an MDI child form. when I removed the MDI child status, the form went through the Shown event code.
I just tested that in VS 2017 and I saw no such behaviour. This code:
csharp Code:
private void button1_Click(object sender, EventArgs e) { var f2 = new Form2(); var f3 = new Form3 {MdiParent = this}; f2.Show(); f3.Show(); }
saw the Load and Shown event handlers of both forms executed. Not sure if that's an issue that has been fixed or what but it seems OK to me.
-
Mar 26th, 2018, 12:37 AM
#6
Junior Member
Re: form shown event not firing
Well that probably explains why I can't seem to find ANY information about MDI child forms not triggering the Shown event. However, I am still upgrading a VB6 project so am using VS2008 and also noticed this is a C# post and I am using VB. However, I can change the behavior simply by commenting out the MDIparent assignment statement in my environment.
-
Mar 26th, 2018, 01:56 AM
#7
Junior Member
Re: form shown event not firing
Thanks for pointing that out jmcilhinney. I tried this on a different form that is also an MDI child form and the Shown event executed as expected. So I guess I have some other trail to follow with the first form. Thanks again.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|