Hallo,
ich habe hier ein funktionierendes Programm, es sieht mir jedoch ein wenig unntötig kompliziert aus und ich würde mich freuen, wenn ihr mal drüberschaut.
Zur Abfolge:
Es gibt Globale Variablen:
Es kann jetzt vorkommen, dass zum Beispiel Bildpfad[0] Nothing ist, Bildpfad[1] nicht, Bildpfad[2] wieder Nothing, usw. Daher werden alle Pfade, die nicht Nothing sind, ins Array Bildpfad2 kopiert. Dieses enthält demnach gegebenenfalls weniger Pfade. Form2 und 3 dienen zum Ausselektieren. Das ist das Ziel meines Codes. Noch eine Anmerkung: Der Benutzer kann bis zu 12 Bilder auswählen, muss er aber nicht. Aber weil meistens Bilder aussortiert werden müssen, gibt es vorsorglich 12 Pictureboxen – letzten Endes bleiben 5 Pfade übrig. Oder 6. You get the idea.
============================
Form1.vb
Form2
Form3
ich habe hier ein funktionierendes Programm, es sieht mir jedoch ein wenig unntötig kompliziert aus und ich würde mich freuen, wenn ihr mal drüberschaut.
Zur Abfolge:
Es gibt Globale Variablen:
- Bildpfad als String-Array mit 12 Pfaden
- Bildpfad2 als String-Array mit 12 Pfaden
- Arrays leeren, falls vom vorigen Mal etwas drinsteht
- Using: Form2 laden als modalen Dialog
- CommonOpenFileDialog mit Multiselect
- Pfade werden auf Form1.Bildpfad gespeichert
- Bilder werden in den Pictureboxen angezeigt
- schließen
- Using: Form3 laden als modalen Dialog
- in die Textboxen die Pfade schreiben
- .Show
- Benutzer klickt auf die Checkboxen, deren Pfade er nicht haben will
- schließen
Es kann jetzt vorkommen, dass zum Beispiel Bildpfad[0] Nothing ist, Bildpfad[1] nicht, Bildpfad[2] wieder Nothing, usw. Daher werden alle Pfade, die nicht Nothing sind, ins Array Bildpfad2 kopiert. Dieses enthält demnach gegebenenfalls weniger Pfade. Form2 und 3 dienen zum Ausselektieren. Das ist das Ziel meines Codes. Noch eine Anmerkung: Der Benutzer kann bis zu 12 Bilder auswählen, muss er aber nicht. Aber weil meistens Bilder aussortiert werden müssen, gibt es vorsorglich 12 Pictureboxen – letzten Endes bleiben 5 Pfade übrig. Oder 6. You get the idea.
============================
Form1.vb
VB.NET-Quellcode
- Imports Microsoft.WindowsAPICodePack.Dialogs
- Public Class Form_main
- Public Bildpfad(11) As String
- Public Bildpfad2(11) As String
- Private Sub Button_Start_Click(sender As Object, e As EventArgs) Handles Button_Start.Click
- For i As Integer = 0 To Bildpfad2.Length - 1 Step 1
- Bildpfad(i) = ""
- Bildpfad2(i) = ""
- Next
- Using Form2 As New Form_Bilder_auswaehlen
- Dim DR As DialogResult = Form2.ShowDialog(Me)
- If DR <> DialogResult.OK Then 'Falls Form2 einfach wegge-x-t wurde, wird das hier abgefangen.
- Return
- End If
- End Using
- Using Form3 As New Form_entfernen
- Dim tb As TextBox() = {Form3.TextBox1, Form3.TextBox2, Form3.TextBox3, Form3.TextBox4, Form3.TextBox5, Form3.TextBox6, Form3.TextBox7, Form3.TextBox8, Form3.TextBox9, Form3.TextBox10, Form3.TextBox11, Form3.TextBox12}
- For i As Integer = 0 To Bildpfad.Count - 1 Step 1
- If Bildpfad(i) IsNot Nothing Then
- If String.IsNullOrEmpty(tb(i).Text) Then
- tb(i).Text = Bildpfad(i)
- End If
- End If
- Next
- Dim DR As DialogResult = Form3.ShowDialog(Me)
- If DR <> DialogResult.OK Then 'Falls Form3 einfach wegge-x-t wurde, wird das hier abgefangen.
- Return
- End If
- Dim cb As CheckBox() = {Form3.CheckBox1, Form3.CheckBox2, Form3.CheckBox3, Form3.CheckBox4, Form3.CheckBox5, Form3.CheckBox6, Form3.CheckBox7, Form3.CheckBox8, Form3.CheckBox9, Form3.CheckBox10, Form3.CheckBox11, Form3.CheckBox12}
- For i As Integer = 0 To 11 Step 1
- If Not cb(i).Checked Then
- Bildpfad2(i) = Bildpfad(i)
- End If
- Next
- End Using
- End Sub
- End Class
Form2
VB.NET-Quellcode
- Imports Microsoft.WindowsAPICodePack.Dialogs
- Public Class Form_Bilder_auswaehlen
- Private Sub Button_bestaetige_Click(sender As Object, e As EventArgs) Handles Button_bestaetige.Click
- If String.IsNullOrEmpty(TextBox13.Text) Then 'Testbox13 ist die erste, also oben links. Man soll nicht bestätigen können, wenn gar nichts vorhanden ist.
- Return
- End If
- schliessen()
- End Sub
- Private Sub schliessen()
- Me.Close()
- End Sub
- Private Sub Button_auswaehlen_Click(sender As Object, e As EventArgs) Handles Button_auswaehlen.Click
- Dim Zaehler As Integer = 0
- Dim Pfade() As String = {"", "", "", "", "", "", "", "", "", "", "", ""}
- Using OFD As New CommonOpenFileDialog
- OFD.Title = "Bilder zauswählen"
- OFD.Filters.Add(New CommonFileDialogFilter("JPEG", ".jpg"))
- OFD.Filters.Add(New CommonFileDialogFilter("Bitmap", ".bmp"))
- OFD.Filters.Add(New CommonFileDialogFilter("PNG", ".png"))
- OFD.Multiselect = True
- OFD.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
- OFD.IsFolderPicker = False
- OFD.RestoreDirectory = True
- If OFD.ShowDialog() = CommonFileDialogResult.Ok Then
- For i As Integer = 0 To OFD.FileNames.Count - 1 Step 1
- Form_main.Bildpfad(i) = OFD.FileNames(i)
- Pfade(i) = OFD.FileNames(i)
- Zaehler += 1
- Next
- Else
- Return
- End If
- End Using
- Dim pb As PictureBox() = {PictureBox1, PictureBox2, PictureBox3, PictureBox4, PictureBox5, PictureBox6, PictureBox7, PictureBox8, PictureBox9, PictureBox10, PictureBox11, PictureBox12}
- Dim tb As TextBox() = {TextBox13, TextBox14, TextBox15, TextBox16, TextBox17, TextBox18, TextBox19, TextBox20, TextBox21, TextBox22, TextBox23, TextBox24}
- For i As Integer = 0 To Zaehler - 1
- If Pfade(i) IsNot Nothing Then
- Using My_Bitmap As New Bitmap(Pfade(i))
- pb(i).Image = My_Bitmap
- tb(i).Text = Pfade(i)
- End Using
- End If
- Next
- End Sub
- Private Sub Form_Bilder_auswaehlen_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
- If PictureBox1.Image IsNot Nothing Then
- PictureBox1.Image.Dispose()
- End If
- If PictureBox2.Image IsNot Nothing Then
- PictureBox2.Image.Dispose()
- End If
- If PictureBox3.Image IsNot Nothing Then
- PictureBox3.Image.Dispose()
- End If
- If PictureBox4.Image IsNot Nothing Then
- PictureBox4.Image.Dispose()
- End If
- If PictureBox5.Image IsNot Nothing Then
- PictureBox5.Image.Dispose()
- End If
- If PictureBox6.Image IsNot Nothing Then
- PictureBox6.Image.Dispose()
- End If
- If PictureBox7.Image IsNot Nothing Then
- PictureBox7.Image.Dispose()
- End If
- If PictureBox8.Image IsNot Nothing Then
- PictureBox8.Image.Dispose()
- End If
- If PictureBox9.Image IsNot Nothing Then
- PictureBox9.Image.Dispose()
- End If
- If PictureBox10.Image IsNot Nothing Then
- PictureBox10.Image.Dispose()
- End If
- If PictureBox11.Image IsNot Nothing Then
- PictureBox11.Image.Dispose()
- End If
- If PictureBox12.Image IsNot Nothing Then
- PictureBox12.Image.Dispose()
- End If
- End Sub
- End Class
Form3
VB.NET-Quellcode
- Public Class Form_entfernen
- Private Sub Button_OK_Click(sender As Object, e As EventArgs) Handles Button_OK.Click
- schliessen()
- End Sub
- Private Sub Form3_KeyDown(sender As Object, e As KeyEventArgs) Handles MyBase.KeyDown
- If e.KeyCode = Keys.Enter Then
- schliessen()
- End If
- End Sub
- Private Sub schliessen()
- Me.Close()
- End Sub
- End Class