| ■No85002 (a さん) に返信 > VBでOpenFileDialog1から同じファイルを入れないようにするにはどうすればできますか?
Private history As New HashSet(Of String)() Private Sub OpenFileDialog1_FileOk(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk Dim files = OpenFileDialog1.FileNames Dim conflict = files.Where(AddressOf history.Contains)
If conflict.Any() Then e.Cancel = True Dim fileNames = conflict.Select(AddressOf System.IO.Path.GetFileName) MessageBox.Show("以前と同じファイルは選択できません。" & vbCrLf & String.Join(vbCrLf, fileNames), "競合", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Else Array.ForEach(files, AddressOf history.Add) End If End Sub |