如何处理Windows窗体文本框的AutoSize硬编码为true?

我正在为Windows窗体编写具有自动布局的自定义容器。 microsoft文档建议使用以下代码来遵守控件的autosize属性:

if (control.AutoSize)
{
    control.Size = control.GetPreferredSize(parentDisplayRectangle.Size);
}

问题在于文本框似乎已将AutoSize硬编码为true,并在其上调用所提到的代码,如下所示:

如何处理Windows窗体文本框的AutoSize硬编码为true?

我应该如何评估自定义容器控件中文本框的首选大小?


更新:访问Referencesource之后。

DefaultLayout类中有一个有用的注释:

    // Loop through the AutoSized controls and expand them if they are smaller than
    // their preferred size.  If expanding the controls causes overlap,bump the overlapped
    // control if it is AutoRelocatable.

AutoSize的想法似乎是允许控件大于设计的大小,而不是实际上精确地从GetPreferredSize返回的大小。

这有待确认。

来源:DockAndAnchorLayout.cs,class DefaultLayout

largehand 回答:如何处理Windows窗体文本框的AutoSize硬编码为true?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3168635.html

大家都在问