我在尝试将文本框锚定到所有 4 个侧面的表单时遇到问题。我在窗体中添加了一个文本框,并将 Multiline 属性设置为 True,将 Anchor 属性设置为 Left、Right、Up 和 Down,以便文本框在运行时随窗体展开和缩小。我在文本框上方和下方还有一些其他控件。
锚定在 Visual Studio 2005 中正常工作(即我可以调整窗体大小并使控件按预期扩展和缩小),但是当我运行项目时,文本框的底部延伸到窗体的底部,在另一个之后通常会出现在其下方的控件。在尝试任何调整大小之前加载表单时会出现此问题。文本框的锚定在顶部、左侧和右侧是正确的;只有底部出现故障。
有没有人听说过这个,如果有,你能找到解决办法吗?
谢谢!
更新:
这是根据 Greg D 的要求的一些设计器代码(我只包括与文本框本身有关的东西,而不是其他控件):
Friend WithEvents txtRecommendationText1 As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.txtRecommendationText1 = New System.Windows.Forms.TextBox
' ...snip...
'txtRecommendationText1
Me.txtRecommendationText1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.txtRecommendationText1.Location = New System.Drawing.Point(4, 127)
Me.txtRecommendationText1.Multiline = True
Me.txtRecommendationText1.Name = "txtRecommendationText1"
Me.txtRecommendationText1.Size = New System.Drawing.Size(223, 149)
Me.txtRecommendationText1.TabIndex = 10
End Sub
另一个更新:
我最初发布的文本框不是从基类表单继承的(尽管它被添加到自定义用户控件类;我可能应该在前面提到过),但我最近在一组完全不相关的控件上遇到了同样的问题继承自基类形式。将这些问题归咎于 .NET 框架中可能存在的错误很容易,但在我看来,它真的开始如此了。