0

类似于我在这里提出的问题,当我使用我制作的表单作为基类并重新调整它的大小时,我的按钮丢失了。我确定这是因为我重新调整了表单的大小并且按钮放置在页面之外的位置,所以当我重新调整大小时它们仍然在页面之外,只是不知道如何修复它。一个简单的解决方法是在加载事件时重新调整大小,但这并不能让我正确设计页面 - 另外我真的只是希望按钮总是从底部向上 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
            }
        }
4

1 回答 1

0

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

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

于 2013-01-23T18:29:38.577 回答