アットウィキロゴ
Public Class Form1

    Private Sub TextBox1_TextChanged(sender As System.Object, e As System.EventArgs)

    End Sub

    Private Sub btnFile1_Click(sender As System.Object, e As System.EventArgs) Handles btnFile1.Click
        Me.SelectFile(btnFile1, txtFile1)
    End Sub

    Private Sub btnFile2_Click(sender As System.Object, e As System.EventArgs) Handles btnFile2.Click
        Me.SelectFile(btnFile2, txtFile2)
    End Sub

    Private Sub SelectFile(button As Button, txt As TextBox)

        'OpenFileDialogクラスのインスタンスを作成
        Dim ofd As New OpenFileDialog()

        'ダイアログを表示する
        If ofd.ShowDialog() = DialogResult.OK Then
            'OKボタンがクリックされたとき
            '選択されたファイル名をすべて表示する
            Dim file As String = ofd.FileNames(0)
            txt.Text = file
        End If
    End Sub


    Private Sub txtFile_DragEnter(sender As Object, e As System.Windows.Forms.DragEventArgs) _
        Handles txtFile1.DragEnter, txtFile2.DragEnter


        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            e.Effect = DragDropEffects.Copy
        End If

    End Sub

    Private Sub txtFile_DragDrop(sender As Object, e As System.Windows.Forms.DragEventArgs) _
        Handles txtFile1.DragDrop, txtFile2.DragDrop

        Dim txt As TextBox = DirectCast(sender, TextBox)

        Dim fileNameList As String() = CType(e.Data.GetData(DataFormats.FileDrop, False), String())
        Dim fileName As String = fileNameList(0)

        txt.Text = fileName

    End Sub

    Private Sub btnExecute_Click(sender As System.Object, e As System.EventArgs) Handles btnExecute.Click
        If String.IsNullOrEmpty(txtFile1.Text) _
            OrElse String.IsNullOrEmpty(txtFile2.Text) Then

            MsgBox("ファイル名を指定してください")
            Return
        End If

        Dim args As New ExecuteArgs(txtFile1.Text, txtFile2.Text)
        If chkIgnoreCase.Checked Then
            args.IgnoreCase = True
        End If
        If chkIgnoreEOL.Checked Then
            args.IgnoreEol = True
        End If
        If chkIgnoreSpace.Checked Then
            args.IgnoreSpace = True
        End If

        Me.Execute(args)

    End Sub

    Private Sub Execute(args As ExecuteArgs)

        'ProcessStartInfoオブジェクトを作成する
        Dim psi As New System.Diagnostics.ProcessStartInfo()
        psi.CreateNoWindow = True
        psi.UseShellExecute = False

        '起動する実行ファイルのパスを設定する
        psi.FileName = SetQuotation("C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\diffmerge.exe")

        Dim strOpitonList As New List(Of String)
        strOpitonList.Add(SetQuotation(args.File1))
        strOpitonList.Add(SetQuotation(args.File2))

        If args.IgnoreCase Then
            strOpitonList.Add(SetQuotation("/ignorecase"))
        End If
        If args.IgnoreEol Then
            strOpitonList.Add(SetQuotation("/ignoreeol"))
        End If
        If args.IgnoreSpace Then
            strOpitonList.Add(SetQuotation("/ignorespace"))
        End If

        psi.Arguments = String.Join(" ", strOpitonList.ToArray)

        '起動する
        Dim p As System.Diagnostics.Process = _
            System.Diagnostics.Process.Start(psi)

    End Sub

    Private Function SetQuotation(str As String) As String
        Return """" & str & """"
    End Function

    Private Class ExecuteArgs
        Public File1 As String
        Public File2 As String
        Public IgnoreSpace As Boolean = False
        Public IgnoreEol As Boolean = False
        Public IgnoreCase As Boolean = False

        Public Sub New(f1 As String, f2 As String)
            File1 = f1
            File2 = f2
        End Sub
    End Class

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Me.Close()
    End Sub
End Class


