hi guys! I need help. Im trying to develop a windows application and i want to have a form were there is a Static side and Dynamic side...whatever button i click on the Static side the output is always shown in the Dynamic side. Pls consider the attached screen size as example. Can any body please suggest or help me on how to do this. Thanks in advance!
Set the form's IsMdiContainer property to True. Now add a Panel to the form and set its Dock property to Left. You can now add controls, like Buttons, to the Panel like any other Panel on any other form. Each Button will presumably correspond to a different child form. Are you intending there to be only one each of the different types of child forms?
You have three buttons. Presumably they each correspond to a different type of child form. Are you intending that there only ever be one instance of each type, or do you want to allow multiple instances?
You should implement the Singleton pattern in your forms, e.g.
C# Code:
private static SingletonForm _instance;
public static SingletonForm Instance
{
get
{
if (_instance == null || _instance.IsDisposed)
{
_instance = new SingletonForm();
}
return _instance;
}
}
private SingletonForm()
{
InitializeComponent();
}
The only constructor is private so all interaction with the class takes place through the Instance property. That ensures that only one instance ever exists. Each time you press a button you just call the Show and Activate methods of the Instance property of the appropriate class. That ensures that the one and only instance of that class is visible and selected.
thanks for that again JM! but i still have a problem, how will I prevent the controls, like buttons, label, etc., from my "static" panel from moving everytime i show/close the child form? Pls. see attached screenshot.
The controls aren't actually moving. Their Location property is a point relative to the top, left corner of the Panel. If you maximise a child form then a control strip is created along the top of the parent form that causes the Height of the Panel to be reduced and the its Top to move downwards. The controls on the Panel remain in exactly the same Location relative to top, left corner of the Panel.
If you don't want the controls to be anchored to the top, left corner of the Panel then you need to change their Anchor property to something other than the default {Top, Left}. Note that that will also affect their behaviour when the Height of the form changes. If that never happens then you're OK, otherwise it's something to consider.
Another way around it would be to place a TableLayoutPanel on the Panel and set all the lower rows to static Heights and then have the top row take up whatever's left. That way if the Panel resizes only the top row of the TLP will resize.
I'll try the TableLayoutPanel..anyway, is there any way for me to remove or prevent the control strip from appearing everytime i maximize the child form?