代码之家  ›  专栏  ›  技术社区  ›  jasonh

锚定控件自行脱离窗体

  •  2
  • jasonh  · 技术社区  · 17 年前

    作为参考,我操纵了设计器生成的代码来重新排列语句的顺序,以便在设置位置和宽度后进行锚定,但这没有什么好处。以下是行为不端的文本框的代码:

            // 
            // txtComments
            // 
            this.txtComments.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.txtComments.Location = new System.Drawing.Point(430, 6);
            this.txtComments.Name = "txtComments";
            this.txtComments.Size = new System.Drawing.Size(166, 20);
            this.txtComments.TabIndex = 25;
    

    以及行为正常的组合框的代码:

            // 
            // cbMacroList
            // 
            this.cbMacroList.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.cbMacroList.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cbMacroList.FormattingEnabled = true;
            this.cbMacroList.Location = new System.Drawing.Point(128, 78);
            this.cbMacroList.Name = "cbMacroList";
            this.cbMacroList.Size = new System.Drawing.Size(468, 21);
            this.cbMacroList.TabIndex = 30;
            this.cbMacroList.SelectedIndexChanged += new System.EventHandler(this.cbMacroList_SelectedIndexChanged);
    

    2 回复  |  直到 17 年前
        1
  •  1
  •   Dave Markle    17 年前

    你确定你行为不端的控件不是由你不期望的东西(如面板或其他东西)造成的吗?

        2
  •  0
  •   jasonh    17 年前

    这是相当奇怪的,但是简单地从表单中删除控件并再次将其放下来就解决了问题。我在使用控件的窗体上重新检查了设计器生成的代码,在创建或添加到窗体中的方式上完全没有区别。然而,它是固定的。我想知道为什么它会这样。。。?