Moin Leute.
Ich wollte inmal fragen, ob ihr hier kurz bitte rüberschauen könntet und ob man bei der Suche (
Edit
Ich frage mich, ob die 3 For-Each-Schleifen wegkönnen.
Die Klassenstruktur soll erhalten bleiebn (ist in Wirklichkeit noch etwas mehr im letzten innersten If, was abgefragt wird).
Die Bitmaps müssen neu instanziiert werden, sonst wird auf die alten gezeigt.
Klasse Post
Spoiler anzeigen
Klasse Thread
Spoiler anzeigen
FormMain (auf's Wesentliche beschränkt)
Spoiler anzeigen
Ich wollte inmal fragen, ob ihr hier kurz bitte rüberschauen könntet und ob man bei der Suche (
TextBox_Search_KeyDown
) etwas verbessern kann, am liebsten mit Linq.Edit
Ich frage mich, ob die 3 For-Each-Schleifen wegkönnen.
Die Klassenstruktur soll erhalten bleiebn (ist in Wirklichkeit noch etwas mehr im letzten innersten If, was abgefragt wird).
Die Bitmaps müssen neu instanziiert werden, sonst wird auf die alten gezeigt.
Klasse Post
VB.NET-Quellcode
- Public NotInheritable Class Post
- Public Property Paths As List(Of String)
- Public Property Images As List(Of Drawing.Bitmap)
- Public Property AreImagesLoaded As Boolean()
- ''' <summary>
- ''' Überschrift
- ''' </summary>
- ''' <returns></returns>
- Public Property Caption As String
- Public Property CreationDate As Date
- Public Sub New(Caption As String, CreationDate As Date, Paths As List(Of String), Images As List(Of Drawing.Bitmap))
- Me.Caption = Caption
- Me.CreationDate = CreationDate
- Me.Paths = Paths
- Me.Images = Images
- End Sub
- End Class
Klasse Thread
VB.NET-Quellcode
- Public NotInheritable Class Thread
- ''' <summary>
- ''' Überschrift
- ''' </summary>
- ''' <returns></returns>
- Public Property Caption As String
- Public Property CreationDate As Date
- Public Property ListOfPosts As List(Of Post)
- Public Sub New(Caption As String, CreationDate As Date, ListOfPosts As List(Of Post))
- Me.Caption = Caption
- Me.CreationDate = CreationDate
- Me.ListOfPosts = ListOfPosts
- End Sub
- End Class
FormMain (auf's Wesentliche beschränkt)
VB.NET-Quellcode
- Public NotInheritable Class FormMain
- Private ReadOnly allThreads As New List(Of Thread)
- Private Sub Button_new_Thread_Click(sender As Object, e As EventArgs) Handles Button_new_Thread.Click
- allThreads.Clear()
- Dim Path1 As New List(Of String) From {"C:\Users\Name\Pictures\BlackBackground.png"}
- Dim Image1 As New List(Of Drawing.Bitmap)
- If System.IO.File.Exists("C:\Users\Name\Pictures\BlackBackground.png") Then
- Image1.Add(New Drawing.Bitmap("C:\Users\Name\Pictures\BlackBackground.png"))
- End If
- Dim Path2 As New List(Of String) From {"C:\Users\Name\Pictures\RedBackground.png"}
- Dim Image2 As New List(Of Drawing.Bitmap)
- If System.IO.File.Exists("C:\Users\Name\Pictures\RedBackground.png") Then
- Image2.Add(New Drawing.Bitmap("C:\Users\Name\Pictures\RedBackground.png"))
- End If
- Dim Path3 As New List(Of String) From {"C:\Users\Name\Pictures\LightBlueBackground.png"}
- Dim Image3 As New List(Of Drawing.Bitmap)
- If System.IO.File.Exists("C:\Users\Name\Pictures\LightBlueBackground.png") Then
- Image3.Add(New Drawing.Bitmap("C:\Users\Name\Pictures\LightBlueBackground.png"))
- End If
- Dim Post1 As New List(Of Post) From {
- New Post("Postüberschrift 1", Date.Now, Path1, Image1)
- }
- allThreads.Add(New Thread("Thread-Überschrift 2", Date.Now, Post1))
- Dim Post2 As New List(Of Post) From {
- New Post("Postüberschrift 2", Date.Now, Path2, Image2)
- }
- allThreads.Add(New Thread("Thread-Überschrift 2", Date.Now, Post2))
- Dim Post3 As New List(Of Post) From {
- New Post("Postüberschrift 3", Date.Now, Path3, Image3)
- }
- allThreads.Add(New Thread("Thread-Überschrift 3", Date.Now, Post3))
- End Sub
- Private Sub TextBox_Search_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox_Search.KeyDown
- If Not (e.KeyCode = Keys.Enter) Then Return
- If System.String.IsNullOrEmpty(TextBox_Search.Text) Then Return
- Dim foundPosts As New List(Of Post)
- For Each [Thread] As Thread In allThreads
- For Each [Post] As Post In Thread.ListOfPosts
- If Post.Caption.Contains(TextBox_Search.Text) Then
- Debug.WriteLine($"Found »{TextBox_Search.Text}«")
- Dim Images As New List(Of Drawing.Bitmap)
- For Each Path As String In Post.Paths
- If IO.File.Exists(Path) Then
- Images.Add(New Drawing.Bitmap(Path))
- End If
- Next
- foundPosts.Add(New Post(Post.Caption, Post.CreationDate, Post.Paths, Images))
- End If
- Next
- Next
- End Sub
- Private Sub TextBox_Search_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox_Search.KeyPress
- If e.KeyChar = Microsoft.VisualBasic.ControlChars.Cr Then
- e.Handled = True
- End If
- End Sub
- End Class
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Bartosz“ ()