Windows Develop Bookmark and Share   
 index > Windows Forms General > Newbie: usercontrol load question
 

Newbie: usercontrol load question

I create a Visual C# Windows Forms Control Library project in VS 2008

click the events icon and double click the Load field. AUserControl_Load method

is written which I modify as follows.

private void UserControl1_Load(object sender, EventArgs e)

{

MessageBox.Show("It loads");

}

When I run the project it displays

It loads

When I drag and drop a WebBrowser to the UserConrtol and run it it does not display "It loads"

Why does this happen?

-Bill

BilCo1239  Wednesday, July 30, 2008 6:57 PM

Ok, found an work around (not sure why it works though!)

If you set the webbrowser control (in the user control)property AllowWebBrowserDrop to false, then usercontrol_load method is called (and message box is displayed).

Regards,

Jayanta Dey  Thursday, July 31, 2008 5:35 PM

I could not duplicate that

JohnGrove  Wednesday, July 30, 2008 9:25 PM

Thanks John. From your post I suspected that I had a corrupt system soI borrowed another machine, did a clean install of VS2008 and got the same results as before.

If I delete the web browser it again prints the "It loads" message.Adding it back I see no message.

BilCo1239  Thursday, July 31, 2008 4:47 PM

I am using VS2005 Professional. Let me test on C# Express 2008

JohnGrove  Thursday, July 31, 2008 4:49 PM

The problem is reproducible in both VS 2005 and VS 2008 Express.

It seems when we have a web browser control in a user control, the usercontrol_load method is not called. Not sure if it's an issue with web browser controland has it been mentioned some where in MSDN.

Regards,

Jayanta Dey  Thursday, July 31, 2008 5:17 PM

Can you send me your usercontrol to look at?

JohnGrove  Thursday, July 31, 2008 5:25 PM

Will do John.
BilCo1239  Thursday, July 31, 2008 5:33 PM

Ok, found an work around (not sure why it works though!)

If you set the webbrowser control (in the user control)property AllowWebBrowserDrop to false, then usercontrol_load method is called (and message box is displayed).

Regards,

Jayanta Dey  Thursday, July 31, 2008 5:35 PM

That does the trick! Thank you Jayanta!

BilCo1239  Thursday, July 31, 2008 5:39 PM

Awesome good job!

JohnGrove  Thursday, July 31, 2008 5:39 PM

You can use google to search for other answers

Custom Search

More Threads

• Loading indexed gif files to a Graphics instance
• WebBrowser Control and IE7 on Vista
• return focus to the calling application
• How to check status of checkedListBox Items
• set the border color of a label
• Datagrid
• populating a form textbox from a class file in c#.net
• [treeview ] find node based on wildcard
• giving a panel focus
• Imagelist & Toolstrip image quality degrading