Forum  General Visual ...  Visual WebGui v...  AutoSize with dynamically created controls
Previous Previous
 
Next Next
New Post 2/26/2010 4:50 AM
Unresolved
  zz9pa
37 posts
No Ranking


AutoSize with dynamically created controls 
Modified By zz9pa  on 2/26/2010 7:51:17 AM)

Is there something special I should be doing when trying to create controls dynamically in order to make 'autosize' work properly ?

 

For example - if I have something like :

 

 

            Panel p = new Panel();
            Panel p2 = new Panel();
            Label l=new Label();

            // So we have a label in a panel with a border.
            // And that panel in another panel without a border
            // but that is autosize..


            p.BorderStyle = BorderStyle.Fixed3D;
    //        p.AutoSize = true;
    //        p2.AutoSize = true;

           
            l.Text = "Hello";
            l.AutoSize = true;

            l.BackColor = Color.Red;
            p.BackColor = Color.Blue;
            p2.BackColor = Color.Green;

            p.Controls.Add(l);
            p2.Controls.Add(p);

            p.Top = 40;
            p.Left = 40;
        
            p.AutoSize = true;
            p2.AutoSize = true;
            this.Controls.Add(p2);

 

 

(just put in a button click on a blank form)

 

Running it - you should see the panels are too large for the label..

(Doesn't seem to matter if I set the 'autosize' before or after )

 

Now - in practice - I've got some very complicated forms generated - with flowlayouts etc - but the Autosizing isn't working properly in similar ways, including not allocating enough space for the borders on some of the contained controls etc..

Any thoughts ?

As an alternative - is there someway to force a resize to a control and all its children ?

 

 

(For reference - I had major problems in 6.3 with this too - including having to set the size to something massive adding child controls, and then setting autosize)

 
New Post 3/8/2010 3:37 PM
  palli
11189 posts
1st Level Poster




Re: AutoSize with dynamically created controls 
Modified By palli  on 3/8/2010 6:39:18 PM)

Hi,

Running your code on WinForms Form, and you get the exact same non-autosizing behaviour for the panels. Checking the WinForms documentation for Panel.Autosize, you can see the AutoSize property is not relevant for the Panel control, so I guess this means you are out of luck with automatic autosizing of a Panel control.

If you on the other hand do have some Autosizing behaviour that is different from the WinForms implementation, then please create the most minimal app, clean it, zip it and email it to support (see email address in my signature) along with a full reference to this thread and we will surely take a look. Please remember to post here when you have sent it so we will know when to look.

Palli

 


Páll Björnsson - Visual WebGui support team - Email: support@visualwebgui.com
 
New Post 3/17/2010 7:30 AM
  zz9pa
37 posts
No Ranking


Re: AutoSize with dynamically created controls 

Try setting

 

p.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            p2.AutoSizeMode = AutoSizeMode.GrowAndShrink;

 

just before setting the AutoSize=true;

 

Eg :

 

 Panel p = new Panel();
            Panel p2 = new Panel();
            Label l = new Label();

            // So we have a label in a panel with a border.
            // And that panel in another panel without a border
            // but that is autosize..


            p.BorderStyle = BorderStyle.Fixed3D;
            p.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            p2.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            p.AutoSize = true;
            p2.AutoSize = true;


            l.Text = "Hello";
            l.AutoSize = true;

            l.BackColor = Color.Red;
            p.BackColor = Color.Blue;
            p2.BackColor = Color.Green;

            p.Controls.Add(l);
            p2.Controls.Add(p);

            p.Top = 40;
            p.Left = 40;

            //p.AutoSize = true;
            //p2.AutoSize = true;
            this.Controls.Add(p2);

 

 

 
New Post 3/18/2010 2:26 PM
  palli
11189 posts
1st Level Poster




Re: AutoSize with dynamically created controls 

Hi,

Yes, I must admit that here we have a different behaviour in Visual WebGui than we have in WinForms. I do not see the logic in WinForms though, as I would have thought that either both panels should autosize, or neither of them. In WinForms the read (inner) panel does resize around the Label, but the green (outer) panel does not.

Is that the same behaviour you get in Winforms ?

Palli

 


Páll Björnsson - Visual WebGui support team - Email: support@visualwebgui.com
 
Previous Previous
 
Next Next
  Forum  General Visual ...  Visual WebGui v...  AutoSize with dynamically created controls
Azure banner
.NET Web, Cloud and Mobile application delivery platform | Sitemap | Terms of Use | Privacy Statement | Copyright © 2005-2011 Visual WebGui®       Visual WebGui weblog on ASP.NET Visual WebGui Group on LinkedIn Visual WebGui updates on Twitter Visual WebGui Page on Facebook Visual WebGui YouTube Channel Visual WebGui Platform News RSS