Results 1 to 3 of 3

Thread: [2.0] Control having multiple positions

  1. #1

    Thread Starter
    Frenzied Member Lightning's Avatar
    Join Date
    Oct 2002
    Location
    Eygelshoven
    Posts
    1,611

    Thumbs down [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....
    VB6 & C# (WCF LINQ) mostly


    If you need help with a WPF/WCF question post in the NEW WPF & WCF forum and we will try help the best we can

    My site

    My blog, couding troubles and solutions

    Free online tools

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    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.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width