保持按钮位置从基类不变

时间:2013-01-23 18:05:36

标签: c# forms button location size

类似于我在使用我作为基类制作的表单时问here的问题,并重新调整大小,我的按钮丢失了。我确定这是因为我重新调整了表单大小并且按钮位置位于页面外的位置,所以当我重新调整大小时它们仍然不在页面上,只是不知道如何修复它。一个简单的解决方法是在load事件上重新调整大小,但这不能让我正确设计页面 - 而且我真的只想让按钮始终从底部向上10-20,从右向向5-15 - 无论我如何调整表格大小。提前谢谢。

基本表格:

    namespace EXT
        {
        partial class ExtFormCard
            {
            private void InitializeComponent ()
                {
                this.btnSaveandClose = new System.Windows.Forms.Button();
                this.btnCancel = new System.Windows.Forms.Button();
                this.btnSave = new System.Windows.Forms.Button();
                this.SuspendLayout();
               // 
                // btnSaveandClose
                // 
                this.btnSaveandClose.Anchor = ((System.Windows.Forms.AnchorStyles)        ((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
               this.btnSaveandClose.Location = new System.Drawing.Point(899, 663);
                this.btnSaveandClose.Name = "btnSaveandClose";
                this.btnSaveandClose.Size = new System.Drawing.Size(100, 30);
                this.btnSaveandClose.TabIndex = 0;
                this.btnSaveandClose.Text = "Save and Close";
                this.btnSaveandClose.UseVisualStyleBackColor = true;
                this.btnSaveandClose.Click += new System.EventHandler(this.Click_SaveandClose);

            ... other buttons
            ...
                //
                // ExtFormCard
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(1200, 874);
                this.Controls.Add(this.btnSave);
                this.Controls.Add(this.btnCancel);
                this.Controls.Add(this.btnSaveandClose);
                this.Name = "ExtFormCard";
                this.Text = "ExtFormCard";
                this.ResumeLayout(false);
                }

            private System.Windows.Forms.Button btnSaveandClose;
            private System.Windows.Forms.Button btnCancel;
            private System.Windows.Forms.Button btnSave;
            }
        }

新表格:

    namespace IDVisitorWindowsForms.Manager
        {
        public partial class AnswerForm : EXT.ExtFormCard
            {
            public AnswerForm ()
                {
                InitializeComponent ();
                }
            }
        }

    namespace IDVisitorWindowsForms.Manager
        {
        partial class AnswerForm
            {
            #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.SuspendLayout();
                // 
                // AnswerForm
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF (6F, 13F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size (724, 411);
                this.Name = "AnswerForm";
                this.Text = "Answer Form";
                this.Load += new System.EventHandler(this.AnswerForm_Load);
                this.ResumeLayout(false);

               }

            #endregion
            }
        }

1 个答案:

答案 0 :(得分:0)

使用WinForms时,您可以Anchor控件。这在“属性”框中完成。在锚定时,选择要锚定到的父容器的边。

锚定一个控件意味着它将保持其相对于它所在容器侧面的位置(间距)。在您的示例中,您需要将按钮的底部和右侧固定,以便它们始终是你想远离那些方面的距离。