如何仅设置 1 个特定大小的边框边缘?
How to set only 1 specific sizing border edge?
我有一些工具面板是通过带有 bsSizeToolWin
边框的表单制作的,我有自定义处理 window-movement 和 sticking/aligning 带有 main 边框的工具面板的自定义例程形式(几乎像对接功能),但是 bsSizeToolWin
边框样式的问题我有所有 corners/sides 的边框相当大。
是否可以只使一个特定的边框变大?
(例如,当工具面板贴在主窗体的左边框上时,我只希望面板的右边框足够大,因为面板的顶部和底部坐标根据主窗体客户区的高度对齐,左坐标贴在主窗体的右边框上)
从 视觉 的角度来看,默认情况下,如果 window 具有相当大的边框,则 所有 边缘都被绘制为相当大的,否则none 它们之间没有中间,因为 Win32 API 没有每边边框样式的概念,只有整体 -window 边框样式。如果您希望各种边框看起来不同,您可能必须通过直接处理 WM_NCCALCSIZE
和 WM_NCPAINT
消息来手动自定义绘制边框。
从功能 的角度来看,防止用户调整特定边上的 window 大小是相当容易的。最简单的方法是让面板处理 WM_NCHITTEST
消息。为面板提供正常大小的边框(如果需要,可以自定义绘制),然后让它首先将收到的任何 WM_NCHITTEST
消息传递给默认处理程序,然后根据需要调整结果。这种方法的好处是 OS 将不允许用户抓取报告为 HTBORDER
的任何边缘(不可调整大小的边界),并且不会有边缘可调整大小的视觉反馈(即使真的是)。
例如,让我们使用您的面板左对齐示例。如果默认处理程序 returns HTBOTTOM
、HTBOTTOMLEFT
、HTLEFT
、HTTOPLEFT
或 HTTOP
、return HTBORDER
代替。如果默认处理程序 returns HTBOTTOMRIGHT
或 HTTOPRIGHT
, return HTRIGHT
代替。否则 return 无论默认处理程序如何 returned.
根据您希望放大面板的哪个边缘,根据需要调整值。
例如:
type
TMyPanelForm = class(TForm)
private
fWhichSideCanBeResized: TAlign;
procedure WMNCHitTest(var Message: TMessage); message WM_NCHITTEST;
end;
procedure TMyPanelForm.WMNCHitTest(var Message: TMessage);
begin
inherited;
case fWhichSideCanBeResized of
alLeft:
begin
case Message.Result of
HTBOTTOM, HTBOTTOMRIGHT, HTRIGHT, HTTOPRIGHT, HTTOP:
Message.Result := HTBORDER;
HTBOTTOMLEFT, HTTOPLEFT:
Message.Result := HTLEFT;
end;
end;
alRight:
begin
case Message.Result of
HTBOTTOM, HTBOTTOMLEFT, HTLEFT, HTTOPLEFT, HTTOP:
Message.Result := HTBORDER;
HTBOTTOMRIGHT, HTTOPRIGHT:
Message.Result := HTRIGHT;
end;
end;
alTop:
begin
case Message.Result of
HTLEFT, HTBOTTOMLEFT, HTBOTTOM, HTBOTTOMRIGHT, HTRIGHT:
Message.Result := HTBORDER;
HTTOPLEFT, HTTOPRIGHT:
Message.Result := HTTOP;
end;
end;
alBottom:
begin
case Message.Result of
HTLEFT, HTTOPLEFT, HTTOP, HTTOPRIGHT, HTRIGHT:
Message.Result := HTBORDER;
HTBOTTOMLEFT, HTBOTTOMRIGHT:
Message.Result := HTBOTTOM;
end;
end;
end;
end;
或者:
procedure TMyPanelForm.WMNCHitTest(var Message: TMessage);
begin
inherited;
case Message.Result of
HTLEFT:
if fWhichSideCanBeResized <> alLeft then
Message.Result := HTBORDER;
HTRIGHT:
if fWhichSideCanBeResized <> alRight then
Message.Result := HTBORDER;
HTTOP:
if fWhichSideCanBeResized <> alTop then
Message.Result := HTBORDER;
HTBOTTOM:
if fWhichSideCanBeResized <> alBottom then
Message.Result := HTBORDER;
HTTOPLEFT:
case fWhichSideCanBeResized of
alTop: Message.Result := HTTOP;
alLeft: Message.Result := HTLEFT;
else
Message.Result := HTBORDER;
end;
HTBOTTOMLEFT:
case fWhichSideCanBeResized of
alBottom: Message.Result := HTBOTTOM;
alLeft: Message.Result := HTLEFT;
else
Message.Result := HTBORDER;
end;
HTTOPRIGHT:
case fWhichSideCanBeResized of
alTop: Message.Result := HTTOP;
alRight: Message.Result := HTRIGHT;
else
Message.Result := HTBORDER;
end;
HTBOTTOMRIGHT:
case fWhichSideCanBeResized of
alBottom: Message.Result := HTBOTTOM;
alRight: Message.Result := HTRIGHT;
else
Message.Result := HTBORDER;
end;
end;
end;
我有一些工具面板是通过带有 bsSizeToolWin
边框的表单制作的,我有自定义处理 window-movement 和 sticking/aligning 带有 main 边框的工具面板的自定义例程形式(几乎像对接功能),但是 bsSizeToolWin
边框样式的问题我有所有 corners/sides 的边框相当大。
是否可以只使一个特定的边框变大? (例如,当工具面板贴在主窗体的左边框上时,我只希望面板的右边框足够大,因为面板的顶部和底部坐标根据主窗体客户区的高度对齐,左坐标贴在主窗体的右边框上)
从 视觉 的角度来看,默认情况下,如果 window 具有相当大的边框,则 所有 边缘都被绘制为相当大的,否则none 它们之间没有中间,因为 Win32 API 没有每边边框样式的概念,只有整体 -window 边框样式。如果您希望各种边框看起来不同,您可能必须通过直接处理 WM_NCCALCSIZE
和 WM_NCPAINT
消息来手动自定义绘制边框。
从功能 的角度来看,防止用户调整特定边上的 window 大小是相当容易的。最简单的方法是让面板处理 WM_NCHITTEST
消息。为面板提供正常大小的边框(如果需要,可以自定义绘制),然后让它首先将收到的任何 WM_NCHITTEST
消息传递给默认处理程序,然后根据需要调整结果。这种方法的好处是 OS 将不允许用户抓取报告为 HTBORDER
的任何边缘(不可调整大小的边界),并且不会有边缘可调整大小的视觉反馈(即使真的是)。
例如,让我们使用您的面板左对齐示例。如果默认处理程序 returns HTBOTTOM
、HTBOTTOMLEFT
、HTLEFT
、HTTOPLEFT
或 HTTOP
、return HTBORDER
代替。如果默认处理程序 returns HTBOTTOMRIGHT
或 HTTOPRIGHT
, return HTRIGHT
代替。否则 return 无论默认处理程序如何 returned.
根据您希望放大面板的哪个边缘,根据需要调整值。
例如:
type
TMyPanelForm = class(TForm)
private
fWhichSideCanBeResized: TAlign;
procedure WMNCHitTest(var Message: TMessage); message WM_NCHITTEST;
end;
procedure TMyPanelForm.WMNCHitTest(var Message: TMessage);
begin
inherited;
case fWhichSideCanBeResized of
alLeft:
begin
case Message.Result of
HTBOTTOM, HTBOTTOMRIGHT, HTRIGHT, HTTOPRIGHT, HTTOP:
Message.Result := HTBORDER;
HTBOTTOMLEFT, HTTOPLEFT:
Message.Result := HTLEFT;
end;
end;
alRight:
begin
case Message.Result of
HTBOTTOM, HTBOTTOMLEFT, HTLEFT, HTTOPLEFT, HTTOP:
Message.Result := HTBORDER;
HTBOTTOMRIGHT, HTTOPRIGHT:
Message.Result := HTRIGHT;
end;
end;
alTop:
begin
case Message.Result of
HTLEFT, HTBOTTOMLEFT, HTBOTTOM, HTBOTTOMRIGHT, HTRIGHT:
Message.Result := HTBORDER;
HTTOPLEFT, HTTOPRIGHT:
Message.Result := HTTOP;
end;
end;
alBottom:
begin
case Message.Result of
HTLEFT, HTTOPLEFT, HTTOP, HTTOPRIGHT, HTRIGHT:
Message.Result := HTBORDER;
HTBOTTOMLEFT, HTBOTTOMRIGHT:
Message.Result := HTBOTTOM;
end;
end;
end;
end;
或者:
procedure TMyPanelForm.WMNCHitTest(var Message: TMessage);
begin
inherited;
case Message.Result of
HTLEFT:
if fWhichSideCanBeResized <> alLeft then
Message.Result := HTBORDER;
HTRIGHT:
if fWhichSideCanBeResized <> alRight then
Message.Result := HTBORDER;
HTTOP:
if fWhichSideCanBeResized <> alTop then
Message.Result := HTBORDER;
HTBOTTOM:
if fWhichSideCanBeResized <> alBottom then
Message.Result := HTBORDER;
HTTOPLEFT:
case fWhichSideCanBeResized of
alTop: Message.Result := HTTOP;
alLeft: Message.Result := HTLEFT;
else
Message.Result := HTBORDER;
end;
HTBOTTOMLEFT:
case fWhichSideCanBeResized of
alBottom: Message.Result := HTBOTTOM;
alLeft: Message.Result := HTLEFT;
else
Message.Result := HTBORDER;
end;
HTTOPRIGHT:
case fWhichSideCanBeResized of
alTop: Message.Result := HTTOP;
alRight: Message.Result := HTRIGHT;
else
Message.Result := HTBORDER;
end;
HTBOTTOMRIGHT:
case fWhichSideCanBeResized of
alBottom: Message.Result := HTBOTTOM;
alRight: Message.Result := HTRIGHT;
else
Message.Result := HTBORDER;
end;
end;
end;