Public Class Form1 Dim deleteFileList As New List(Of String) 'コンパイルしたファイルのリスト Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load '実行ファイルと同じフォルダのvbのソースファイルを取得してListBoxに追加 For Each file As String In IO.Directory.GetFiles(".", "*.vb", System.IO.SearchOption.TopDirectoryOnly) Me.ListBox1.Items.Add(file) Next End Sub Private Sub ListBox1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick 'ソースファイル読み込み Dim sourceFile As String = Me.ListBox1.SelectedItem Dim sourceCode As String Using sr As New System.IO.StreamReader(sourceFile) sourceCode = sr.ReadToEnd() sr.Close() End Using 'コンパイル Dim param As New System.CodeDom.Compiler.CompilerParameters() param.GenerateExecutable = True Dim rs As System.CodeDom.Compiler.CompilerResults rs = New Microsoft.VisualBasic.VBCodeProvider().CompileAssemblyFromSource(param, New String() {sourceCode}) '実行 System.Diagnostics.Process.Start(rs.PathToAssembly) '後始末用 deleteFileList.Add(rs.PathToAssembly) End Sub Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing 'コンパイルして出来た一時ファイルを削除 For Each file As String In deleteFileList System.IO.File.Delete(file) Next End Sub End Class