简体   繁体   English

如何在TForm的边界之外显示控件(例如TListbox)

[英]How to display a control (e.g. TListbox) beyond the borders of a TForm

How can I display a Listbox beyond the borders of the parent Form at runtime: 如何在运行时如何在父窗体的边界之外显示列表框:

在此处输入图片说明

The image is obtained from the IDE when clicking on the listbox in design time. 在设计时单击列表框时,将从IDE获取图像。 I would like to achieve this effect at runtime. 我想在运行时实现这种效果。

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.

相关问题 如何调用网络服务方法进行测试,例如从浏览器 - How to call a webservice method for testing, e.g. from a browser 在鼠标拖出边界后,控件如何接收鼠标事件? - How can a control receive mouse events after the mouse is dragged beyond its borders? TForm.OnKeyDown中的KeyPreview的键处理不适用于TListBox - Key handling with KeyPreview in TForm.OnKeyDown does not work with TListBox 如何在TForm以外的控件中捕获WM_DEVICECHANGE? - How to catch WM_DEVICECHANGE in a control other than TForm? 如何从FireMonkey TListBox控件中删除边界线? - How can I remove the border line from a FireMonkey TListBox control? 如何将只有十个字符的字符串(例如“ 12345 * 45688”)拆分为数组 - How to split a string of only ten characters e.g.“12345*45688” into an array 如何使用SuperObject序列化包含点(例如IP地址)的JSON密钥? - How to serialize JSON key containing dots (like e.g. IP address) with SuperObject? 如何在每个项目文件夹中保存dcu文件(例如:。\ $(平台)\ $(配置)\ $(ProjectFilename)? - How to keep dcu files in per project folder (e.g.: .\$(Platform)\$(Config)\$(ProjectFilename)? 如何正确地流传输子组件的TCollection属性,例如嵌入式TDBGrid的Columns属性 - How to correctly stream a TCollection property of a subcomponent, e.g. the Columns property of an embedded TDBGrid 使用DefineProperties替换TPersistent属性,例如TFont - Use DefineProperties to replace TPersistent properties e.g. TFont
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM