如何在 delphi 中创建聊天标注
How to create a Chat callout in delphi
我想创建一个聊天气球,就像 Messenger 通过 FireMonkey TCalloutPanel 所做的那样,所以我如何通过给它一个文本作为参数然后根据给定的文本调整标注大小来做到这一点 ^^
提前致谢
我很快就写完了。可以以此为例来满足您的特定需求needs/wants。此外,我强烈建议以这种方式使用自定义样式路线,将 TControls 添加到 TListBoxItem(尽管有效)会使 TListbox 滚动变得糟糕。
procedure TForm1.LoadMessage(SelfSent:Boolean;msg:String;var LItem:TListBoxItem);
var
panel:Tcalloutpanel;
memo:TMemo;
begin
panel:=TCalloutPanel.Create(LItem);
panel.Parent:=LItem;
panel.Align:=TAlignLayout.Client;
panel.Margins.Left:=5;
panel.Margins.Right:=5;
panel.Margins.Top:=5;
panel.Margins.Bottom:=5;
if selfSent=true then
panel.CalloutPosition:=TCalloutPosition.right
else
panel.CalloutPosition:=TCalloutPosition.Left;
panel.CalloutOffset:=10;
memo:=TMemo.Create(panel);
memo.Parent:=panel;
memo.Align:=TAlignLayout.Contents;
memo.Margins.Left:=15;
memo.Margins.Right:=15;
memo.Margins.Top:=5;
memo.Margins.Bottom:=5;
memo.HitTest:=false;
memo.Text:=msg;
LItem.Height:=memo.ContentBounds.Height+30;
if LItem.Height<60 then
LItem.Height:=70;
end;
我想创建一个聊天气球,就像 Messenger 通过 FireMonkey TCalloutPanel 所做的那样,所以我如何通过给它一个文本作为参数然后根据给定的文本调整标注大小来做到这一点 ^^
提前致谢
我很快就写完了。可以以此为例来满足您的特定需求needs/wants。此外,我强烈建议以这种方式使用自定义样式路线,将 TControls 添加到 TListBoxItem(尽管有效)会使 TListbox 滚动变得糟糕。
procedure TForm1.LoadMessage(SelfSent:Boolean;msg:String;var LItem:TListBoxItem);
var
panel:Tcalloutpanel;
memo:TMemo;
begin
panel:=TCalloutPanel.Create(LItem);
panel.Parent:=LItem;
panel.Align:=TAlignLayout.Client;
panel.Margins.Left:=5;
panel.Margins.Right:=5;
panel.Margins.Top:=5;
panel.Margins.Bottom:=5;
if selfSent=true then
panel.CalloutPosition:=TCalloutPosition.right
else
panel.CalloutPosition:=TCalloutPosition.Left;
panel.CalloutOffset:=10;
memo:=TMemo.Create(panel);
memo.Parent:=panel;
memo.Align:=TAlignLayout.Contents;
memo.Margins.Left:=15;
memo.Margins.Right:=15;
memo.Margins.Top:=5;
memo.Margins.Bottom:=5;
memo.HitTest:=false;
memo.Text:=msg;
LItem.Height:=memo.ContentBounds.Height+30;
if LItem.Height<60 then
LItem.Height:=70;
end;