-1

My main form has two panels, left docked and right docked. The right side panel has two child panels with top dock and bottom dock settings. The usercontrol is added to the right side top panel.

My usercontrol has a panel and a label. The panel is anchored on all 4 sides, the label is anchored on all except the bottom. At runtime I create this usercontrol and set it to dockstyle=fill and then I add it to my top right panel.

With everything set to "fill" I expect that when I add my usercontrol to the panel it will take on the appropriate width and height and pass that info to the child controls (labels) inside of my usercontrol.

My problem is that this stretching of the size does not happen when I create my objects during the Load event on my usercontrol. Even though initializecomponent has ran for the usercontrol the panel inside of it (4 corners anchored) has not taken the x/y values of the available space. As a result my usercontrol shows up about 50% of the width I want.

Lets say that instead of creating objects during usercontrol load that I instead start a timer and have the timer call my create routine when it raises the tick event. When I do things like this my objects are created with the full width/height that I expect. The only issue here is that this causes a delay in my interface.

Can someone help explain this behavior? My mainform is calling a "load gui" routine which is instantiating usercontrols, setting panel sizes, and then adding usercontrols to those panels. This particular user control is the last to load into the panels from that load gui routine so it does not make sense that the parent panel width/height would not be known yet. This is one of my first apps where I am purposely trying to use dockstyle=fill to keep things consistent across different main form sizes without writing all the extra size_changed code handlers. I'm sure this one is easy to work around once I know where the problem lies.

Thanks for any help provided!

jmoreno
  • 12,752
  • 4
  • 60
  • 91
TWood
  • 2,563
  • 8
  • 36
  • 58
  • Have you tried adding the user control to the panel and then setting DockStyle to Fill? Also, make sure the usercontrol and panel have AutoSize set to false. – stuartd May 26 '11 at 08:39
  • I tried it out at design time. The designer shows the same behavior. Checked the autosize props and they were all false. Here's the weird thing when I run it with the "design time" added control...it comes up at full size. Wish I knew what was happening when I add at runtime but I can deal for now. Thank you Stuart for the suggestions. – TWood May 26 '11 at 14:28

1 Answers1

0

this turned out to be a padding issue on the parent usercontrol. I also had to allow a bit of wiggle room to make sure that the controls didn't overflow the panel so I did a parent.width - 15 and that along with the padding made everything work much better.

TWood
  • 2,563
  • 8
  • 36
  • 58