Click here to Skip to main content
15,885,953 members
Articles / Programming Languages / C#

Relative Design Components on WinForm

Rate me:
Please Sign up or sign in to vote.
4.83/5 (4 votes)
14 Nov 2012CPOL2 min read 17K   339   12  
Simple code to make your components always fit exact size of Form, during and after resize.
namespace RelativeLayoutTest {
    partial class RelativeTest {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing) {
            if (disposing && (components != null)) {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent() {
            this.leftButton = new System.Windows.Forms.Button();
            this.rightButton = new System.Windows.Forms.Button();
            this.centerButton = new System.Windows.Forms.Button();
            this.BoxLeft = new System.Windows.Forms.GroupBox();
            this.BoxRight = new System.Windows.Forms.GroupBox();
            this.TreeTest = new System.Windows.Forms.TreeView();
            this.ListTest = new System.Windows.Forms.ListBox();
            this.TopLeftLabel = new System.Windows.Forms.Label();
            this.HorizonBottomLabel = new System.Windows.Forms.Label();
            this.WidHeiLabel = new System.Windows.Forms.Label();
            this.TextBoxTest = new System.Windows.Forms.RichTextBox();
            this.BoxLeft.SuspendLayout();
            this.BoxRight.SuspendLayout();
            this.SuspendLayout();
            // 
            // leftButton
            // 
            this.leftButton.Location = new System.Drawing.Point(68, 12);
            this.leftButton.Name = "leftButton";
            this.leftButton.Size = new System.Drawing.Size(112, 23);
            this.leftButton.TabIndex = 0;
            this.leftButton.Text = "Left side button";
            this.leftButton.UseVisualStyleBackColor = true;
            // 
            // rightButton
            // 
            this.rightButton.Location = new System.Drawing.Point(579, 12);
            this.rightButton.Name = "rightButton";
            this.rightButton.Size = new System.Drawing.Size(113, 23);
            this.rightButton.TabIndex = 1;
            this.rightButton.Text = "Right side button";
            this.rightButton.UseVisualStyleBackColor = true;
            // 
            // centerButton
            // 
            this.centerButton.Location = new System.Drawing.Point(305, 12);
            this.centerButton.Name = "centerButton";
            this.centerButton.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
            this.centerButton.Size = new System.Drawing.Size(96, 23);
            this.centerButton.TabIndex = 2;
            this.centerButton.Text = "Center Button";
            this.centerButton.UseVisualStyleBackColor = true;
            // 
            // BoxLeft
            // 
            this.BoxLeft.Controls.Add(this.HorizonBottomLabel);
            this.BoxLeft.Controls.Add(this.TopLeftLabel);
            this.BoxLeft.Location = new System.Drawing.Point(12, 223);
            this.BoxLeft.Name = "BoxLeft";
            this.BoxLeft.Size = new System.Drawing.Size(301, 278);
            this.BoxLeft.TabIndex = 3;
            this.BoxLeft.TabStop = false;
            this.BoxLeft.Text = "TestBox Left";
            // 
            // BoxRight
            // 
            this.BoxRight.Controls.Add(this.WidHeiLabel);
            this.BoxRight.Location = new System.Drawing.Point(343, 223);
            this.BoxRight.Name = "BoxRight";
            this.BoxRight.Size = new System.Drawing.Size(349, 278);
            this.BoxRight.TabIndex = 4;
            this.BoxRight.TabStop = false;
            this.BoxRight.Text = "TestBox Right";
            // 
            // TreeTest
            // 
            this.TreeTest.Location = new System.Drawing.Point(442, 42);
            this.TreeTest.Name = "TreeTest";
            this.TreeTest.Size = new System.Drawing.Size(250, 175);
            this.TreeTest.TabIndex = 5;
            // 
            // ListTest
            // 
            this.ListTest.FormattingEnabled = true;
            this.ListTest.Location = new System.Drawing.Point(343, 42);
            this.ListTest.Name = "ListTest";
            this.ListTest.Size = new System.Drawing.Size(93, 173);
            this.ListTest.TabIndex = 6;
            // 
            // TopLeftLabel
            // 
            this.TopLeftLabel.AutoSize = true;
            this.TopLeftLabel.Location = new System.Drawing.Point(7, 20);
            this.TopLeftLabel.Name = "TopLeftLabel";
            this.TopLeftLabel.Size = new System.Drawing.Size(75, 13);
            this.TopLeftLabel.TabIndex = 0;
            this.TopLeftLabel.Text = "Right and Top";
            // 
            // HorizonBottomLabel
            // 
            this.HorizonBottomLabel.AutoSize = true;
            this.HorizonBottomLabel.Location = new System.Drawing.Point(10, 37);
            this.HorizonBottomLabel.Name = "HorizonBottomLabel";
            this.HorizonBottomLabel.Size = new System.Drawing.Size(144, 13);
            this.HorizonBottomLabel.TabIndex = 1;
            this.HorizonBottomLabel.Text = "Horizontal center and Bottom";
            // 
            // WidHeiLabel
            // 
            this.WidHeiLabel.AutoSize = true;
            this.WidHeiLabel.Location = new System.Drawing.Point(16, 20);
            this.WidHeiLabel.Name = "WidHeiLabel";
            this.WidHeiLabel.Size = new System.Drawing.Size(117, 13);
            this.WidHeiLabel.TabIndex = 0;
            this.WidHeiLabel.Text = "3/4 of width and height";
            // 
            // TextBoxTest
            // 
            this.TextBoxTest.Location = new System.Drawing.Point(12, 41);
            this.TextBoxTest.Name = "TextBoxTest";
            this.TextBoxTest.Size = new System.Drawing.Size(301, 174);
            this.TextBoxTest.TabIndex = 7;
            this.TextBoxTest.Text = "";
            // 
            // RelativeTest
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(704, 513);
            this.Controls.Add(this.TextBoxTest);
            this.Controls.Add(this.ListTest);
            this.Controls.Add(this.TreeTest);
            this.Controls.Add(this.BoxRight);
            this.Controls.Add(this.BoxLeft);
            this.Controls.Add(this.centerButton);
            this.Controls.Add(this.rightButton);
            this.Controls.Add(this.leftButton);
            this.Name = "RelativeTest";
            this.Text = "Test";
            this.Load += new System.EventHandler(this.RelativeTest_Load);
            this.BoxLeft.ResumeLayout(false);
            this.BoxLeft.PerformLayout();
            this.BoxRight.ResumeLayout(false);
            this.BoxRight.PerformLayout();
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.Button leftButton;
        private System.Windows.Forms.Button rightButton;
        private System.Windows.Forms.Button centerButton;
        private System.Windows.Forms.GroupBox BoxLeft;
        private System.Windows.Forms.GroupBox BoxRight;
        private System.Windows.Forms.TreeView TreeTest;
        private System.Windows.Forms.ListBox ListTest;
        private System.Windows.Forms.Label TopLeftLabel;
        private System.Windows.Forms.Label HorizonBottomLabel;
        private System.Windows.Forms.Label WidHeiLabel;
        private System.Windows.Forms.RichTextBox TextBoxTest;
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Poland Poland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions