Form in den Vordergrund wenn schon geöffnet

  • VB.NET

Es gibt 4 Antworten in diesem Thema. Der letzte Beitrag () ist von ThePlexian.

    Form in den Vordergrund wenn schon geöffnet

    Hallo zusammen,

    Ich öffne mit Hilfe eines Buttons auf Form1 eine 2. Form (Form2)

    Nun wenn Form 2 schon geöffnet ist, jedoch minimiert oder sich im Hintergrund befindet. Soll diese in den Vordergrund gebracht werden.
    Dies über ich wie Folgt auf:

    VB.NET-Quellcode

    1. If (Not kontakte.IsDisposed) Then
    2. kontakte.Show()
    3. Else
    4. kontakte.WindowState = FormWindowState.Normal
    5. kontakte.BringToFront()
    6. kontakte.Focus()
    7. End If


    Nun Funktioniert zwar das die Form geöffnet wird (falls geschlossen), jedoch wenn sie geöffnet ist wird die Form nicht in den Vordergrund gebracht.

    Kann mir jemand Helfen
    Mach das If weg:

    VB.NET-Quellcode

    1. If (Not kontakte.IsDisposed) Then
    2. kontakte.Show()
    3. End If
    4. kontakte.WindowState = FormWindowState.Normal
    5. kontakte.BringToFront()
    6. kontakte.Focus()
    »There's no need to "teach" atheism. It's the natural result of education without indoctrination.« — Ricky Gervais

    ThePlexian schrieb:

    Mach das If weg
    What?
    @schnibli
    Dann wird im Nicht-If-Fall auf eine Dispose-te Form zugegriffen und es knallt mörderisch.
    So geht das:

    VB.NET-Quellcode

    1. If (kontakte.IsDisposed) Then
    2. kontakte = New KontakteForm()
    3. End If
    4. kontakte.Show()
    5. ' ...
    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!
    @RodFromGermany
    Ich hab mir nur blöd ausgedrückt, deswegen das Beispiel ;)

    EDIT: Dummheit tut weh. Tut mir leid,du hast natürlich recht :)

    EDIT2: Dann aber richtig: If Kontakte Is Nothing OrElse Kontakte.IsDisposed
    »There's no need to "teach" atheism. It's the natural result of education without indoctrination.« — Ricky Gervais

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