1

我一直在搞一些应该很简单的事情。

我已经换了工作,并试图获得一些我以前使用过的基本工具,但当然我没有旧的资源可以查看。

我们扩展了面板以具有一些标准属性和功能(保存、关闭、保存和关闭)。

但是我无法在调整大小时正确定位按钮。我把这个 ExtPanel 放在一个表单上,但是当我调整大小时,按钮一直消失,或者没有按预期移动(冻结在右下角)。

班上

public partial class ExtPanel: UserControl
   {
   private System.Windows.Forms.Button btnSaveandClose;
   private System.Windows.Forms.Button btnCancel;
   private System.Windows.Forms.Button btnSave;

   public ExtPanel ()
      {
      InitializeComponent ();
      }

// misc things this class does...


}

public partial class ExtPanel
    {
    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.panel1 = new System.Windows.Forms.Panel();
        this.panel1.SuspendLayout();
        this.SuspendLayout();
        // 
        // btnSaveandClose
        // 
        this.btnSaveandClose.Location = new System.Drawing.Point(899, 689);
        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);
        this.btnSaveandClose.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));

        // 
        // btnCancel
        // 
        this.btnCancel.Location = new System.Drawing.Point(687, 689);
        this.btnCancel.Name = "btnCancel";
        this.btnCancel.Size = new System.Drawing.Size(100, 30);
        this.btnCancel.TabIndex = 1;
        this.btnCancel.Text = "Cancel";
        this.btnCancel.UseVisualStyleBackColor = true;
        this.btnCancel.Click += new System.EventHandler(this.Click_Close);
        this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));

        // 
        // btnSave
        // 
        this.btnSave.Location = new System.Drawing.Point(793, 689);
        this.btnSave.Name = "btnSave";
        this.btnSave.Size = new System.Drawing.Size(100, 30);
        this.btnSave.TabIndex = 2;
        this.btnSave.Text = "Save";
        this.btnSave.UseVisualStyleBackColor = true;
        this.btnSave.Click += new System.EventHandler(this.Click_Save);
        this.btnSave.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));

        // 
        // panel1
        // 
        this.panel1.AutoScroll = true;
        this.panel1.Controls.Add(this.btnSave);
        this.panel1.Controls.Add(this.btnCancel);
        this.panel1.Controls.Add(this.btnSaveandClose);
        this.panel1.Location = new System.Drawing.Point(0, 0);
        this.panel1.Name = "panel1";
        this.panel1.Size = new System.Drawing.Size(1008, 730);
        this.panel1.TabIndex = 0;
        // 
        // ExtPanel
        // 
        this.Controls.Add(this.panel1);
        this.Name = "ExtPanel";
        this.Size = this.panel1.Size;
        this.Click += new System.EventHandler(this.click_this);
        this.panel1.ResumeLayout(false);
        this.ResumeLayout(false);

        }

    #endregion

    private System.Windows.Forms.Panel panel1;


}
4

1 回答 1

7

您是否尝试过锚定按钮?

...我错过了锚定代码。

如果您在右下角有一个按钮,并且您希望在调整表单大小时将其保留在右下角,请将其锚属性设置为 Bottom, Right。

更新:
我加载了你的代码。你有一个面板里面ExtPanel。如果您停靠 ( Fill) 该面板,那么您应该可以通过调整 ExtPanel 的大小来正常工作。

于 2012-07-06T20:57:43.890 回答