Form wird durch Application.OpenForms nicht erkannt

  • VB.NET
  • .NET (FX) 4.5–4.8

Es gibt 11 Antworten in diesem Thema. Der letzte Beitrag () ist von woeh.

    Form wird durch Application.OpenForms nicht erkannt

    hallo :)

    ich öffne eine form

    VB.NET-Quellcode

    1. Dim frmPro As New frmProgress
    2. frmPro.Show()


    dass problem ist, das diese form nicht von Application.OpenForms verarbeitet wird.

    ich habe 3 offene formen...Application.OpenForms.Count gibt mir nur 2 zurück.

    woran kann das liegen ?
    Das Problem ist, dass Du Application.OpenForms gar nicht brauchst. Du hast doch eine Referenz für jede Form. Beschreibe mal, was Du vor hast, dann finden wir eine Lösung.
    Die Unendlichkeit ist weit. Vor allem gegen Ende. ?(
    Manche Menschen sind gar nicht dumm. Sie haben nur Pech beim Denken. 8o
    Wird bei Application.OpenForms.Count die Main Form auch gezählt?
    "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
    ja....die mainform wird gefunden.

    das ist die funktion die es prüft:

    VB.NET-Quellcode

    1. Private Sub NotifyIcon_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles NotifyIcon.MouseDoubleClick
    2. Dim visible As Boolean
    3. visible = Not (Me.Visible)
    4. For Each frm As Form In Application.OpenForms
    5. frm.Visible = visible
    6. If frm.Visible = True Then
    7. frm.TopMost = True
    8. frm.TopMost = False
    9. End If
    10. Application.DoEvents()
    11. Next
    12. If Me.Enabled = True And Me.Visible = True Then
    13. Me.Activate()
    14. End If
    15. End Sub


    frmPro wird dabei nicht gefunden....warum weiß ich auch nicht

    ich habe gerade mal folgendes probiert:

    VB.NET-Quellcode

    1. Public Function FormIsLoaded(ByVal sName As String) As Boolean
    2. Dim bResult As Boolean = False
    3. ' alle geöffneten Forms durchlauden
    4. For Each oForm As Form In Application.OpenForms
    5. If oForm.Name.ToLower = sName.ToLower Then
    6. bResult = True : Exit For
    7. End If
    8. Next
    9. Return (bResult)
    10. End Function


    habe ich direkt in die form eingegeben und rufe die funktion auf

    VB.NET-Quellcode

    1. MsgBox(FormIsLoaded(Me.Name))


    ich bekomme False zurück ???

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

    es funktioniert ja sonst....nur mit frmProgress habe ich probleme.

    vorhin war die form 1x kurz aufgetaucht...dann nicht mehr...
    ich habe versucht es zu reproduzieren...sie ist nicht mehr aufgetaucht.

    ich habe mir jetzt mit ner hilfsreferenz geholfen.

    werde nachher mal versuchen die form umzubenennen.
    vielleicht hilft das ja
    nein....ich habe formen, die im eigenem thread laufen...mit denen gehts.
    frmProgress ist nur ne form, die den fortschritt für verschiedene dinge zuständig ist.
    es gibt nur einen sub.

    VB.NET-Quellcode

    1. Public Sub SetInfo(ByVal Title As String,
    2. ByVal Message As String,
    3. ByVal Min As Integer,
    4. ByVal Max As Integer,
    5. ByVal Value As Integer,
    6. Optional lblInfoText As String = "",
    7. Optional pathCompact As Boolean = True,
    8. Optional showPercentInTitle As Boolean = True,
    9. Optional showFileCount As Boolean = False)
    10. Static oldTitle As String
    11. Static oldMessage As String
    12. Static oldLblText As String
    13. If showPercentInTitle = True Then
    14. Title = Title & " (" & CInt((100 / Max * Value)).ToString & "%)"
    15. End If
    16. If Title <> oldTitle Then
    17. oldTitle = Title
    18. Me.Text = Title
    19. End If
    20. If Message <> oldMessage Then
    21. oldMessage = Message
    22. If pathCompact = False Then
    23. gb.Text = Message
    24. Else
    25. gb.Text = clsClass.CompactPath(gb, Message)
    26. End If
    27. If pbar.Minimum <> Min Then
    28. pbar.Minimum = Min
    29. End If
    30. End If
    31. If pbar.Maximum <> Max Then
    32. pbar.Maximum = Max
    33. End If
    34. If showFileCount = True Then
    35. If lblInfoText.Length = 0 Then
    36. lblInfoText = "Datei"
    37. End If
    38. lblInfoText = lblInfoText & " " & Value.ToString & " von " & pbar.Maximum.ToString
    39. End If
    40. If lblInfoText <> "" Then
    41. If oldLblText <> lblInfoText Then
    42. oldLblText = lblInfoText
    43. lblInfo.Text = lblInfoText
    44. End If
    45. End If
    46. pbar.Value = Value
    47. Application.DoEvents()
    48. End Sub
    @woeh Möglicherweise liegt es am anderen Thread, ich hab da kein Beispiel rumliegen.
    Schreib mal ein kurzes Programm / Projekt, das Dein Problem reproduziert und häng es hier dran.
    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!

    Stack Overflow schrieb:

    There's a bug in Windows Forms that makes a form disappear from the
    Application.OpenForms collection. This will happen when you assign the
    ShowInTaskbar, FormBorderStyle, ControlBox, Min/MaximizedBox,
    RightToLeftLayout, HelpButton, Opacity, TransparencyKey, ShowIcon or
    MdiParent property after the window was created. These
    properties are special in that they are specified as style flags in the
    native CreateWindowEx() call.


    stackoverflow.com/questions/37…-0-always/3751748#3751748