Windows Develop Bookmark and Share   
 index > Windows Forms General > Control Anchoring malfunctions when form loads maximized
 

Control Anchoring malfunctions when form loads maximized

I have a usercontrol that is populated with various controls. All controls are anchored 'Top'. When the usercontrol is initally loaded in maximized mode the controls seem to fan out horizonatlly and then when the form is resized to be smaller they dont redraw in the form and instead stay off to their sides and end up out of the visible area. This doesnt happen to all of the controls only a few. The problem ones are panels which contain labels and maskedtextboxes. The rest of the controls work fine, including other panels with content.I have compared the properties and they are all set to the same so I cant figure out why some are fanning out horzionatlly when they are only anchored to top. Then not moving when the form is downsized.

note: if the form loads at the inate size ( i have the min size set as the default loading size) then I am able to resize and maximize with no problems and the panels correctly move with the form. it only occurs when it is initally loaded maximized.

note: they are all set to dock =none
  • Moved byMark Wilson-ThomasMSFTFriday, September 25, 2009 7:35 PMWindows Forms question, not WPF (From:Visual Studio WPF Designer)
  • Changed TypenobugzMVP, ModeratorMonday, September 28, 2009 12:12 PMwon't provide necessary repro steps or project
  •  
Without ME its just Aweso  Friday, September 25, 2009 7:23 PM
Are these TableLayoutPanels? Are these inherited controls? Best thing to do is to remove all code and controls but one or two that have this problem, then post the project to a file sharing service, like skydrive.live.com

Hans Passant.
nobugz  Friday, September 25, 2009 8:17 PM
Hello,

First I want to make sure is this a Winform project? I see you have post the question on WPF forum at first.

In winform, if you only set a control’s Anchor property to “Top� when resize the form’s width; we cannot make sure the control is always visible. When the form is not width enough, some control will be hided.

My suggestion is you can set Anchor property to “Top, Left�for left side controls and “Top, Right�for right side controls. That can make sure their horizontal location being changed according to the form’s width.

If you still have problem, please feel free to tell me. If you can upload the project to the skydrive, it can let us know it clearly.

Sincerely,
Kira Qian
Send us any feedback you have about the help from MSFT at fbmsdn@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework!
Kira Qian  Monday, September 28, 2009 9:30 AM
They are just panels, the controls are all inherited from one base usercontrol, all of the anchoring is done on that one base user control

The problem with adding anchoring of top and one of the sides is we want the controls to stay centered in the winform.

Is there another way to center controls? I tried using docking but that resulting in some odd layouts.
Without ME its just Aweso  Monday, September 28, 2009 11:24 AM
I can not provide the project, its far to large to simply remove controls and is business property.

Here is the details I can give:

I have a custom user control. On that I have a Tab user control. On the tab i have 3 panels each with controls in them. The panels are anchored to TOP. I also have several buttons on the tab and they are anchored to BOTTOM.

in the designer the panels are next to one another in the native resolution

-----------------------------------
| |
| |
|[ 1 ][ 2 ][ 3 ] |
| |
| |
-----------------------------------


When the form loads maximized the panels seem to fan out:

-----------------------------------
| |
| |
|[ 1 ] [ 2 ] [ 3 ] |
| |
| |
-----------------------------------

They are only anchored to TOP so I cant figure out why thy are spreading out. Them spreading out leads to the issue of when the form is resized they stay to the sides since infact they are only anchored to the top.
Without ME its just Aweso  Monday, September 28, 2009 12:32 PM
Hi,

>On the tab i have 3 panels each with controls in them

Is it a TabPage in a TabControl?

The issue still cannot be reproduced on my side. When I test it, I created a user control with a TabControl on it; put 3 panels on one of the tabpages of TabControl. There panel’s Anchor properties were set to Top. Then put the user control on a form and set its “Dock�property to Top. When the form was load as maximized, 3 panels were displayed on the center of the form. When I resized the form, they kept at the center. I don’t see any fan out effect.

Am I doing something different from yours? Could you please post the screen shot of your issue?

Sincerely,
Kira Qian
Send us any feedback you have about the help from MSFT at fbmsdn@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework!
Kira Qian  Tuesday, September 29, 2009 6:08 AM
Yes it is a tabpage in a tabpagecontrol.

The one wtih 3 panels is to complicated of a form to screenshot and black everythign so here is a picture of another control in the same program that has a simliar problem.

In the normal size view you can see where everything should be and their anchors. When the form is loaded in this size and then resized everything moves as expected.

http://img.photobucket.com/albums/v519/spreston36/VS/normalsize.jpg

Here is the view when the control is loaded maximized. You can see how the panel is no longer centered and one of the buttons that was in the lower right is now towards the center. After the control is loaded maximized like this the resizing is very odd and buttons end up off screen.

http://img.photobucket.com/albums/v519/spreston36/VS/maximized.jpg

Without ME its just Aweso  Tuesday, September 29, 2009 11:55 AM
Hello,

Thank you for posting the screen shot.

From the picture, I can see the button (anchor to bottom) and two textboxes (one above and one below anchor to top) look properly when maximized. It seems only the rectangle with 3 textboxes in it don’t act properly. Is there any difference between them?

Sincerely,
Kira Qian
Send us any feedback you have about the help from MSFT at fbmsdn@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework!
Kira Qian  Wednesday, September 30, 2009 6:50 AM
From looking at properties i cant find anything thats different. There is also one button that should be in the bottomr ight that ends up floating in the middle of the screen on maximized load. That button that ends up floating has the exact same properties as the one that is right above it in the normal resolution. So I cant figure out why it jumps up there while the other one doesnt.

Theblack box at the top is a panel that has those controls inside of it. I drew that black box so you could see the grouping's since the panel is set to transparent.
Without ME its just Aweso  Wednesday, September 30, 2009 11:59 AM

You can use google to search for other answers

Custom Search

More Threads

• General paths problem
• [VS.NET 2003] DataGrid event
• Library for Printing HTML?
• help plzzz, strange result
• Custom pick-able item to draw in Graphics?
• datagrid view properties are not working in main application
• Crystal Report using MySql
• ComboBox Problems
• IPersistComponentSettings example for component
• Problems creating XML and Schema from SQL