auto position
-
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?
-
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?
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.
-
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.
how to i recalculate the location? do i have to so some division or multiplication or somthing./
-
how to i recalculate the location? do i have to so some division or multiplication or somthing./
-
how to i recalculate the location? do i have to so some division or multiplication or somthing./
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.
-
-
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.
<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.
-
<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.
-
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.
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
-
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