C# - 关联文件类型并在 WebBrowser 控件中打开它?

发布于 2024-08-10 20:53:29 字数 104 浏览 2 评论 0原文

我如何能够打开一个文件(比如说 .html 文件)并将其加载到我的 WinForm 应用程序上的 WebBrowser 控件中?我说的是右键单击该文件并选择使用我的应用程序打开它。有什么想法吗?

How would I be able to open a file (lets say an .html file) and load it into the WebBrowser control on my WinForm application? I'm talking about right clicking on the file and choosing to open it with my application. Any ideas?

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

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

发布评论

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

评论(3

随风而去 2024-08-17 20:53:29

您可以将其作为命令行参数传递。与您的应用程序相比,您应该分析命令行参数并将文件加载到 WebBrowser 中。

You can pass it as command line parameter. Than in your application you should analyze command line parameters and load file into WebBrowser.

夜光 2024-08-17 20:53:29

我从未在 Windows 中预先填充“打开方式”菜单,它总是由我手动添加新项目来填充。

如果你想创建一个完整的关联,这里有一些代码:(

Public Sub associate(EXT As String, FileType As String, _
   FileName As String)
On Error Resume Next
Dim b As Object
Set b = CreateObject("wscript.shell")
b.regwrite "HKCR\" & EXT & "\", FileType
b.regwrite "HKCR\" & FileType & "\", "MY file"
b.regwrite "HKCR\" & FileType & "\DefaultIcon\", FileName
b.regwrite "HKCR\" & FileType & "\shell\open\command\", _
   FileName & " %L"
b.regdelete "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & EXT & "\Application"
b.regwrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & EXT & "\Application", FileName
b.regdelete "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & EXT & "\OpenWithList\"
b.regwrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & EXT & "\OpenWithList\a", FileName

End Sub

对VB感到抱歉,它是从互联网)

I've never had the Open With menu prepopulated in Windows, its always been populated by me adding new items manually.

If you want to create a full association, here is some code:

Public Sub associate(EXT As String, FileType As String, _
   FileName As String)
On Error Resume Next
Dim b As Object
Set b = CreateObject("wscript.shell")
b.regwrite "HKCR\" & EXT & "\", FileType
b.regwrite "HKCR\" & FileType & "\", "MY file"
b.regwrite "HKCR\" & FileType & "\DefaultIcon\", FileName
b.regwrite "HKCR\" & FileType & "\shell\open\command\", _
   FileName & " %L"
b.regdelete "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & EXT & "\Application"
b.regwrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & EXT & "\Application", FileName
b.regdelete "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & EXT & "\OpenWithList\"
b.regwrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & EXT & "\OpenWithList\a", FileName

End Sub

(sorry about the VB, its stolen from teh interwebs)

失退 2024-08-17 20:53:29

我假设您想要做的是以编程方式创建文件关联 - 为此,您需要在注册表中创建适当的条目。

代码来完成此操作

有一篇文章介绍了如何通过 codeproject 此处的 您可以与安装程序创建关联。

I'm assuming what you want to do is create a file association programmatically - to do this you need to create the appropriate entries in the registry.

There is an article on how this might be done from code at codeproject here

Alternatively you can create associations with an installer.

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