[英]How to display a control (e.g. TListbox) beyond the borders of a TForm
You can not really visually extend the control outside of the parent form. 您不能真正在外观上将控件扩展到父窗体之外。 But you can achieve the effect by creating a separate borderless form for this control and display this secondary form partly over the first form:
但是您可以通过为此控件创建一个单独的无边界表单并部分在第一个表单上显示此辅助表单来实现此效果:
Here Form1
is a main form, with following OnClick
handler for Button1
: 这里
Form1
是一个主要形式,下面是Button1
OnClick
处理程序:
procedure TForm1.Button1Click(Sender: TObject);
begin
Form2 := TForm2.Create(nil);
try
Form2.Left := ClientOrigin.X + 140;
Form2.Top := ClientOrigin.Y + ClientHeight - 20;
Form2.ShowModal;
Edit1.Text := IntToStr(Form2.ModalResult);
finally
Form2.Free;
end;
end;
Since the second form ( Form2
) is not related (child - parent wise) to Form1
we must give its location as screen pixels, but still relative to Form1
. 由于第二个窗体(
Form2
)与Form1
不相关(在子级上为父级),我们必须将其位置指定为屏幕像素,但仍要相对于Form1
。 Therefore we use the Form1.ClientOrigin
(`Form1 client area top and left as screen coordinates) as reference. 因此,我们使用
Form1.ClientOrigin
(“ Form1客户区顶部和左侧作为屏幕坐标”)作为参考。
The second form, Form2
that holds the TListBox
, has following property settings 第二种形式,即拥有
TListBox
Form2
,具有以下属性设置
BorderStyle = bsNone
KeyPreview = True (to catch `Enter` key)
and it has the OnKeyUp
event handler written as 并且它的
OnKeyUp
事件处理程序写为
procedure TForm2.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if Key = VK_RETURN then
ModalResult := ListBox1.ItemIndex;
end;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.