best way to proceed on Windows.Forms user interface?

G

Guest

Hello everyone,

I'm wondering if I could get some advice on the best way to build the user
interface depicted in this diagram:
http://www.senske.com/images/winforms_layout.jpg

The gray areas will be static throughout. However, I'd like the blue area
to change to a different interface depending on which of the buttons at left
is pressed. Should I design the interface for each of the buttons as a
separate custom user control, then swap the controls in and out depending on
which button is pressed?

Or, am I going about it entirely wrong and there's a better approach?

Thanks in advance for any insight.

Andre Ranieri
 
J

Joe

Hello,

I would create a user control with a property like this:
enum ScreenMode {ContractInfo, Details, Leads, Services, AccountingAdj,
AccountingDefaults};

public ScreenMode ScreenMode
{
get
{
return // you current mode. probably stored in a variable
}
set
{
variable = value;
DoScreenModeChange();
}
}

Create a user control for each of the 6 screens you would need and just
switch them in the DoScreenModeChange() method.

HTH
-Joe
 
G

Guest

Joe,

Thanks immensely for your feedback. I'm fairly new to WinForm user
controls; I hope you'll bear with me while I ask a followup question or two:

Do I understand correctly that I can create one "master" user control (I
assume it woul be blank) which is placed on the form, then six other ones
for the six respective buttons?

In the DoScreenModeChange(); method, roughly how would I go about replacing
the contents of the master control (or whichever is displayed) with the new
one?

Thanks again,

Andre Ranieri
 
G

Guest

For your center area, find a control in the tool box called "Panel" add a
panel for each page you want in there, and put controls on that panel. make
sure they are "children" of that panel. To do that, just click the control
you want to add, and drag a box for it inside of the panel.

Anyways, here is a almost complete example:

using System;
using System.Collections;
using System.Windows.Forms;

namespace YourProject
{
public class PanelData
{
private static Hashtable m_Table = null;

public static void RegisterPanel(Panel panel, Button button)
{
if(m_Table == null)
m_Table = new Hashtable();
m_Table.Add(panel, button);
}

public static void HidePanels()
{
foreach(DictionaryEntry de in m_Table)
{
Panel panel = (Panel) de.Key;
panel.Hide();
}
}

public static void DisplayPanel(Button button)
{
HidePanels();
foreach(DictionaryEntry de in m_Table)
{
Button b = (Button) de.Value;
if(b == button)
{
Panel panel = (Panel) de.Key;
panel.Show();
break;
}
}
}

}
}


Now in your main form:

On form load:
PanelData.RegisterPanel(CustomersButton, CustomersPanel);
PanelData.RegisterPanel(HelpButton, HelpPanel);
//ETC
 
G

Guest

Thanks for your help. I think this will work fine.

I ended up using user controls instead of panels for the solution because
each element will have a fair amount of back-end code for data binding, etc,
and I didn't want all the code packed up in one form class.

Andre Ranieri
 
B

Bruce Wood

User controls are also superior because you can design them separately,
in their own design spaces, then merely place them on the final form.
Designing all six panels in the same form is difficult. (I know: I've
tried it. :-( )
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top