Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# User-controls
hi all,
i've encountered a problem while trying to fill a UserControl
inside a panel.
 
i've created some UserControl's. my problem is that while trying to fill them in a panel, some are resizing as expected and some don't react and remain at the same size.
 

???
 
another thing - the controls whom react normally are PictrueBox type.
the other ones are Panels containing many controls.
 
thx!
Posted 16-Dec-09 7:12am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

What have you set those panels to do when they are docked ? I'd suggest they are doing what they are told.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi,
It's an old post but anyway, I have experienced similar problems.
 
A set of my controls was not docking properly ( it was placed properly , but once I resized the form the controls stayed of the same size ( I was adding the controls at runtime). So , I actualy hadd to code a couple of methods to resize the whole control hierarchy.
 
private static void ResizeChildsInt(Control c,bool recursive) {
      Rectangle r = c.DisplayRectangle;
 
      foreach (Control item in c.Controls) {
        if (item.Dock == DockStyle.Top) {
          item.Top = r.Top;
          item.Left = r.Left;
          item.Width = r.Width;
          if (item.Height > r.Height) {
            item.Height = r.Height;
          }
          r = new Rectangle(r.X, r.Y + item.Height, r.Width, r.Height - item.Height);
        } else if (item.Dock == DockStyle.Bottom) {
          int bottom = r.Bottom - item.Height;
          if (item.Height > r.Height) {
            item.Height = r.Height;
          }          
          item.Top = item.Height - r.Bottom;
          item.Left = r.Left;
          item.Width = r.Width;
          r = new Rectangle(r.X, r.Y, r.Width, r.Height - item.Height);
        } else if (item.Dock == DockStyle.Left) {
          int width = item.Width;
          if (width > r.Width) {
            width = r.Width;
          }
          item.Top = r.Top;
          item.Left = r.Left;
          item.Height = r.Height;
          item.Width = width;
          r = new Rectangle(r.X + item.Width, r.Y, r.Width - item.Width, r.Height);
        } else if (item.Dock == DockStyle.Right) {
          int width = item.Width;
          if (width > r.Width) {
            width = r.Width;
          }
 
          item.Top = r.Top;
          item.Left = r.Right - item.Width;
          item.Height = r.Height;
          item.Width = width;
          r = new Rectangle(r.X, r.Y, r.Width - item.Width, r.Height);
        }
      }
      //Fill
      foreach (Control item in c.Controls) {
        if (item.Dock == DockStyle.Fill) {
          item.Top = r.Top;
          item.Left = r.Left;
          item.Width = r.Width;
          item.Height = r.Height;
        }
      }
 
      //Recursive
      if (recursive) {
        foreach (Control item in c.Controls) {                
          if (item is UserControl == false) {
            ResizeChildsInt(item, recursive);
          }
        }
      }
    }
 
    public static void ResizeChilds(Control c) {
      c.SuspendLayout();
      ResizeChildsInt(c, true);
      c.ResumeLayout();
    }
Just call the static method ResizeChilds each time the control is resized.
  Permalink  
v2
Comments
Collin Jasnoch at 28-Oct-11 13:43pm
   
Good gawd man let it die!
Start your own thread.
For one the Op has likely moved on. For two you can not 'accept' and answer. For three it is almost 2 years old!
Armando de la Torre at 4-Nov-11 15:33pm
   
I actually found the article because I had the same question. So I bookmarked it. Once I found the answer I posted it. Maybe it will help someone in the future.
phil.o at 28-Oct-11 15:47pm
   
Would call that 'topic digging' :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 280
1 Jochen Arndt 150
2 Kornfeld Eliyahu Peter 120
3 PIEBALDconsult 110
4 Richard MacCutchan 105
0 OriginalGriff 6,055
1 DamithSL 4,621
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,500
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 29 Oct 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100