OO GUI programming..

wyrd

Senior Contributor
Joined
Aug 23, 2002
Messages
1,405
Location
California
Question about how I can do GUI programming with an OO approach..

Say you've got a couple of tab pages, and within each tab page are some controls and whatever else you may have there. Obviously, the form in which all these reside would have a huge code page (all those events and helper methods that access controls on the form).

How can I logically break the different tab pages into classes so I can still easily access the child controls that are on the tab pages? ATM I've been breaking the code up using #region, but still, that just doesn't seem right. Anything methods that I can make generic enough and group them in a logical form are encapsulated into classes, unfortunately the problem comes with dealing with the GUI interface itself.

I'm not sure of a better way to explain this. :( Let me try this;

There's a tab control with two tab pages, and each tab page has a list view and text boxes and buttons on it. I want to encapsulate each tab pages functionality into a class. By this, I mean, I want a class that will accept what tab page it's using and be able to use all child controls within it, and when the user for example clicks a button (a child control on the tab page), it will trigger the event inside the class which is encapsulating the tab page.

Does this make sense? Obviously keeping all events, etc in the main forms code page for ALL controls on it (which could be a lot) seems to just be a bad idea to me, especially if it's a large program. I'm looking for a logical way to organize the code in an OOP way.

Thanks for the help, and hopefully I'm not confusing anyone but myself. :)
 
I think I do not totally understand, for you already seem to have the answer.

Design a base class inheriting from a tab and put all common code and common controls in that one. You can do this in a class, or even create an ocx.

Next inherit from these classes and implement the code that is specifically for that tab.

As we say in dutch : i am pointing you, where you already know to go. So I don;t think I understand. Confusion succeeded
 
I tried at one time to create a TabPage as a separate class, complete with GUI design. The idea was that we may have 2 or more developers working on a complex form but with sourcesafe, only one developer could work on the form at once. Try as I might, I couldn't get the designer to show a TabPage. Even if that were possible, having the individual tab pages in a separate class gave us new problems that I won't go into. Suffice it to say, it didn't work out.

In the end, using #region is the best option for splitting up most GUI code. You can definitely break out some code into common functions (such as filling a listbox or combobox, for instance), but there will still be a LOT of code for complex GUI forms.

-Nerseus
 
Vincentnl:
A custom control doesn't sound to bad, I'll try that out...

Nerseus:
Even if that were possible, having the individual tab pages in a separate class gave us new problems that I won't go into. Suffice it to say, it didn't work out.

That sucks.

In the end, using #region is the best option for splitting up most GUI code.

Ugh. Talk about a huge code file.

You can definitely break out some code into common functions (such as filling a listbox or combobox, for instance),

Yup.. did that as best as I could.

but there will still be a LOT of code for complex GUI forms.

Once again.. that sucks. :(

----------

Oh well, back to coding my 20 page code file. :eek:
When I'm done with my project I'll post up the code so you guys can nit pick and help me out with what I did wrong and how I can improve my OOP. For now it seems like I'm on the right track and just break up the main form as best as I can into #regions. When I'm done I'll try the custom control idea (I probably should of tried that before hand, but now that I'm in the middle of the project, doing it now would be a headache, I'll do re-design and re-building after I finish my first project)

Thanks again for the advice.
 
Last edited:
Ive made a project in which I had a lot of GUI manipulation. I just made a controler class filled with functions and had the form calling this controller class for everything. And the controler class was responsible for comunicating with other classes like Database, XML, registry, etc. But in the end it didnt make much difference, since the controler class became very huge. At least I had no logic on the form.
 
Back
Top