delphi 按回车键
如何制作一个编辑框,以便当我按 Enter 键时光标仍在其中。然后它会转到网络浏览器中编辑框中的那个网站?
谁能帮助我吗?
How can I make an edit box so that when I hit enter with the cursor still in it. Then it goes to that website in the webbrowser which was in the edit box?
can anyone help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该使用
OnKeyPress
事件而不是OnKeyDown
事件:You should use the
OnKeyPress
event instead of theOnKeyDown
event:在窗体上拖放一个
TEdit
和一个TWebBrowser
,并为编辑控件编写一个事件处理程序,即OnKeyDown
:为了让它稍微优雅一些,我建议
更新
如果您希望在系统默认浏览器中打开 URL,而不是在表单上的
TWebBrowser
中打开,请替换WebBrowser1.Navigate(Edit1.Text)
将
ShellAPI
添加到 use 子句后, 。但现在请注意,您必须明确协议。例如,bbc.co.uk
不起作用,但http://bbc.co.uk
可以。Drop a
TEdit
and aTWebBrowser
on the form, and write an event handler to the edit control, namelyOnKeyDown
:To make it slightly more elegant, I would suggest
Update
If you rather would like the URL to open in the system's default browser, and not in a
TWebBrowser
on your form, replaceWebBrowser1.Navigate(Edit1.Text)
withafter you have added
ShellAPI
to your uses clause. But notice now that you have to be explicit with the protocol. For instance,bbc.co.uk
won't work, buthttp://bbc.co.uk
will.