如何从 THtmlViewer 对象复制和粘贴?

发布于 2024-11-05 10:27:59 字数 609 浏览 0 评论 0原文

目前我有以下技巧:

procedure TForm1.HTMLViewer1KeyDown(Sender: TObject; var Key: Word;
    Shift: TShiftState);
begin
    if (Key = Word('C')) and (Shift = [ssCtrl]) then
        HTMLViewer1.CopyToClipboard;
end;

是否有更明智/可维护的方法来启用从 htmlviewer 进行复制?我希望有一个可以设置的属性,或者其他东西,因为必须执行上述操作似乎很愚蠢。 TCustomEdit 的后代默认具有复制、粘贴和全选功能,但由于某种原因 htmlviewer 似乎没有以这种方式实现。

另一个问题是上述方法也没有考虑右键单击并选择“复制”

编辑:最后我选择用适当的上下文菜单替换上述代码,按照本教程: http://delphi.about.com/od/tmemotrichedit/a/richedit-popup.htm

At the moment I have the following hack:

procedure TForm1.HTMLViewer1KeyDown(Sender: TObject; var Key: Word;
    Shift: TShiftState);
begin
    if (Key = Word('C')) and (Shift = [ssCtrl]) then
        HTMLViewer1.CopyToClipboard;
end;

Is there a more sensible/maintainable way of enabling copying from an htmlviewer? I am hoping that there is a property that I can set, or something, because having to do the above seems stupid. Descendants of TCustomEdit have copying, pasting and select-all-ing by default, but htmlviewer for some reason doesnt seem to be implemented this way.

Another problem is that the above method also doesnt account for right-clicking and selecting "copy"

EDIT: In the end I chose to replace the above code with a proper context menu, as per this tutorial: http://delphi.about.com/od/tmemotrichedit/a/richedit-popup.htm

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

永不分离 2024-11-12 10:27:59

您可以在用户按下 Ctrl-C 时执行某些操作(即使用您自己的解决方案#1),

procedure TForm1.HTMLViewer1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  if (Key = Word('C')) and (Shift = [ssCtrl]) then
    HTMLViewer1.CopyToClipboard;
end;

或者您可以按照此处所述实现弹出菜单(即您自己的解决方案#2)

向 Delphi 的 TRichEdit 添加标准上下文(弹出)菜单

You could do something when the user presses Ctrl-C (ie. use your own solution #1)

procedure TForm1.HTMLViewer1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  if (Key = Word('C')) and (Shift = [ssCtrl]) then
    HTMLViewer1.CopyToClipboard;
end;

or you could implement a popup menu as described here (ie. your own solution #2)

Add a Standard Context (popup) Menu to Delphi's TRichEdit

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文