Imports System.IO Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ChargeLstMachine() End Sub Private Sub ChargeLstMachine() If My.Computer.FileSystem.FileExists(My.Application.Info.DirectoryPath & "\Utile\Produit-Machine.txt") Then lstMachine.Items.Clear() Try Using sr As StreamReader = New StreamReader(My.Application.Info.DirectoryPath & "\Utile\Produit-Machine.txt") Dim line As String Do line = sr.ReadLine() lstMachine.Items.Add(line) Loop Until line Is Nothing sr.Close() End Using Catch ex As Exception Console.WriteLine(ex.Message) End Try End If End Sub Private Sub lstMachine_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstMachine.SelectedIndexChanged Dim sNomMachine As String sNomMachine = lstMachine.SelectedItem.ToString() If My.Computer.FileSystem.FileExists(My.Application.Info.DirectoryPath & "\Utile\Descriptif" & sNomMachine & ".rtf") Then RichTextBox1.Clear() RichTextBox1.LoadFile(My.Application.Info.DirectoryPath & "\Utile\Descriptif" & sNomMachine & ".rtf") End If If My.Computer.FileSystem.FileExists(My.Application.Info.DirectoryPath & "\Utile\Images" & sNomMachine & ".jpeg") Then Dim photoStream As FileStream = New FileStream(My.Application.Info.DirectoryPath & "\Utile\Images" & sNomMachine & ".jpeg", FileMode.Open) PictureBox1.Image = Image.FromStream(photoStream) photoStream.Close() Me.Refresh() ElseIf My.Computer.FileSystem.FileExists(My.Application.Info.DirectoryPath & "\Utile\Images" & sNomMachine & ".jpg") Then Dim photoStream As FileStream = New FileStream(My.Application.Info.DirectoryPath & "\Utile\Images" & sNomMachine & ".jpg", FileMode.Open) PictureBox1.Image = Image.FromStream(photoStream) photoStream.Close() Me.Refresh() ElseIf My.Computer.FileSystem.FileExists(My.Application.Info.DirectoryPath & "\Utile\Images" & sNomMachine & ".bmp") Then Dim photoStream As FileStream = New FileStream(My.Application.Info.DirectoryPath & "\Utile\Images" & sNomMachine & ".bmp", FileMode.Open) PictureBox1.Image = Image.FromStream(photoStream) photoStream.Close() Me.Refresh() End If End Sub End Class
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question