Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
180
Correct Usage of WinGridLayoutPanel
posted

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