gpt4 book ai didi

delphi - 如何仅设置 1 个特定大小的边框边缘?

转载 作者:行者123 更新时间:2023-12-03 15:51:40 26 4
gpt4 key购买 nike

我有一些通过带有 bsSizeToolWin 边框的表单制作的工具面板,我有窗口移动的自定义处理和用于将工具面板与主表单边框粘贴/对齐的自定义例程(几乎就像对接)功能),但是问题是,使用 bsSizeToolWin 边框样式,我的边框的所有角/边都相当大。

是否可以仅使一个特定的边框一侧变得相当大?(例如,当工具面板粘贴到主窗体的左边框时,我只希望面板的右边框相当大,因为面板的顶部和底部坐标根据主窗体客户区的高度对齐,而左坐标粘贴到主窗体的右边框)

最佳答案

视觉的角度来看,默认情况下,如果窗口具有相当大的边框,那么所有边缘都将绘制为相当大的,否则没有,没有中间的情况,因为 Win32 API 没有每边缘边框样式的概念,只有整个窗口边框样式。如果您希望各种边框看起来不同,则可能必须通过直接处理 WM_NCCALCSIZEWM_NCPAINT 消息来手动自定义绘制边框。

功能的角度来看,阻止用户在特定边缘调整窗口大小是相当容易的。最简单的方法是让面板处理 WM_NCHITTEST 消息。为面板提供正常大小的边框(如果需要,可以自定义绘制),然后让它首先将任何收到的 WM_NCHITTEST 消息传递给默认处理程序,然后根据需要调整结果。这种方法的好处是,操作系统不允许用户抓取任何报告为 HTBORDER(不可调整大小的边框)的边缘,并且不会有任何视觉反馈表明该边缘可调整大小(即使确实如此)。

例如,让我们使用面板左侧对齐的示例。如果默认处理程序返回 HTBOTTOMHTBOTTOMLEFTHTLEFTHTTOPLEFTHTTOP >,返回 HTBORDER 。如果默认处理程序返回 HTBOTTOMRIGHTHTTOPRIGHT,则返回 HTRIGHT。否则返回默认处理程序返回的任何内容。

根据需要调整面板边缘大小的值。

例如:

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;

关于delphi - 如何仅设置 1 个特定大小的边框边缘?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38256553/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com