如何在ShowMessage中显示表格?
我正在尝试使用 ShowMessage 显示一个如下所示的表格:
short | Description for "short"
verylongtext | Description for "verylongtext"
How do I get multiple columns like that in a simple messagedialog?
我尝试使用空格对齐列,但 ShowMessage 的字体是可变的。然后我尝试使用制表符对齐它们,但我不知道如何计算每行正确的制表符计数。
有没有可靠的方法来计算标签数?
PS:我想避免为此目的编写自定义对话框。
I am trying to display a table using ShowMessage that looks like this:
short | Description for "short"
verylongtext | Description for "verylongtext"
How do I get two correctly aligned columns like that in a simple message dialog?
I tried to align the columns using spaces, but the font of ShowMessage is variable. Then I tried to align them using tab characters, but I do not know how to calculate the proper tab count for each row.
Is there a reliable way to calculate the tab count?
PS: I would like to avoid writing a custom dialog for this purpose.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
发布评论
评论(3)
刚刚创建了一些显示弹出窗口的内容,如下所示:
只需调用下面的过程,并添加一个 TStringList 作为参数即可。
当然,您可以通过使用 TListView、图标、滚动条等来实现这一点。
将其放在单独的单元中,您将始终能够轻松地显示这样的内容。
uses ..., StdCtrls, ExtCtrls;
procedure ShowTablePopup(SL:TStringList);
var
LButtonOK: TButton;
LMemo: TMemo;
LPanel: TPanel;
LForm: TForm;
begin
LForm := TForm.Create(Application);
LMemo := TMemo.Create(LForm);
LPanel := TPanel.Create(LForm);
LButtonOK := TButton.Create(LForm);
LForm.Left := 0;
LForm.Top := 0;
LForm.Caption := 'Values';
LForm.ClientHeight := 250;
LForm.ClientWidth := 400;
LMemo.Parent := LForm;
LMemo.AlignWithMargins := True;
LMemo.Left := 3;
LMemo.Top := 3;
LMemo.Width := 295;
LMemo.Height := 226;
LMemo.Align := alClient;
LMemo.Font.Name := 'Courier New';
LMemo.Lines.Assign(SL);
LPanel.Parent := LForm;
LPanel.Caption := '';
LPanel.Left := 0;
LPanel.Top := 232;
LPanel.Width := 301;
LPanel.Height := 37;
LPanel.Align := alBottom;
LPanel.BevelOuter := bvNone;
LButtonOK.Parent := LPanel;
LButtonOK.AlignWithMargins := True;
LButtonOK.Left := 223;
LButtonOK.Top := 3;
LButtonOK.Width := 75;
LButtonOK.Height := 31;
LButtonOK.Align := alRight;
LButtonOK.Caption := '&OK';
LButtonOK.ModalResult := mrOk;
LButtonOK.Default := True;
LForm.ShowModal;
end;
如何使用它的示例:
var
SL:TStringList;
begin
SL := TStringList.Create;
try
SL.Add('short | Description for "short"');
SL.Add('verylongtext | Description for "verylongtext"');
ShowTablePopup(SL);
finally
SL.Free;
end;
end;
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
您也可以在自定义对话框中使用列表视图。
我的类支持标准 Windows 图标(和声音):信息、警告、错误、确认、无。这是无图标版本:
易于使用:
它支持 DPI 缩放(高 DPI)和 Windows XP 以来的所有 Windows 版本(可能适用于 Windows 2000)同样,我只是没有测试过)到 Windows 10:
该表格是列表视图,因此您获得其所有优点,例如滚动条、截断省略号和工具提示:
您还可以指定对话框的大小以使其适合内容:
当然,还有确定按钮既是
默认
又是取消
,因此您可以使用Enter或Escape关闭对话框。最后,按 Ctrl+C 将表格复制到剪贴板。
完整源代码:
更新:新版本支持自定义文本和按钮:
You could use a list view in a custom dialog box, as well.
My class supports the standard Windows icons (and sounds): information, warning, error, confirmation, none. Here is the icon-less version:
It is easy to use:
It supports DPI scaling (high DPI) and all Windows versions from Windows XP (it might work on Windows 2000 as well, I just haven't tested that) to Windows 10:
The table is a list view, so you get all its benefits, like a scrollbar, truncation ellipses, and tooltips:
You can also specify the dialog's size to make it fit the contents:
Of course, the OK button is both
Default
andCancel
, so you can dismiss the dialog with Enter or Escape.Finally, pressing Ctrl+C will copy the table to clipboard.
Full source code:
Update: A new version supports custom text and buttons: