关键PANEL排列的,绝对有难度

jxzqsun 2005-03-26 02:57:08
___________________
|   p1    |
|-----------------
| |      |
| |  memo  |
|p2|      |
| |____________|
| |  p3   |
|__⊥_____________|
谁能画出这样的图形
上面的panel---> p1 altop
左边的panel--->p2 alleft
右下的panel--->p3 albuttom
中间那个memo alclient
要求不能增加panel等控件,就是以上4个控件能达到图中的效果
...全文
148 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
王集鹄 2005-03-27
  • 打赏
  • 举报
回复
放一个TApplicationEvents控件,处理OnMessage事件代码

procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
begin
if Msg.hwnd = Memo1.Handle then
{ TODO }
end;
jxzqsun 2005-03-27
  • 打赏
  • 举报
回复
不好意思,呵呵,刚才直接用上面的代码就OK了,所以没注意,我以为下面是另外一个方法,不好意思
jxzqsun 2005-03-27
  • 打赏
  • 举报
回复
DoAlign(alTop);
DoAlign(alBottom);
DoAlign(alLeft);
DoAlign(alRight);
DoAlign(alClient);
这个我就不明白怎么写了,怎么说doalign没定义呢?不好意思,水了点,多多包涵
jxzqsun 2005-03-27
  • 打赏
  • 举报
回复
谢谢,真的有用。

我是要接收WndProc消息,这个消息呢,只能传到FORM上,如果我MEMO在PANEL里面就接收不到给MEMO的消息了,我也觉得纳闷,无奈才想到重新排列,把MEMO放到FORM上

我暂时先不揭贴,我们先讨论,分随时都可以给你。谢谢大师!
herman~~ 2005-03-27
  • 打赏
  • 举报
回复
同意楼上的
caiso 2005-03-27
  • 打赏
  • 举报
回复
帮顶一下
jxzqsun 2005-03-27
  • 打赏
  • 举报
回复
ok
jxzqsun 2005-03-27
  • 打赏
  • 举报
回复
我先给分,再测试一下,谢谢 zswang(伴水清清)(专家门诊清洁工)
王集鹄 2005-03-26
  • 打赏
  • 举报
回复
参考TWinControl::AlignControls()的方法(这个方法可以重载)
AlignList := TList.Create;
try
DoAlign(alTop);
DoAlign(alBottom);
DoAlign(alLeft);
DoAlign(alRight);
DoAlign(alClient);
DoAlign(alCustom);
DoAlign(alNone);// Move anchored controls
ControlsAligned;
finally
AlignList.Free;
end;
可以看到排列顺序是:上、下、左、右……
DoAlign(alTop);
DoAlign(alBottom);
DoAlign(alLeft);
DoAlign(alRight);
DoAlign(alClient);
只要改变成,上、左、右、下……


-------------“memo1的parent必须为self,这样才能接收发送给MEMO1的消息”
这个话看不明白,能不能贴出能调试的代码,分析分析原因,找到最简洁的解决方法
王集鹄 2005-03-26
  • 打赏
  • 举报
回复
//参考如下代码
type
TForm1 = class(TForm)
Memo1: TMemo;
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
private
{ Private declarations }
FAnchorRules: TPoint;
FOriginalParentSize: TPoint;
FAnchorMove: Boolean;
procedure UpdateAnchorRules;
protected
procedure AlignControls(AControl: TControl; var Rect: TRect); override;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

{ TForm1 }

procedure TForm1.AlignControls(AControl: TControl; var Rect: TRect);
var
AlignList: TList;

function InsertBefore(C1, C2: TControl; AAlign: TAlign): Boolean;
begin
Result := False;
case AAlign of
alTop: Result := C1.Top < C2.Top;
alBottom: Result := (C1.Top + C1.Height) >= (C2.Top + C2.Height);
alLeft: Result := C1.Left < C2.Left;
alRight: Result := (C1.Left + C1.Width) >= (C2.Left + C2.Width);
alCustom: Result := CustomAlignInsertBefore(C1, C2);
end;
end;

procedure DoPosition(Control: TControl; AAlign: TAlign; AlignInfo: TAlignInfo);
var
NewLeft, NewTop, NewWidth, NewHeight: Integer;
ParentSize: TPoint;
begin
with Rect do
begin
if (AAlign = alNone) or (Control.Anchors <> AnchorAlign[AAlign]) then
begin
with Control do
if (FOriginalParentSize.X <> 0) and (FOriginalParentSize.Y <> 0) then
begin
NewLeft := Left;
NewTop := Top;
NewWidth := Width;
NewHeight := Height;
if Parent.HandleAllocated then
ParentSize := Parent.ClientRect.BottomRight
else
ParentSize := Point(Parent.Width, Parent.Height);
if akRight in Anchors then
if akLeft in Anchors then
// The AnchorRules.X is the original width
NewWidth := ParentSize.X - (FOriginalParentSize.X - FAnchorRules.X)
else
// The AnchorRules.X is the original left
NewLeft := ParentSize.X - (FOriginalParentSize.X - FAnchorRules.X)
else if not (akLeft in Anchors) then
// The AnchorRules.X is the original middle of the control
NewLeft := MulDiv(FAnchorRules.X, ParentSize.X, FOriginalParentSize.X) -
NewWidth div 2;
if akBottom in Anchors then
if akTop in Anchors then
// The AnchorRules.Y is the original height
NewHeight := ParentSize.Y - (FOriginalParentSize.Y - FAnchorRules.Y)
else
// The AnchorRules.Y is the original top
NewTop := ParentSize.Y - (FOriginalParentSize.Y - FAnchorRules.Y)
else if not (akTop in Anchors) then
// The AnchorRules.Y is the original middle of the control
NewTop := MulDiv(FAnchorRules.Y, ParentSize.Y, FOriginalParentSize.Y) -
NewHeight div 2;
FAnchorMove := True;
try
SetBounds(NewLeft, NewTop, NewWidth, NewHeight);
finally
FAnchorMove := False;
end;
end;
if AAlign = alNone then Exit;
end;

NewWidth := Right - Left;
if (NewWidth < 0) or (AAlign in [alLeft, alRight, alCustom]) then
NewWidth := Control.Width;
NewHeight := Bottom - Top;
if (NewHeight < 0) or (AAlign in [alTop, alBottom, alCustom]) then
NewHeight := Control.Height;
NewLeft := Left;
NewTop := Top;
case AAlign of
alTop:
Inc(Top, NewHeight);
alBottom:
begin
Dec(Bottom, NewHeight);
NewTop := Bottom;
end;
alLeft:
Inc(Left, NewWidth);
alRight:
begin
Dec(Right, NewWidth);
NewLeft := Right;
end;
alCustom:
CustomAlignPosition(Control, NewLeft, NewTop, NewWidth,
NewHeight, Rect, AlignInfo);
end;
end;
Control.SetBounds(NewLeft, NewTop, NewWidth, NewHeight);

if (Control.Width <> NewWidth) or (Control.Height <> NewHeight) then
with Rect do
case AAlign of
alTop: Dec(Top, NewHeight - Control.Height);
alBottom: Inc(Bottom, NewHeight - Control.Height);
alLeft: Dec(Left, NewWidth - Control.Width);
alRight: Inc(Right, NewWidth - Control.Width);
alClient:
begin
Inc(Right, NewWidth - Control.Width);
Inc(Bottom, NewHeight - Control.Height);
end;
end;
end;

function Anchored(Align: TAlign; Anchors: TAnchors): Boolean;
begin
case Align of
alLeft: Result := akLeft in Anchors;
alTop: Result := akTop in Anchors;
alRight: Result := akRight in Anchors;
alBottom: Result := akBottom in Anchors;
alClient: Result := Anchors = [akLeft, akTop, akRight, akBottom];
else
Result := False;
end;
end;

procedure DoAlign(AAlign: TAlign);
var
I, J: Integer;
Control: TControl;
AlignInfo: TAlignInfo;
begin
AlignList.Clear;
if (AControl <> nil) and ((AAlign = alNone) or AControl.Visible or
(csDesigning in AControl.ComponentState) and
not (csNoDesignVisible in AControl.ControlStyle)) and
(AControl.Align = AAlign) then
AlignList.Add(AControl);
for I := 0 to ControlCount - 1 do
begin
Control := Controls[I];
if (Control.Align = AAlign) and ((AAlign = alNone) or (Control.Visible or
(Control.ControlStyle * [csAcceptsControls, csNoDesignVisible] =
[csAcceptsControls, csNoDesignVisible])) or
(csDesigning in Control.ComponentState) and
not (csNoDesignVisible in Control.ControlStyle)) then
begin
if Control = AControl then Continue;
J := 0;
while (J < AlignList.Count) and not InsertBefore(Control,
TControl(AlignList[J]), AAlign) do Inc(J);
AlignList.Insert(J, Control);
end;
end;
for I := 0 to AlignList.Count - 1 do
begin
AlignInfo.AlignList := AlignList;
AlignInfo.ControlIndex := I;
AlignInfo.Align := AAlign;
DoPosition(TControl(AlignList[I]), AAlign, AlignInfo);
end;
end;

function AlignWork: Boolean;
var
I: Integer;
begin
Result := True;
for I := ControlCount - 1 downto 0 do
if (Controls[I].Align <> alNone) or
(Controls[I].Anchors <> [akLeft, akTop]) then Exit;
Result := False;
end;

begin
UpdateAnchorRules;
if AlignWork then
begin
AdjustClientRect(Rect);
AlignList := TList.Create;
try
DoAlign(alTop);
DoAlign(alLeft);
DoAlign(alRight);
DoAlign(alBottom);
DoAlign(alClient);
DoAlign(alCustom);
DoAlign(alNone); // Move anchored controls
ControlsAligned;
finally
AlignList.Free;
end;
end;
if Showing then AdjustSize;
end;

procedure TForm1.UpdateAnchorRules;
begin
if Anchors = [akLeft, akTop] then
begin
FOriginalParentSize.X := 0;
FOriginalParentSize.Y := 0;
Exit;
end;
if akRight in Anchors then
if akLeft in Anchors then
FAnchorRules.X := Width else
FAnchorRules.X := Left
else
FAnchorRules.X := Left + Width div 2;
if akBottom in Anchors then
if akTop in Anchors then
FAnchorRules.Y := Height else
FAnchorRules.Y := Top
else
FAnchorRules.Y := Top + Height div 2;
if Parent <> nil then
else if Parent.HandleAllocated then
FOriginalParentSize := Parent.ClientRect.BottomRight
else
begin
FOriginalParentSize.X := Parent.Width;
FOriginalParentSize.Y := Parent.Height;
end;
end;
晨池 2005-03-26
  • 打赏
  • 举报
回复
先设置p1的是altop
然后设置p2的是alLeft
接着设置p3的是alBottom
最后设置memo是alclient
jxzqsun 2005-03-26
  • 打赏
  • 举报
回复
不是,那3个PANEL是做别的显示的,现在我就是想MEMO1能直接放在FORM上,能设置alclient就好了,用程序控制我试过,老是不正常,有时候会有滚动条
我是在FORM的RESIZE里面这样写的
memo1.left:=p2.width;
memo1.width:=self.width-p2.width
memo1.top:=p1.height;
memo1.height:=self.height-p1.height-p3.height;

这样写就会有滚动条,郁闷
bob008 2005-03-26
  • 打赏
  • 举报
回复
要PANEL干什么?你是要那种效果吗?自己画不行吗?为什么要PANEL
jxzqsun 2005-03-26
  • 打赏
  • 举报
回复
因为加容器,memo1就无法接收系统消息了,5555555555555,memo1的parent必须为self,这样才能接收发送给MEMO1的消息
码农天天向上 2005-03-26
  • 打赏
  • 举报
回复
就是!增加Panel有什么不好!几下搞定!关注
liaoqingpeng 2005-03-26
  • 打赏
  • 举报
回复
要实现的话
必须把memo、p3放到一个容器里
要不就只有写代码模仿(可能会事倍功半)
否则是不可能的,
我就想不通,为什么不能多加一个容器
-------------------------------------
楼主,你这个问题可以在这一天解决:
不是星期一
不是星期二
不是星期三
不是星期四
不是星期五
不是星期六
不是星期日
cn2002boy 2005-03-26
  • 打赏
  • 举报
回复
用代码吧,不用控件只有用代码了

5,392

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