c# - 按钮 anchor 的重新定位不如组中的其他控件快

标签 c# winforms

我试图将两个按钮保持在组框中的相同位置,而其他控件可以调整大小。

这是正常情况下的样子,没有调整大小。我希望这两个按钮位于组框内部的相同相对位置。

Fresh instance without resizing.

当我向左或向右调整表单大小时它起作用,但是当我向上或向下调整它时, 按钮的移动速度似乎比组框中的其他控件慢。

Making form larger

Making form smaller

这是相关的设计器代码:

// 
        // groupBox1
        // 
        this.groupBox1.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.groupBox1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
        this.groupBox1.Controls.Add(this.button_delete);
        this.groupBox1.Controls.Add(this.button_add);
        this.groupBox1.Controls.Add(this.list_files);
        this.groupBox1.Font = new System.Drawing.Font("Lucida Console", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        this.groupBox1.Location = new System.Drawing.Point(13, 42);
        this.groupBox1.Name = "groupBox1";
        this.groupBox1.Size = new System.Drawing.Size(502, 297);
        this.groupBox1.TabIndex = 0;
        this.groupBox1.TabStop = false;
        this.groupBox1.Text = "Audio";
        // 
        // list_files
        // 
        this.list_files.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.list_files.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        this.list_files.GridLines = true;
        this.list_files.Location = new System.Drawing.Point(7, 18);
        this.list_files.Name = "list_files";
        this.list_files.Size = new System.Drawing.Size(489, 239);
        this.list_files.TabIndex = 0;
        this.list_files.UseCompatibleStateImageBehavior = false;
        this.list_files.View = System.Windows.Forms.View.List;
        // 
        // button_add
        // 
        this.button_add.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
        this.button_add.Location = new System.Drawing.Point(7, 264);
        this.button_add.MaximumSize = new System.Drawing.Size(75, 23);
        this.button_add.MinimumSize = new System.Drawing.Size(75, 23);
        this.button_add.Name = "button_add";
        this.button_add.Size = new System.Drawing.Size(75, 23);
        this.button_add.TabIndex = 1;
        this.button_add.Text = "Add File";
        this.button_add.UseVisualStyleBackColor = true;
        this.button_add.Click += new System.EventHandler(this.button_add_Click);
        // 
        // button_delete
        // 
        this.button_delete.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
        this.button_delete.Location = new System.Drawing.Point(88, 264);
        this.button_delete.MaximumSize = new System.Drawing.Size(91, 23);
        this.button_delete.MinimumSize = new System.Drawing.Size(91, 23);
        this.button_delete.Name = "button_delete";
        this.button_delete.Size = new System.Drawing.Size(91, 23);
        this.button_delete.TabIndex = 2;
        this.button_delete.Text = "Remove File";
        this.button_delete.UseVisualStyleBackColor = true;
        this.button_delete.Click += new System.EventHandler(this.button_delete_Click);

最佳答案

尝试将按钮固定在左侧和底部。看起来您正在左右锚定它们。

关于c# - 按钮 anchor 的重新定位不如组中的其他控件快,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38237992/

相关文章:

c# - 我可以将动态创建的 c# 表转换为 html 字符串吗?

c# - 在 NHibernate 中进行渴望加入的最佳方法是什么?

c# - Bitmap.Save 保存一个图标实际上保存了一个.png

c# - 如何通过键入(Windows 资源管理器详细信息 View )跳转到 DataGridView 中的特定行

c# - 如何生成 .svc 文件?

C# GDI+/System.Drawing.Graphics - 创建缓冲区并手动 blitting?

winforms - C# OpenFileDialog 在 Win7 中只显示 XP-Style

c# - 通过 Microsoft.Graph 邀请用户会出现错误

c# - 为什么PropertyInfo.GetValue()需要实例来检索值?

c# - 如何使用 C# 完全隐藏 Windows 窗体中的顶部栏