Using an abstract base class for Windows Forms

I found the need to use an abstract base class. This architecture forces each detail form to provide an implementation for a Save() method.

(1) Unfortunately, the Windows Forms designer doesn’t support inheriting from an abstract base class. Fortunately, I was able to use a type descriptor to tell the designer to use a custom concrete class that inherits from the abstract class.

(2) Unfortunately, this caused some user interface element z-ordering code to fail as it relied on variables being set before it was called; these variables were not yet set by the designer at the point it was called. Fortunately, I was able to create a method on the base class and call it from the initialization code: this fixed the issue.

(3) Unfortunately, this method call was placed among auto generated code and was deleted, of course, when the designer recreated the code. Fortunately, I was able to create a property which does the work and gets persisted by the designer.

It’s been a lot of work just to make an abstract base class compatible with the windows forms designer. Now that it works, I may wish to consider refactoring it.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s