Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Building the GUI at run time

Status
Not open for further replies.

drdad5727

Programmer
Feb 28, 2005
28
US
It seems the MS GUI designer is really bad at building GUIs at run time -- although may be I just don't know how to do it.

My particular problem should be simple. I've got a simple, SDI Form, part of whose contents depend on other parts. Simply put, if the user makes selections on the left part of the form, I mess with the right part. I remove and add Panels that are the right part, as needed.

The biggest problem is that the panels have different sizes (heights only). I account for this by manually changing the Form height, like this:

Code:
 visibleControl.Visible = false;
      outerPanel.Controls.Remove(visibleControl);
      int heightDiff = neededControl.Size.Height - visibleControl.Size.Height + 2;
      Size nowSize = ClientSize;
      SetClientSizeCore(nowSize.Width, nowSize.Height + heightDiff);
      outerPanel.Controls.Add(neededControl, 1,0);
      neededControl.Visible = true;

Bizarrely, as these controls get swapped in an out, they change size! So, the size of the form get's messed up. (As the code shows, I'm swapping the controls into/out of a cell of a [tt]TableLayoutPanel. [/tt] The cell changes size, but the controls aren't in the cell when it does so!)

What I'd really like are pointers to how to do this kind of thing. Also, if anyone uses third party .NET controls, do they handle this sort of thing better?

Thanks!

 
All elements of the GUI are defined at design/compile time.
At run time you have logic which knows what elements to load and where to place them. convention over configuration will go a long way at reducing code.

In the end you will probably end up with something like this
1. application controller that controls the flow of the application. all requests will flow through this object at some point.
2. presenters (part of the MVC triad) that control what is happening on each screen.
3. Event Broker/Aggregator which is coordinating the GUI update notifications. When user clicks button A, tell objects X, Y, Z the button was clicked.

I would recommend some reading and research before you go too much further. Jeremy Miller has a couple blog entries on the subject, along with an open source project call StoryTeller which contains the framework that I described above (application controller, presenters, event broker). He has the most content on the subject that I found on the net.

If you are familiar with GoF patterns and the SOLID design principles the code in StoryTeller will be "easier" to digest. If not you may want to read up on GoF and SOLID before looking at StoryTeller.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top