【发布时间】:2021-12-22 01:17:09
【问题描述】:
我有以下布局层次结构:
wxMDIChildFrame -> wxNotebook -> wxScrolledWindow -> wxBoxSizer -> wxStyledTextCtrl
目标: wxStyledTextCtrl (CScriptWnd) 会在用户添加或删除一行或按 Shift+Enter 将另一个 CScriptWnd 添加到 wxScrolledWindow 时自行调整大小。
下面的代码是添加一行的时候:
void CScriptWnd::OnNewLineAdded(wxStyledTextEvent& event)
{
long col, line;
PositionToXY(GetInsertionPoint(), &col, &line);
auto ClientSize = GetClientSize();
int Height = ClientSize.GetHeight();
Height += TextHeight(line);
SetClientSize(ClientSize.GetWidth(), Height);
SetMinSize(wxSize(ClientSize.GetWidth(), Height));
Refresh();
//m_ParentWindow->FitInside(); //CScriptWnd gets smaller rather than larger
//m_ParentWindow->Layout(); //CScriptWnd gets smaller rather than larger
//m_ParentWindow->GetGrandParent()->Layout(); //No effect
event.Skip();
}
大多数工作都很好,例如 CScriptWnd 自行调整大小,添加到 wxScrolledWindow 的新脚本窗口等...
问题是用户界面的更新只有在使用鼠标调整 wxMDIChildFrame 的大小时才会正确发生。
例如,如果有两个CScriptWnd 并且顶部的自己调整大小,它会与底部的重叠
直到使用鼠标调整 wxMDIChildFrame 的大小。滚动条的可见性也发生了类似的情况,当CScriptWnd 客户端大小变大时,滚动条只有在使用鼠标调整顶级窗口大小时才可见。
不知道我错过了什么。
【问题讨论】:
-
到目前为止
GetParent()->FitInside()似乎提供了最好的效果。CScriptWnd的增长和缩小没有任何问题,也没有任何重叠,滚动条会自动出现或消失。