Bei Mehreren Bildschirm ermitteln auf welchem Bildschirm die Form aktuell angezeigt wird.

  • VB.NET

Es gibt 9 Antworten in diesem Thema. Der letzte Beitrag () ist von Schamash.

    Bei Mehreren Bildschirm ermitteln auf welchem Bildschirm die Form aktuell angezeigt wird.

    Hallo zusammen,

    wie die Überschrift schon aussagt müsste ich ermitteln auf welchem Bildschirm meine Form momentan angezeigt wird.
    Bisher habe ich mit Screen.GetWorkingArea gearbeitet und wollte mal fragen ob es eine elegantere Möglichkeit gibt.

    Zum Beispeil eine Abfrage die direkt ausgibt ob Primary oder Secondary Screen?
    There is no CLOUD - just other people's computers

    Q: Why do JAVA developers wear glasses?
    A: Because they can't C#

    Daily prayer:
    "Dear Lord, grand me the strength not to kill any stupid people today and please grant me the ability to punch them in the face over standard TCP/IP."
    Danke.

    Erst mal habe ich das so gelöst:

    VB.NET-Quellcode

    1. If Screen.PrimaryScreen.WorkingArea.Contains(Me.Location) Then
    2. Dim x As Integer = CInt((Screen.PrimaryScreen.WorkingArea.Width - Me.Width) / 2)
    3. Dim y As Integer = CInt((Screen.PrimaryScreen.WorkingArea.Height - Me.Height) / 2)
    4. Me.Location = New Point(x, y)
    5. Else
    6. Dim x As Integer = CInt(Screen.PrimaryScreen.WorkingArea.Width + ((Screen.AllScreens(1).WorkingArea.Width - Me.Width) / 2))
    7. Dim y As Integer = CInt((Screen.AllScreens(1).WorkingArea.Height - Me.Height) / 2)
    8. Me.Location = New Point(x, y)
    9. End If


    Muss jetzt erst mal nur schnell Laufen.
    Wenn ich wieder etwas ruhe hab zum überarbeiten werde ich das "schön" machen.
    There is no CLOUD - just other people's computers

    Q: Why do JAVA developers wear glasses?
    A: Because they can't C#

    Daily prayer:
    "Dear Lord, grand me the strength not to kill any stupid people today and please grant me the ability to punch them in the face over standard TCP/IP."

    Schamash schrieb:

    Muss jetzt erst mal nur schnell Laufen.
    Wenn ich wieder etwas ruhe hab zum überarbeiten werde ich das "schön" machen.
    Falls du die Zeit je findest, kannst du dir mal überlegen, was du in einem wirklich komplexen Fall machst, wenn sich dein Fenster über mehrere Bildschirme unterschiedlicher Ausrichtung und Größe zieht.
    Bilder
    • Screens.png

      14,14 kB, 1.279×529, 252 mal angesehen
    --
    If Not Program.isWorking Then Code.Debug Else Code.DoNotTouch
    --
    Hier in der Firma gibt es genau 2 Fälle von Monitoren: 1 Monitor oder 2 Monitore.
    Die Einstellung ist immer Primärer Monitor links und Sekundärer Monitor rechts.
    There is no CLOUD - just other people's computers

    Q: Why do JAVA developers wear glasses?
    A: Because they can't C#

    Daily prayer:
    "Dear Lord, grand me the strength not to kill any stupid people today and please grant me the ability to punch them in the face over standard TCP/IP."
    1978 ist auch ungefähr das Jahr in dem die Technik hier eingerichtet wurde.

    Wie schon geschrieben:
    Es musste jetzt erst mal schnell funktionieren.
    Und:
    Wenn ich wieder etwas Luft habe werde ich das mal "schön" machen. Im zuge des "schönmachens" werde ich mir sicherlich auch CurrentScreen ansehen.
    There is no CLOUD - just other people's computers

    Q: Why do JAVA developers wear glasses?
    A: Because they can't C#

    Daily prayer:
    "Dear Lord, grand me the strength not to kill any stupid people today and please grant me the ability to punch them in the face over standard TCP/IP."

    picoflop schrieb:

    Was spricht gegen CurrentScreen = Screen.FromControl(dieForm)?


    Ich hab da noch mal etwas Zeit gefunden.

    VB.NET-Quellcode

    1. Dim rec_WA As System.Drawing.Rectangle = Screen.FromControl(Me).WorkingArea
    2. Me.Location = New Point(CInt(rec_WA.X + ((rec_WA.Width - Me.Width) / 2)), CInt(rec_WA.Y + ((rec_WA.Height - Me.Height) / 2)))
    There is no CLOUD - just other people's computers

    Q: Why do JAVA developers wear glasses?
    A: Because they can't C#

    Daily prayer:
    "Dear Lord, grand me the strength not to kill any stupid people today and please grant me the ability to punch them in the face over standard TCP/IP."