Corollary: Be careful about Form.Load

A corollary to yesterday's abstract base class problem: be careful what you put in the Form.Load event. Apparently the form designer raises that too.

Basically, I had a VB.NET data input form and I wanted to create a specialized version of it, so I subclassed it. The problem is, I added some code to the base class's Load event handler. The code just retreived some comfiguration data from an XML file and used it to populate some combo boxes from a database. The intention was to just let the child class inherit this, since the boxes are all the same.

But, of course, it couldn't be that easy. As soon as I switched over to the child class and tried the form designer, SharpDevelop showed me a nice error message and backtrace. Apparently it was trying to open the XML file and couldn't find it. The path was relative to the application's directory, and at design time, "the application" is apparently the IDE.

I ended up just moving this code to a method that's only called in the child class's Load event handler. That seemed to fix the problem.

Seems like a bit of a hack, though. I would think that if it works at run-time, then it shouldn't give you problems at design-time. But apparently I'm alone on that.

You can reply to this entry by leaving a comment below. You can send TrackBack pings to this URL. This entry accepts Pingbacks from other blogs. You can follow comments on this entry by subscribing to the RSS feed.

Add your comments #

A comment body is required. No HTML code allowed. URLs starting with http:// or ftp:// will be automatically converted to hyperlinks.