大家帮我看看里面的代码,问题出在哪???
如何双击*.test文件用我的程序打开他,直接运行程序时不打开文件
为什么双击*.test文件时可以正常打开程序
可是为什么不能直接运行程序
Imports Microsoft.Win32
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows 窗体设计器生成的代码 "
Shared strFile As String
<STAThread()> Shared Sub Main(ByVal CmdArgs() As String)
If CmdArgs.Length = 0 Then
Dim FileExt As String
Dim FileType As String
Dim MIMEType As String
Dim ExecName As String
FileExt = ".test"
FileType = "Test File"
MIMEType = "text/plain"
ExecName = Application.ExecutablePath + " %1"
Dim RegKey As RegistryKey
RegKey = Registry.ClassesRoot
RegKey = RegKey.CreateSubKey(FileExt)
RegKey.SetValue("", FileType)
RegKey.SetValue("Content Type", MIMEType)
RegKey = RegKey.CreateSubKey("shell\open\command")
RegKey.SetValue("", ExecName)
RegKey.Close()
Return
End If
strFile = CmdArgs(0)
System.Windows.Forms.Application.Run(New Form1())
End Sub
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
Me.richTextBox1.Dock = DockStyle.Fill
Me.richTextBox1.LoadFile(strFile, RichTextBoxStreamType.PlainText)
End Sub
'窗体重写处置以清理组件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意:以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents richTextBox1 As System.Windows.Forms.RichTextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.richTextBox1 = New System.Windows.Forms.RichTextBox()
Me.SuspendLayout()
'
'richTextBox1
'
Me.richTextBox1.Location = New System.Drawing.Point(40, 40)
Me.richTextBox1.Name = "richTextBox1"
Me.richTextBox1.TabIndex = 1
Me.richTextBox1.Text = "richTextBox1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(232, 181)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.richTextBox1})
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
End Class