WPF - Anwendung über zwei Monitore laufen lassen

  • C#
  • .NET (FX) 4.5–4.8

Es gibt 1 Antwort in diesem Thema. Der letzte Beitrag () ist von Facebamm.

    WPF - Anwendung über zwei Monitore laufen lassen

    Hallo :D


    ich bin gerade dabei meine Anwendung über zwei Monitore zu strecken :D

    Das ganze wollte ich via WINAIP machen:

    ShitCode
    Spoiler anzeigen

    C#-Quellcode

    1. private void SetupScreen() {
    2. if (Screen.AllScreens.Length > 1) {
    3. Screen[] screen = Screen.AllScreens;
    4. Screen second = screen.FirstOrDefault(x => !x.Primary);
    5. Point location = Screen.PrimaryScreen.Bounds.X < second.Bounds.X
    6. ? PointToScreen(Screen.PrimaryScreen.Bounds.Location.ConvertWinPoint())
    7. : PointToScreen(second.Bounds.Location.ConvertWinPoint());
    8. Utils.MoveWindow(this, location.X, 0, CustomWidth = second.Bounds.Width + Screen.PrimaryScreen.Bounds.Width, CustomHeight = second.Bounds.Height);
    9. }
    10. }
    11. ...
    12. public static void MoveWindow(this Window window,double left, double top, double width, double height) {
    13. int pxLeft = 0, pxTop = 0;
    14. if (left != 0 || top != 0)
    15. window.TransformToPixels(left, top,
    16. out pxLeft, out pxTop);
    17. int pxWidth, pxHeight;
    18. window.TransformToPixels(width, height, out pxWidth, out pxHeight);
    19. // Adding missing pixel
    20. //pxWidth +=14; Grash damit
    21. //pxHeight += 14; Grash damit
    22. var helper = new WindowInteropHelper(window);
    23. SetWindowPos(helper.Handle, new IntPtr(0x0), pxLeft, pxTop, pxWidth, pxHeight, 0x0040);
    24. }
    25. public static void TransformToPixels(this Visual visual, double unitX, double unitY, out int pixelX, out int pixelY) {
    26. Matrix matrix;
    27. var source = PresentationSource.FromVisual(visual);
    28. if (source != null) {
    29. matrix = source.CompositionTarget.TransformToDevice;
    30. } else {
    31. using (var src = new HwndSource(new HwndSourceParameters())) {
    32. matrix = src.CompositionTarget.TransformToDevice;
    33. }
    34. }
    35. pixelX = (int)(matrix.M11 * unitX);
    36. pixelY = (int)(matrix.M22 * unitY);
    37. }
    38. [DllImport("user32.dll", CharSet = CharSet.Auto)]
    39. [return: MarshalAs(UnmanagedType.Bool)]
    40. private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, int flag);



    problem bei dir ganzen sache ich nun, das wenn ich mir von MoveWindow-Methode das "window" anschaue habe ich ein AktuelleBreite von 1934 und eine AktuelleHöhe von 1094, was aus meiner sicht kein sinn macht, das mein Bildschrim 1920x1080 ist.

    Erste frage, wo kommen die 14 Pixel her in W und H?
    Zweite frage, Gibt es eine elegantere löschung von WPF heraus?
    Dritte ..., wobei es eher eine Antort ist- Code auf Stackoverflow hab ich schon gefunden und musst festellen, das irgendwie auch nicht geht Oo


    //Update:
    Mit dem hinzufügen und dem manuellen ausrichten, sitzt die anwendung, aber nur, wenn ich sie auf dem Hauptbildschrim starte.



    MfG

    Facebamm <3 :saint:

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

    Um das Problem zuu lösen müssen ein paar Gegebenheiten existierne

    Das Fenster darf muss auf ResizeMode="NoResize" und WindowState="Normal" sein

    und der quellcode ist das wie folgt
    Spoiler anzeigen

    C#-Quellcode

    1. private void SetupScreen() {
    2. if (Screen.AllScreens.Length > 1) {
    3. Screen[] screen = Screen.AllScreens;
    4. Screen second = screen.FirstOrDefault(x => !x.Primary);
    5. Point location = Screen.PrimaryScreen.Bounds.X < second.Bounds.X
    6. ? Screen.PrimaryScreen.Bounds.Location.ConvertWinPoint()
    7. : second.Bounds.Location.ConvertWinPoint();
    8. int width = second.Bounds.Width + Screen.PrimaryScreen.Bounds.Width;
    9. int height = second.Bounds.Height;
    10. window.Left = location.X;
    11. window.Top = 0;
    12. window.Width = width;
    13. window.Height = height;
    14. }
    15. }


    und fertig :D

    MfG

    Facebamm <3