<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
    Inherits System.Windows.Forms.Form

    'フォームがコンポーネントの一覧をクリーンアップするために dispose をオーバーライドします。
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    'Windows フォーム デザイナーで必要です。
    Private components As System.ComponentModel.IContainer

    'メモ: 以下のプロシージャは Windows フォーム デザイナーで必要です。
    'Windows フォーム デザイナーを使用して変更できます。  
    'コード エディターを使って変更しないでください。
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.btnFile1 = New System.Windows.Forms.Button()
        Me.txtFile1 = New System.Windows.Forms.TextBox()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.txtFile2 = New System.Windows.Forms.TextBox()
        Me.btnExecute = New System.Windows.Forms.Button()
        Me.btnFile2 = New System.Windows.Forms.Button()
        Me.chkIgnoreEOL = New System.Windows.Forms.CheckBox()
        Me.chkIgnoreSpace = New System.Windows.Forms.CheckBox()
        Me.chkIgnoreCase = New System.Windows.Forms.CheckBox()
        Me.Button1 = New System.Windows.Forms.Button()
        Me.SuspendLayout()
        '
        'btnFile1
        '
        Me.btnFile1.Location = New System.Drawing.Point(352, 14)
        Me.btnFile1.Name = "btnFile1"
        Me.btnFile1.Size = New System.Drawing.Size(86, 23)
        Me.btnFile1.TabIndex = 0
        Me.btnFile1.Text = "参照(&1)"
        Me.btnFile1.UseVisualStyleBackColor = True
        '
        'txtFile1
        '
        Me.txtFile1.AllowDrop = True
        Me.txtFile1.Location = New System.Drawing.Point(72, 16)
        Me.txtFile1.Name = "txtFile1"
        Me.txtFile1.Size = New System.Drawing.Size(274, 19)
        Me.txtFile1.TabIndex = 4
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.Location = New System.Drawing.Point(15, 19)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(45, 12)
        Me.Label2.TabIndex = 6
        Me.Label2.Text = "ファイル1"
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.Location = New System.Drawing.Point(15, 44)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(45, 12)
        Me.Label1.TabIndex = 9
        Me.Label1.Text = "ファイル2"
        '
        'txtFile2
        '
        Me.txtFile2.AllowDrop = True
        Me.txtFile2.Location = New System.Drawing.Point(72, 41)
        Me.txtFile2.Name = "txtFile2"
        Me.txtFile2.Size = New System.Drawing.Size(274, 19)
        Me.txtFile2.TabIndex = 8
        '
        'btnExecute
        '
        Me.btnExecute.Location = New System.Drawing.Point(353, 96)
        Me.btnExecute.Name = "btnExecute"
        Me.btnExecute.Size = New System.Drawing.Size(86, 23)
        Me.btnExecute.TabIndex = 10
        Me.btnExecute.Text = "実行(&E)"
        Me.btnExecute.UseVisualStyleBackColor = True
        '
        'btnFile2
        '
        Me.btnFile2.Location = New System.Drawing.Point(352, 39)
        Me.btnFile2.Name = "btnFile2"
        Me.btnFile2.Size = New System.Drawing.Size(86, 23)
        Me.btnFile2.TabIndex = 11
        Me.btnFile2.Text = "参照(&2)"
        Me.btnFile2.UseVisualStyleBackColor = True
        '
        'chkIgnoreEOL
        '
        Me.chkIgnoreEOL.AutoSize = True
        Me.chkIgnoreEOL.Checked = True
        Me.chkIgnoreEOL.CheckState = System.Windows.Forms.CheckState.Checked
        Me.chkIgnoreEOL.Location = New System.Drawing.Point(72, 81)
        Me.chkIgnoreEOL.Name = "chkIgnoreEOL"
        Me.chkIgnoreEOL.Size = New System.Drawing.Size(139, 16)
        Me.chkIgnoreEOL.TabIndex = 12
        Me.chkIgnoreEOL.Text = "行末記号の相違を無視"
        Me.chkIgnoreEOL.UseVisualStyleBackColor = True
        '
        'chkIgnoreSpace
        '
        Me.chkIgnoreSpace.AutoSize = True
        Me.chkIgnoreSpace.Checked = True
        Me.chkIgnoreSpace.CheckState = System.Windows.Forms.CheckState.Checked
        Me.chkIgnoreSpace.Location = New System.Drawing.Point(72, 103)
        Me.chkIgnoreSpace.Name = "chkIgnoreSpace"
        Me.chkIgnoreSpace.Size = New System.Drawing.Size(153, 16)
        Me.chkIgnoreSpace.TabIndex = 13
        Me.chkIgnoreSpace.Text = "空白スペースの相違を無視"
        Me.chkIgnoreSpace.UseVisualStyleBackColor = True
        '
        'chkIgnoreCase
        '
        Me.chkIgnoreCase.AutoSize = True
        Me.chkIgnoreCase.Checked = True
        Me.chkIgnoreCase.CheckState = System.Windows.Forms.CheckState.Checked
        Me.chkIgnoreCase.Location = New System.Drawing.Point(72, 125)
        Me.chkIgnoreCase.Name = "chkIgnoreCase"
        Me.chkIgnoreCase.Size = New System.Drawing.Size(163, 16)
        Me.chkIgnoreCase.TabIndex = 14
        Me.chkIgnoreCase.Text = "大文字小文字の相違を無視"
        Me.chkIgnoreCase.UseVisualStyleBackColor = True
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(353, 121)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(86, 23)
        Me.Button1.TabIndex = 15
        Me.Button1.Text = "終了(&X)"
        Me.Button1.UseVisualStyleBackColor = True
        '
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(451, 157)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.chkIgnoreCase)
        Me.Controls.Add(Me.chkIgnoreSpace)
        Me.Controls.Add(Me.chkIgnoreEOL)
        Me.Controls.Add(Me.btnFile2)
        Me.Controls.Add(Me.btnExecute)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.txtFile2)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.txtFile1)
        Me.Controls.Add(Me.btnFile1)
        Me.Name = "Form1"
        Me.Text = "ファイル比較"
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub
    Friend WithEvents btnFile1 As System.Windows.Forms.Button
    Friend WithEvents txtFile1 As System.Windows.Forms.TextBox
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents txtFile2 As System.Windows.Forms.TextBox
    Friend WithEvents btnExecute As System.Windows.Forms.Button
    Friend WithEvents btnFile2 As System.Windows.Forms.Button
    Friend WithEvents chkIgnoreEOL As System.Windows.Forms.CheckBox
    Friend WithEvents chkIgnoreSpace As System.Windows.Forms.CheckBox
    Friend WithEvents chkIgnoreCase As System.Windows.Forms.CheckBox
    Friend WithEvents Button1 As System.Windows.Forms.Button

End Class
最終更新:2016年04月23日 10:22