FlowLayoutPanel in einer Linie

  • VB.NET

Es gibt 10 Antworten in diesem Thema. Der letzte Beitrag () ist von VBHunter.

    FlowLayoutPanel in einer Linie

    Hi,

    ich blick hier grad nicht durch... ich habe eine class.vb die meine die ein Bauprozess simuliert, wenn ein Button geklickt wird dann läuft ein Countdown ab und es wird ein Label erstellt was getan wird, eine PBar (mit Prozenten) und ein Label wie lange es noch dauert bis es fertig ist. Siehe bild.



    Wie man sehen kann sind diese Objekte untereinander .... Wie bekomme ich sie nebeneinander ?

    hier der Code:

    VB.NET-Quellcode

    1. Public _progressBar As Pbar
    2. Public _restTimeLabel As Label
    3. Public fp2 As New FlowLayoutPanel
    4. Public Sub New(timername As String, timetocompleteSeconds As Integer, flowPanel As FlowLayoutPanel)
    5. Timer = New Timer() With {.Interval = 1000, .Enabled = True}
    6. AddHandler Timer.Tick, AddressOf Timer_Tick
    7. RunsOutAt = DateAdd(DateInterval.Second, timetocompleteSeconds, Now)
    8. CreateCluster(timername, flowPanel)
    9. StartetAt = Now
    10. Timer.Start()
    11. End Sub
    12. Public Sub CreateCluster(timername As String, FlowPanel As FlowLayoutPanel)
    13. FlowPanel.FlowDirection = FlowDirection.LeftToRight
    14. fp2.Controls.Add(New Label() With {.Text = timername, .Width = 200, .Height = 20})
    15. _progressBar = New Pbar
    16. With _progressBar
    17. .Width = 100 : .Height = 10
    18. End With
    19. fp2.Controls.Add(_progressBar)
    20. _restTimeLabel = New Label() With {.Text = New TimeSpan(0, 0, CInt(DateDiff(DateInterval.Second, Now, RunsOutAt))).Duration.ToString}
    21. fp2.Controls.Add(_restTimeLabel)
    22. FlowPanel.Controls.Add(fp2)
    23. End Sub
    24. Public Property Timer As Timer
    25. Public Property StartetAt As DateTime
    26. Public Property RunsOutAt As DateTime
    27. Public Sub Timer_Tick(sender As Object, e As EventArgs)
    28. Dim completTimeSpan As Integer = CInt(DateDiff(DateInterval.Second, StartetAt, RunsOutAt))
    29. Dim resttime As Integer = CInt(DateDiff(DateInterval.Second, Now, RunsOutAt))
    30. Dim percentValue As Double = ((completTimeSpan - resttime) * 100) / completTimeSpan
    31. If percentValue >= 100 Then
    32. _progressBar.Value = 100
    33. fp2.Visible = False
    34. _progressBar.Visible = False
    35. _restTimeLabel.Visible = False
    36. _progressBar.SendToBack()
    37. Timer.Stop()
    38. RaiseEvent Loadcompleted()
    39. Else
    40. _progressBar.Value = percentValue
    41. _restTimeLabel.Text = "Restzeit " & New TimeSpan(0, 0, CType(DateDiff(DateInterval.Second, Now, RunsOutAt), Integer)).Duration.ToString
    42. End If
    43. End Sub
    44. Public Event Loadcompleted()


    ich hatte es kurzzeitig hinbekommen das sie nebeneinander sind.

    Hier das Bild:



    Aber wenn der Countdown abgelaufen ist wird nur die PBar und die Restzeit entfernt ... das erste Infolabel bleibt stehen

    siehe Hier:



    Ich hoffe mir kann einer weiterhelfen ...

    hier der code dazu :

    VB.NET-Quellcode

    1. Public _progressBar As Pbar
    2. Public _restTimeLabel As Label
    3. Public fp2 As New FlowLayoutPanel
    4. Public Sub New(timername As String, timetocompleteSeconds As Integer, flowPanel As FlowLayoutPanel)
    5. Timer = New Timer() With {.Interval = 1000, .Enabled = True}
    6. AddHandler Timer.Tick, AddressOf Timer_Tick
    7. RunsOutAt = DateAdd(DateInterval.Second, timetocompleteSeconds, Now)
    8. CreateCluster(timername, flowPanel)
    9. StartetAt = Now
    10. Timer.Start()
    11. End Sub
    12. Public Sub CreateCluster(timername As String, fp2 As FlowLayoutPanel)
    13. fp2.FlowDirection = FlowDirection.LeftToRight
    14. fp2.Controls.Add(New Label() With {.Text = timername, .Width = 200, .Height = 20})
    15. _progressBar = New Pbar
    16. With _progressBar
    17. .Width = 100 : .Height = 10
    18. End With
    19. fp2.Controls.Add(_progressBar)
    20. _restTimeLabel = New Label() With {.Text = New TimeSpan(0, 0, CInt(DateDiff(DateInterval.Second, Now, RunsOutAt))).Duration.ToString}
    21. fp2.Controls.Add(_restTimeLabel)
    22. End Sub
    23. Public Property Timer As Timer
    24. Public Property StartetAt As DateTime
    25. Public Property RunsOutAt As DateTime
    26. Public Sub Timer_Tick(sender As Object, e As EventArgs)
    27. Dim completTimeSpan As Integer = CInt(DateDiff(DateInterval.Second, StartetAt, RunsOutAt))
    28. Dim resttime As Integer = CInt(DateDiff(DateInterval.Second, Now, RunsOutAt))
    29. Dim percentValue As Double = ((completTimeSpan - resttime) * 100) / completTimeSpan
    30. If percentValue >= 100 Then
    31. _progressBar.Value = 100
    32. fp2.Visible = False
    33. _progressBar.Visible = False
    34. _restTimeLabel.Visible = False
    35. _progressBar.SendToBack()
    36. Timer.Stop()
    37. RaiseEvent Loadcompleted()
    38. Else
    39. _progressBar.Value = percentValue
    40. _restTimeLabel.Text = "Restzeit " & New TimeSpan(0, 0, CType(DateDiff(DateInterval.Second, Now, RunsOutAt), Integer)).Duration.ToString
    41. End If
    42. End Sub
    43. Public Event Loadcompleted()
    @VBHunter Das TLP hat eine Property FlowDirection, die musst Du entsprechend setzen:
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    Zu Problem #2: Ich würde dir empfehlen ein UserControl zu erstellen, das beide Label und Progressbar enthält und sich nach erledigter arbeit selbständig aus dem FlowLayoutPanel löscht.
    Danke @RodFromGermany aber das habe ich schon gemacht im designer und im code

    VB.NET-Quellcode

    1. fp2.FlowDirection = FlowDirection.LeftToRight


    siehe oben

    ohne erfolg

    danke @FormFollowsFunction ein Usercontrol hab ich erstellt gehabt mit Label, PBar, Label aber bei mir funktionierte die Umetzung nicht ... weis nicht genau wie ich darauf zugreife.

    VB.NET-Quellcode

    1. Public Sub CreateCluster(timername As String, fp2 As UserControl1)
    2. fp2.FlowDirection = FlowDirection.LeftToRight
    3. fp2.Controls.Add(New Label() With {.Text = timername, .Width = 200, .Height = 20})
    4. _progressBar = New Pbar
    5. With _progressBar
    6. .Width = 100 : .Height = 10
    7. End With
    8. fp2.Controls.Add(_progressBar)
    9. _restTimeLabel = New Label() With {.Text = New TimeSpan(0, 0, CInt(DateDiff(DateInterval.Second, Now, RunsOutAt))).Duration.ToString}
    10. fp2.Controls.Add(_restTimeLabel)
    11. End Sub


    und beim Timer ... wenn er dann 100 % hat

    fp2.controls.Remove?

    VBHunter schrieb:

    ohne erfolg
    Bei mir schon:

    VB.NET-Quellcode

    1. Public Class Form1
    2. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    3. Me.FlowLayoutPanel1.FlowDirection = FlowDirection.LeftToRight
    4. End Sub
    5. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    6. Me.FlowLayoutPanel1.FlowDirection = FlowDirection.TopDown
    7. End Sub
    8. End Class
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    Ich würde den Timer auch ins UserControl packen, überhaupt alles was damit zu tun hat.
    Dann, wenn der Timer abgelaufen ist, mit Parent.Controls.Remove(Me) das Control entfernen.
    @FormFollowsFunction jetzt hab ich es so in mein UserControl leider spuckt er fehler aus...

    VB.NET-Quellcode

    1. Public _progressBar As Pbar
    2. Public _restTimeLabel As Label
    3. Public fp2 As New FlowLayoutPanel
    4. Public Sub New(timername As String, timetocompleteSeconds As Integer, flowPanel As FlowLayoutPanel)
    5. Timer = New Timer() With {.Interval = 1000, .Enabled = True}
    6. AddHandler Timer.Tick, AddressOf Timer_Tick
    7. RunsOutAt = DateAdd(DateInterval.Second, timetocompleteSeconds, Now)
    8. CreateCluster(timername, flowPanel)
    9. StartetAt = Now
    10. Timer.Start()
    11. End Sub
    12. Public Sub CreateCluster(timername As String, flowPanel As FlowLayoutPanel)
    13. Label1.Text = timername
    14. _progressBar = New Pbar
    15. With _progressBar
    16. .Width = 100 : .Height = 10
    17. End With
    18. Label2.Text = New TimeSpan(0, 0, CInt(DateDiff(DateInterval.Second, Now, RunsOutAt))).Duration.ToString
    19. End Sub
    20. Public Property Timer As Timer
    21. Public Property StartetAt As DateTime
    22. Public Property RunsOutAt As DateTime
    23. Public Sub Timer_Tick(sender As Object, e As EventArgs)
    24. Dim completTimeSpan As Integer = CInt(DateDiff(DateInterval.Second, StartetAt, RunsOutAt))
    25. Dim resttime As Integer = CInt(DateDiff(DateInterval.Second, Now, RunsOutAt))
    26. Dim percentValue As Double = ((completTimeSpan - resttime) * 100) / completTimeSpan
    27. If percentValue >= 100 Then
    28. _progressBar.Value = 100
    29. Me.Parent.Controls.Remove(Me)
    30. _progressBar.SendToBack()
    31. Timer.Stop()
    32. RaiseEvent Loadcompleted()
    33. Else
    34. _progressBar.Value = percentValue
    35. _restTimeLabel.Text = "Restzeit " & New TimeSpan(0, 0, CType(DateDiff(DateInterval.Second, Now, RunsOutAt), Integer)).Duration.ToString
    36. End If
    37. End Sub
    38. Public Event Loadcompleted()

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „VBHunter“ ()

    VBHunter schrieb:

    schpuckt er fehler aus...
    :thumbsup: :thumbsup: :thumbsup:
    Welche Fehler spuckt er denn wo aus?
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    Zugriff auf Controls lieber im Load oder nach InitializeComponents() (was bei dir fehlt). In deiner New Sub sind die Controls noch nicht erstellt worden. Das passiert erst nach dem aufruf von InitializeComponents()
    "Gib einem Mann einen Fisch und du ernährst ihn für einen Tag. Lehre einen Mann zu fischen und du ernährst ihn für sein Leben."

    Wie debugge ich richtig? => Debuggen, Fehler finden und beseitigen
    Wie man VisualStudio nutzt? => VisualStudio richtig nutzen
    okay momentan hab ich es noch in der Deklaration

    Private Const Obstausbau = 9 in 10 sek. ist der bau abgeschlossen

    EDIT: Fehler gefunden .... Lösung

    statt: fp2.Controls.Add(New Label() With {.Text = timername, .Width = 200, .Height = 20})

    hab ich jetzt eine zweites New Label angelegt z.b. so

    VB.NET-Quellcode

    1. _restTimeLabel2 = New Label() With {.Text = timername, .Width = 200, .Height = 20}
    2. fp2.Controls.Add(_restTimeLabel2)


    und dann unten im Timer _restTimeLabel2.Visible = False

    schon klappt das in der class.vb ohne Usercontrol


    VIELEN DANK

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „VBHunter“ ()