I’ve written a couple simple GUI applications but all of the logic is basically written in the default Form1 class that I’m given.
So I thought maybe I’ll rewrite the GUI logic into their own classes. For example, a class for the FileOpenDialog, another class for a ListView, and so on. That way my Form1 class doesn’t have too many unnecessary methods and is just there for handling some basic stuff, possibly not a lot after the other GUI methods have been moved around.
Wrote something like this as a first attempt to get somewhere
namespace WindowsFormsApplication1
{
class OpenFileDialog1 : OpenFileDialog
{
}
}
But then VS tells me I can’t derive from a sealed type.
I haven’t tried it with the other classes, but I’ll probably run into the same issue at some point. Am I not inheriting it correctly? Or do I have to use some sort of workarounds to separate each GUI element into their own classes?
Maybe this is not a good approach?
Based on your clarifying comments, it sounds like you either want some utility classes or factory classes. Perhaps something like below:
And in your form:
You could even do something with a partial class so in your main form you have something like
and in your partial class you have:
Many times its very useful to use partial classes as implementations of interfaces or focused functionality.