Hello,
I wrote a small sample application to show what I want, so first of all here is the code:
public Form1()
{ InitializeComponent(); // MainLayout // UltraGridBagLayoutPanel mainLayout = new UltraGridBagLayoutPanel(); mainLayout.BackColor = System.Drawing.Color.Coral; mainLayout.ExpandToFitHeight = true; mainLayout.ExpandToFitWidth = true; mainLayout.AutoSize = true; mainLayout.AutoSizeMode = AutoSizeMode.GrowAndShrink; this.Controls.Add(mainLayout); // SubLayout // UltraGridBagLayoutPanel subLayout = new UltraGridBagLayoutPanel(); subLayout.BackColor = System.Drawing.Color.Cyan; subLayout.ExpandToFitHeight = true; subLayout.ExpandToFitWidth = true; subLayout.AutoSize = true; subLayout.AutoSizeMode = AutoSizeMode.GrowAndShrink; // add SubLayout mainLayout.Controls.Add(subLayout); GridBagConstraint constraint = mainLayout.GetGridBagConstraint(subLayout); constraint.OriginX = 0; constraint.OriginY = 0; constraint.SpanX = 1; constraint.SpanY = 1; constraint.WeightX = 1; constraint.WeightY = 1; constraint.Insets.Left = 5; constraint.Insets.Right = 5; constraint.Insets.Top = 5; constraint.Insets.Bottom = 5; // add Label to SubLayout Label tempLabel = new Label(); tempLabel.Text = "Christmas"; subLayout.Controls.Add(tempLabel); constraint = subLayout.GetGridBagConstraint(tempLabel); constraint.OriginX = 0; constraint.OriginY = 0; constraint.SpanX = 1; constraint.SpanY = 1; constraint.WeightX = 1; constraint.WeightY = 1; constraint.Insets.Left = 5; constraint.Insets.Right = 5; constraint.Insets.Top = 5; constraint.Insets.Bottom = 5; // add Label to SubLayout UltraDateTimeEditor dateEdit = new UltraDateTimeEditor(); dateEdit.DateTime = new System.DateTime(2008, 12, 24); subLayout.Controls.Add(dateEdit); constraint = subLayout.GetGridBagConstraint(dateEdit); constraint.OriginX = 1; constraint.OriginY = 0; constraint.SpanX = 1; constraint.SpanY = 1; constraint.WeightX = 1; constraint.WeightY = 1; constraint.Insets.Left = 5; constraint.Insets.Right = 5; constraint.Insets.Top = 5; constraint.Insets.Bottom = 5; // add some Controls to mainLayout RadioButton btn = new RadioButton(); btn.Text = "1"; mainLayout.Controls.Add(btn); constraint = mainLayout.GetGridBagConstraint(btn); constraint.OriginX = 0; constraint.OriginY = 1; constraint.SpanX = 1; constraint.SpanY = 1; constraint.WeightX = 1; constraint.WeightY = 1; constraint.Insets.Left = 5; constraint.Insets.Right = 5; constraint.Insets.Top = 5; constraint.Insets.Bottom = 5; // add some Controls to mainLayout btn = new RadioButton(); btn.Text = "2"; mainLayout.Controls.Add(btn); constraint = mainLayout.GetGridBagConstraint(btn); constraint.OriginX = 0; constraint.OriginY = 2; constraint.SpanX = 1; constraint.SpanY = 1; constraint.WeightX = 1; constraint.WeightY = 1; constraint.Insets.Left = 5; constraint.Insets.Right = 5; constraint.Insets.Top = 5; constraint.Insets.Bottom = 5; // add some Controls to mainLayout btn = new RadioButton(); btn.Text = "3"; mainLayout.Controls.Add(btn); constraint = mainLayout.GetGridBagConstraint(btn); constraint.OriginX = 0; constraint.OriginY = 3; constraint.SpanX = 1; constraint.SpanY = 1; constraint.WeightX = 1; constraint.WeightY = 1; constraint.Insets.Left = 5; constraint.Insets.Right = 5; constraint.Insets.Top = 5; constraint.Insets.Bottom = 5; // add some Controls to mainLayout btn = new RadioButton(); btn.Text = "4"; mainLayout.Controls.Add(btn); constraint = mainLayout.GetGridBagConstraint(btn); constraint.OriginX = 0; constraint.OriginY = 4; constraint.SpanX = 1; constraint.SpanY = 1; constraint.WeightX = 1; constraint.WeightY = 1; constraint.Insets.Left = 5; constraint.Insets.Right = 5; constraint.Insets.Top = 5; constraint.Insets.Bottom = 5; }
What I want is that:
1.) The Layout has arrange its size, that all controls are COMPLETELY visibel (see DateTimeEditor)
2.) Why is there a gap between the SubLayout and the first RadioButton
3.) How do I get the Form streched, to see all Controls
4.) If I do a mainLayout.Dock = DockStyle.Fill then the RadioButtons are not completely visible
What am I doing wrong ?
Regards,
Patrick
Patrick, I'm sure you've moved onto other things in the last 5 years but wanted to point you towards a similar question I asked recently and managed to answer. http://ko.infragistics.com/community/forums/p/79402/402320.aspx#402320
Mike is right it is extremely difficult to layout in code, but fortunately I ignored him and tried it anyway. I've not created my controls at runtime, but hopefully if you achieve that part my LayoutEngine might point you or anyone else in the right direction for laying out the controls dependent upon their runtime contents.
Hi Partick,
One of the major features of the UltraGridBagLayoutPanel is design-time support. You can drag and drop controls around on the design-time surface. So creating this control at run-time will lose out on a whole lot of ease-of-use functionality. It's really difficult to do this sort of layout in code. I recommend setting this up the way you want it at design-time. Then... if you really want to code it at run-time, you can use the designer generated code as a guide.