|
-
Jan 30th, 2009, 01:37 PM
#1
Thread Starter
Frenzied Member
[2.0] Control having multiple positions
Hello people,
I am facing a great challenge. In my program there is a form which contains a panel, which contains several controls (datagrid, textbox, combobox...). For some reason the panel sometimes need to be portait, en other times landscape. That is not really difficult, but the controls need to be rearranged when the panel changes from landscape to portait and the other way arround. That can be done by setting the position and size of every control. Now come the challenge, how (or where) do I store the information about the 2 sizes and location of every control. I don't want to have a methode like this:
Code:
private void rearrangeControles(bool landscape)
{
if (landscape)
{
this.tbxClient.Size = new Size(10,100);
this.tbxClient.Location = new Location(5,7);
}
else
{
this.tbxClient.Size = new Size(5,30);
this.tbxClient.Location = new Location(15,20);
}
....
}
Because that would mean that if I change someting in the desinger this method to.
Anybody has a clue....
-
Jan 30th, 2009, 09:05 PM
#2
Re: [2.0] Control having multiple positions
You have to define it somewhere, when you change it in the designer, it just updates the code behind file with the new position of the control, so that is even defined in the code.
The only way I could think of doing it without having to change the code in your function would be to use offsets of the original values and store them in another variable.
-
Jan 30th, 2009, 09:39 PM
#3
Re: [2.0] Control having multiple positions
Instead of using a Panel and adding these controls to the form in the designer, create a UserControl and add the child controls to that. You can then put all the logic for resizing and relocation in the UserControl. The form then simply has to tell the UC to display itself in portrait or landscape and let the UC itself handle the rest. This is called "encapsulation" and is one of the tenets of OOP.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|