Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. auto position

auto position

Scheduled Pinned Locked Moved C#
question
10 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    benjamin yap
    wrote on last edited by
    #1

    Hi, i have a form which is size 500 * 300 I have groupbox, textboxes, and buttons inside that form. When the form is loading into my main mdi parent form, its size is 500*300, when i maximize the childform, my controls all are at the position top left. How do i make it center( when the window is maximize) depending on the screen size?

    S 1 Reply Last reply
    0
    • B benjamin yap

      Hi, i have a form which is size 500 * 300 I have groupbox, textboxes, and buttons inside that form. When the form is loading into my main mdi parent form, its size is 500*300, when i maximize the childform, my controls all are at the position top left. How do i make it center( when the window is maximize) depending on the screen size?

      S Offline
      S Offline
      sunspeed
      wrote on last edited by
      #2

      If you want to center the groupbox, not the controls in it, personally I would recalc the Location from the groupbox on the maximize event. The controls in the groupbox will change their location automatically. For the other controls outside the groupbox, use a panel and calc its location as you do for the groupbox. Hope this helps

      Tiefe Brunnen muss man graben wenn man klares Wasser will, tiefe Wasser sind nicht still.

      B 1 Reply Last reply
      0
      • S sunspeed

        If you want to center the groupbox, not the controls in it, personally I would recalc the Location from the groupbox on the maximize event. The controls in the groupbox will change their location automatically. For the other controls outside the groupbox, use a panel and calc its location as you do for the groupbox. Hope this helps

        Tiefe Brunnen muss man graben wenn man klares Wasser will, tiefe Wasser sind nicht still.

        B Offline
        B Offline
        benjamin yap
        wrote on last edited by
        #3

        how to i recalculate the location? do i have to so some division or multiplication or somthing./

        D S 2 Replies Last reply
        0
        • B benjamin yap

          how to i recalculate the location? do i have to so some division or multiplication or somthing./

          D Offline
          D Offline
          dan sh
          wrote on last edited by
          #4

          You do not need to any calculations if you do proper anchoring. It will solve the purpose. Use TableLayoutPanel in case you find it difficult to anchor controls as such.

          Avoid Google. Use Blackle[^]

          S 1 Reply Last reply
          0
          • B benjamin yap

            how to i recalculate the location? do i have to so some division or multiplication or somthing./

            S Offline
            S Offline
            sunspeed
            wrote on last edited by
            #5

            youp, heres a example. Point newLocation = new Point(); newLocation.X = (int)(this.Width - groupBox1.Width) / 2; newLocation.Y = (int)(this.Height - groupBox1.Height) / 2; groupBox1.Location = newLocation;

            Tiefe Brunnen muss man graben wenn man klares Wasser will, tiefe Wasser sind nicht still.

            1 Reply Last reply
            0
            • D dan sh

              You do not need to any calculations if you do proper anchoring. It will solve the purpose. Use TableLayoutPanel in case you find it difficult to anchor controls as such.

              Avoid Google. Use Blackle[^]

              S Offline
              S Offline
              sunspeed
              wrote on last edited by
              #6

              anchoring changes the size of the control to center i thought? imho if you want to center the control without changing its size, you have to recalc.

              Tiefe Brunnen muss man graben wenn man klares Wasser will, tiefe Wasser sind nicht still.

              D 1 Reply Last reply
              0
              • S sunspeed

                anchoring changes the size of the control to center i thought? imho if you want to center the control without changing its size, you have to recalc.

                Tiefe Brunnen muss man graben wenn man klares Wasser will, tiefe Wasser sind nicht still.

                D Offline
                D Offline
                dan sh
                wrote on last edited by
                #7

                <blockquote class="FQ"><div class="FQA">sunspeed wrote:</div>imho</blockquote> What does this mean? If used smartly, anchoring can help you postion the control to centre the control with or without resizing. I have created a sample form in which control will be at centre(and of same size) regardless of how you resize the form.

                Avoid Google. Use Blackle[^]

                S 1 Reply Last reply
                0
                • D dan sh

                  <blockquote class="FQ"><div class="FQA">sunspeed wrote:</div>imho</blockquote> What does this mean? If used smartly, anchoring can help you postion the control to centre the control with or without resizing. I have created a sample form in which control will be at centre(and of same size) regardless of how you resize the form.

                  Avoid Google. Use Blackle[^]

                  S Offline
                  S Offline
                  sunspeed
                  wrote on last edited by
                  #8

                  Could you send me the code? Thats interesting. I have not found this possibility. imho means "in my humble opinion"

                  Tiefe Brunnen muss man graben wenn man klares Wasser will, tiefe Wasser sind nicht still.

                  D 1 Reply Last reply
                  0
                  • S sunspeed

                    Could you send me the code? Thats interesting. I have not found this possibility. imho means "in my humble opinion"

                    Tiefe Brunnen muss man graben wenn man klares Wasser will, tiefe Wasser sind nicht still.

                    D Offline
                    D Offline
                    dan sh
                    wrote on last edited by
                    #9

                    Here it is: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace CPProj { public partial class Anchoring : Form { #region Constructors public Anchoring() { // Default constructor InitializeComponent(); } // Anchoring #endregion #region Code from Designer File /// <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); } /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); this.grpSample = new System.Windows.Forms.GroupBox(); this.btnSample = new System.Windows.Forms.Button(); this.tableLayoutPanel1.SuspendLayout(); this.grpSample.SuspendLayout(); this.SuspendLayout(); // // tableLayoutPanel1 // this.tableLayoutPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.tableLayoutPanel1.ColumnCount = 3; this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 110F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.tableLayoutPanel1.Controls.Add(this.grpSample, 1, 1); this.tableLayoutPanel1.Location = new System.Drawing.Point(3, 12); this.tableLayoutPan

                    S 1 Reply Last reply
                    0
                    • D dan sh

                      Here it is: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace CPProj { public partial class Anchoring : Form { #region Constructors public Anchoring() { // Default constructor InitializeComponent(); } // Anchoring #endregion #region Code from Designer File /// <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); } /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); this.grpSample = new System.Windows.Forms.GroupBox(); this.btnSample = new System.Windows.Forms.Button(); this.tableLayoutPanel1.SuspendLayout(); this.grpSample.SuspendLayout(); this.SuspendLayout(); // // tableLayoutPanel1 // this.tableLayoutPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.tableLayoutPanel1.ColumnCount = 3; this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 110F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.tableLayoutPanel1.Controls.Add(this.grpSample, 1, 1); this.tableLayoutPanel1.Location = new System.Drawing.Point(3, 12); this.tableLayoutPan

                      S Offline
                      S Offline
                      sunspeed
                      wrote on last edited by
                      #10

                      ah, ok you use the TableLayoutPanel thats one possiblity. Thanks for that example! cheers

                      Tiefe Brunnen muss man graben wenn man klares Wasser will, tiefe Wasser sind nicht still.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups