如何从 THtmlViewer 对象复制和粘贴?
目前我有以下技巧:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在用户按下 Ctrl-C 时执行某些操作(即使用您自己的解决方案#1),
或者您可以按照此处所述实现弹出菜单(即您自己的解决方案#2)
向 Delphi 的 TRichEdit 添加标准上下文(弹出)菜单
You could do something when the user presses Ctrl-C (ie. use your own solution #1)
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