I am having trouble getting controls to position themselves in the upper left corner of a Windows.Forms.Panel which is hosting a WinGridBagLayoutPanel. There are a number of controls that are under the control of the WinGridBagLayoutPanel and are ending up against the left and vertically centered. The relative positions of the individual controls is perfect but I need to have the controls cluster at the top left corner of the panel. Any ideas?
Hi,
I'm having a hard time understanding what you are trying to do. Can you post a screen shot or two showing what you need?
In the following screen shot the selected area is a Panel. This Panel has a number of children which are properly clustered relative to each other and properly positioned to the left side of the Panel. However, the cluster is improperly aligned vertically. It is desired that the cluster be aligned to the top left corner of the Panel, not the middle left.
Okay, so I think what you probably need to do is set the ExpandToFitHeight property on the UltraGridBagLayoutPanel to true. You might also want to set ExpandToFitWidth, but I think it might already be true, or I don't see how you could have aligned the controls to the left as you have.
You will also need to set the Fill property on the GridBagLayout.GridBagConstrint of each individual control within the panel to None (or maybe Veritcal) so it doesn't increase it's height to fill the entire space.
I'd already tried that and it does not do the trick. Setting the ExpandToFitHeight property results in the controls being spread vertically across the entire panel. The GridBagConstraint is already None. Setting it to anything else causes the size of the control to be modified to fill Panel space vertically or horizontally.
In the attached screenshot notice that the controls are now laid out so that the control group occupies all available vertical space. This is not what we want. The bottom multiline edit control's GridBagConstraint has been changed from None to Vertical. The dotted rectangle shows where the control used to be before it was changed and the white rectangle shows where the layout manager moved it to.
Hm, okay I think I see the confusion, now.
I was saying you should set the Anchor to TopLeft, not just Left.
But I see now that when I originally tested this, I was using only a single control. I tried it just now with a couple of UltraLabels and a couple of UltraTextEditors and I don't really see any great way to make this work.
I can get something pretty close if I explicitly size the labels heights and widths, but the bottom row of controls ends up filling to the bottom.
Maybe what you need to do here is use a smaller UltraGridLayoutPanel and then simply position the whole panel in the upper left of some other container (it looks like you are using an UltraExpandableGroupBox.
I guess I was not clear enough. What I want is for the cluster of controls to be positioned in the upper left of the parent panel. What I am getting is the cluster is vertically centered and against the left side of the parent. Close but no cigar. The first screen shot demonstrates what I'm getting.
The purpose of the second shot was to demonstrate what I get when I followed your suggested settings. Again, not what I want.
The UltraGridBagLayoutManager's 'ExpandToFitHeight' is false. When I follow your suggestion of "Okay, so I think what you probably need to do is set the ExpandToFitHeight property on the UltraGridBagLayoutPanel to true. " then that's when the results of screen shot 2 are achieved.
On the individual controls the GridBagContraints are set like this:
Are you able to position the child controls in the upper left corner of the parent panel?
I'm confused. You are saying that you do not want the controls to occupy the entire vertical size of the panel. So why are you setting the GridBagConstraint.Fill property on the control to Vertical? If you don't want it to fill the whole vertical space, you should be setting it to None. You seem to be saying that it was working the way you want and then you changed it. But why change it if it was already doing what you wanted?
Maybe I am just failing to understand what you want. Your original post said you want the controls aligned to the top left and not to fill the entire space. When I tried this out, I was able to get this to happen with the property settings I described above. It worked for me, so either I must be misunderstanding what you want or something else is going on in your application settings that is playing a role here and changing the behavior.