Sign in to follow this  
CDProp

Subclassing in C#

Recommended Posts

CDProp    1451
Hello, I have a form, that has a Panel, and I need to make the Panel double buffered. The DoubleBuffered property, it seems, is protected, so I can't set it from my Form class. It looks as though I will have to create a new Panel-derived class, called DoubleBufferedPanel or something, and then set the DoubleBuffered property in the constructor. My question is, since I've created this Form, and Panel, using the Designer & toolbox, how can I make sure that this is a DoubleBufferedPanel rather than a regular panel? I could edit InitializeComponent in MyForm.Designer.cs, but there's a comment there explicitly stating that the code should not be edited with the code editor. I heard that I can create a new UserControl-derived class with a Panel docked in it, and then add this class to my toolbox. However, this does not seem like an ideal solution because, first of all, it seems I would have to create a separate project for it so that it's in it's own assembly, and second of all, because I'm still inheriting from UserControl, not Panel. I guess I could just abstain from creating this panel with the designer, and create it in-code instead.

Share this post


Link to post
Share on other sites
mutex    1111
You can actually edit MyForm.Designer.cs to change the type to DoubleBufferedPanel. As long as your DoubleBufferedPanel is compatible with the designer (isn't a generic type, has a default constructor, and some other obscure rules) you should still be able to use the designer without issues.

Also note that once you define a new class inheriting from Control or one of its descendants, the class should automatically show up in Toolbox (you may need to rebuild).

Share this post


Link to post
Share on other sites
CDProp    1451
Thank you for your help. I've made a class that derives from Panel, however I can't seem to get it to show up in the Toolbox. The only way I know how to add it is to right-click, and select 'Choose Items' at which point I can browse for a DLL. But since this class is defined in the same project, there is no distinct DLL for it.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this