Пример #1
0
 public Screen(System.Windows.Forms.Screen screen)
 {
     FScreen = screen;
     Dpi = this.GetDpi();
     Scaling = (float)Dpi / DEFAULT_DPI;
     Watch();
 }
Пример #2
0
        public WindowImpl(string title)
        {
            Background = Brushes.HotPink;
            UseLayoutRounding = true;
            Title = title;            

            Grid = new Grid()
            {
                UseLayoutRounding = true,
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch,
            };
            
            this.AddChild(Grid);

            KeyDownEvents = Observable.FromEvent<KeyEventArgs>(this, "KeyDown").Select(e => e.EventArgs);
            KeyUpEvents = Observable.FromEvent<KeyEventArgs>(this, "KeyUp").Select(e => e.EventArgs);
            MouseMoveEvents = Observable.FromEvent<MouseEventArgs>(this, "MouseMove").Select(e => e.EventArgs.GetPosition(Grid).ToXna());
            MouseDownEvents = Observable.FromEvent<MouseButtonEventArgs>(this, "MouseDown").Select(e => e.EventArgs.GetPosition(Grid).ToXna());
            MouseUpEvents = Observable.FromEvent<MouseButtonEventArgs>(this, "MouseUp").Select(e => e.EventArgs.GetPosition(Grid).ToXna());

            KeyDownEvents.Where(e => e.Key == Key.F).Subscribe(ie => this.Fullscreen = this.Fullscreen == null ? Screen.PrimaryScreen : null);
            
            MaybeFullscreen = null;
            Hwnd = new WindowInteropHelper(this).EnsureHandle();            
            Show();
        }
Пример #3
0
 protected override void OnStartup(StartupEventArgs e)
 {
     DoResize = true;
     MoveToScreen = System.Windows.Forms.Screen.PrimaryScreen;
     if (_hook == null)
         _hook = new ShellHook();
     base.OnStartup(e);
 }
Пример #4
0
        private double WindowTop()
        {
            var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
            var dip1   = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y);
            var dip2   = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Height);
            var top    = (dip2.Y - this.SearchBox.ActualHeight) / 4 + dip1.Y;

            return(top);
        }
Пример #5
0
        /// <summary>
        /// Calculates X co-ordinate of main window top left corner.
        /// </summary>
        /// <returns>X co-ordinate of main window top left corner</returns>
        private double WindowLeft()
        {
            var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
            var dip1   = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0);
            var dip2   = WindowsInteropHelper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0);
            var left   = (dip2.X - ActualWidth) / 2 + dip1.X;

            return(left);
        }
Пример #6
0
        private MeasureWnd getWindowForScreen(System.Windows.Forms.Screen screen)
        {
            if (!_MeasureWnds.TryGetValue(screen.DeviceName, out MeasureWnd wnd))
            {
                return(createWindowForScreen(screen));
            }

            return(wnd);
        }
Пример #7
0
        /// <summary>
        /// Take screenshot.
        /// </summary>
        public static Bitmap CaptureImage(System.Windows.Forms.Screen screen = null)
        {
            var s = screen ?? System.Windows.Forms.Screen.PrimaryScreen;

            return(CaptureImage(
                       s.Bounds.X, s.Bounds.Y,
                       s.Bounds.Width, s.Bounds.Height
                       ));
        }
Пример #8
0
        public static void CaptureImage(ref Bitmap b, System.Windows.Forms.Screen screen = null)
        {
            var s = screen ?? System.Windows.Forms.Screen.PrimaryScreen;

            CaptureImage(ref b,
                         s.Bounds.X, s.Bounds.Y,
                         s.Bounds.Width, s.Bounds.Height
                         );
        }
        private double SetWindowTopPosition()
        {
            var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
            var dip1   = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y);
            var dip2   = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Height);
            var top    = ((dip2.Y - LauncherControl.ActualHeight) / 4) + dip1.Y;

            return(top);
        }
Пример #10
0
        public MenuBarShadow(MenuBar bar, System.Windows.Forms.Screen screen)
        {
            Screen  = screen;
            MenuBar = bar;

            InitializeComponent();

            SetPosition();
        }
Пример #11
0
        private void GetMainWindowPosAndSaveSettings()
        {
            GDIScreen currentScreen = GDIScreen.FromHandle(new WindowInteropHelper(this).Handle);

            Properties.Settings.Default.CurrentScreenHeight = currentScreen.WorkingArea.Height;
            Properties.Settings.Default.CurrentScreenWidth  = currentScreen.WorkingArea.Width;

            Properties.Settings.Default.Save();
        }
Пример #12
0
        public static WpfScreen GetScreenFrom(Window window)
        {
            WindowInteropHelper windowInteropHelper = new WindowInteropHelper(window);

            System.Windows.Forms.Screen screen = System.Windows.Forms.Screen.FromHandle(windowInteropHelper.Handle);
            WpfScreen wpfScreen = new WpfScreen(-1, screen);

            return(wpfScreen);
        }
Пример #13
0
        public Taskbar(System.Windows.Forms.Screen screen)
        {
            Screen = screen;

            InitializeComponent();

            setupTaskbar();
            setupTaskbarAppearance();
        }
Пример #14
0
        private static void CenterWindowToScreen(System.Windows.Forms.Screen screen)
        {
            if (!isFullScreen)
            {
                Rectangle screenRect = new Rectangle(screen.Bounds.X, screen.Bounds.Y, screen.Bounds.Width, screen.Bounds.Height);

                window.Position = screenRect.Location + new Point((screenRect.Size.X - graphics.PreferredBackBufferWidth) / 2, (screenRect.Size.Y - graphics.PreferredBackBufferHeight - 80) / 2);
            }
        }
Пример #15
0
        public void SetPos(System.Windows.Forms.Screen screen)
        {
            Left   = screen.Bounds.Left;
            Top    = screen.Bounds.Top;
            Width  = screen.Bounds.Width;
            Height = screen.Bounds.Height;

            Reset();
        }
Пример #16
0
 public static ScreenInfo Convert(this System.Windows.Forms.Screen screen)
 {
     return(new ScreenInfo
     {
         Primary = screen.Primary,
         DeviceName = screen.DeviceName,
         Bounds = screen.Bounds.Convert(),
         BitsPerPixel = screen.BitsPerPixel,
     });
 }
Пример #17
0
        public static Monitor CreateFromScreen(System.Windows.Forms.Screen screen)
        {
            Monitor mon = new Monitor();

            mon.WorkArea = new Size(screen.WorkingArea.Width, screen.WorkingArea.Height);
            mon.Primary  = screen.Primary;
            mon.Device   = screen.DeviceName;
            mon.WorkAreaStartPosition = new Size(screen.WorkingArea.Left, screen.WorkingArea.Top);
            return(mon);
        }
Пример #18
0
        /// <summary>
        /// Calculates Y co-ordinate of main window top left corner
        /// </summary>
        /// <returns>Y co-ordinate of main window top left corner</returns>
        private double WindowTop()
        {
            var screen      = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
            var dpi1        = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y);
            var dpi2        = WindowsInteropHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Height);
            var totalHeight = this.SearchBoxBorder.Margin.Top + this.SearchBoxBorder.Margin.Bottom + this.SearchBox.Height + this.ListBoxBorder.Margin.Top + this.ListBoxBorder.Margin.Bottom + MAX_LIST_HEIGHT;
            var top         = (dpi2.Y - totalHeight) / 4 + dpi1.Y;

            return(top);
        }
Пример #19
0
        private void renderCapturedImage(System.Windows.Controls.Image i, System.Windows.Forms.Screen s)
        {
            System.Drawing.Size size = s.Bounds.Size;
            Bitmap   b = new Bitmap(s.Bounds.Width, s.Bounds.Height);
            Graphics g = Graphics.FromImage(b as System.Drawing.Image);

            g.CopyFromScreen(s.Bounds.X, s.Bounds.Y, 0, 0, size);

            i.Source = BitmapToImageSource(b);
        }
Пример #20
0
 public static Rect GetScreenBoundsAt(int x, int y)
 {
     System.Windows.Forms.Screen screenAtPoint = System.Windows.Forms.Screen.FromPoint(new System.Drawing.Point(x, y));
     if (screenAtPoint != null)
     {
         System.Drawing.Rectangle screenBounds = screenAtPoint.Bounds;
         return(new Rect(screenBounds.Left, screenBounds.Top, screenBounds.Width, screenBounds.Height));
     }
     return(Rect.Empty);
 }
Пример #21
0
 private void SettingsChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
 {
     if (e.PropertyName == "primaryMonitor")
     {
         primaryScreen = DeviceUtil.GetScreen(Settings.Default.primaryMonitor);
         Dispatcher.BeginInvoke(new Action(delegate()
         {
             this.updateWindowToScreen(primaryScreen);
         }));
     }
 }
Пример #22
0
        public static void GetDpiByScreen(System.Windows.Forms.Screen screen, out uint dpiX, out uint dpiY)
        {
            if (!Exists_SHCore_Library())
            {
                throw new DllNotFoundException("Dll file not find.");
            }
            System.Drawing.Point pnt = new System.Drawing.Point(screen.Bounds.Left + 1, screen.Bounds.Top + 1);
            IntPtr mon = MonitorFromPoint(pnt, 2 /*MONITOR_DEFAULTTONEAREST*/);

            GetDpiForMonitor(mon, DpiType.Effective, out dpiX, out dpiY);
        }
Пример #23
0
        public void CornerWindow(System.Windows.Forms.Screen screen)
        {
            System.Drawing.Rectangle desktopArea = screen.WorkingArea;

            // Set Window to a fixed position on Desktop
            Left = desktopArea.Right - Width;
            Top  = desktopArea.Top;

            // Set Window to TopMost
            // Topmost = true;
        }
Пример #24
0
        /// <summary>
        /// Get the max size allowed for this window based on the current screen.
        /// </summary>
        /// <param name="hwnd">The handle to the window.</param>
        /// <returns>The max size allowed for this window based on the current screen.</returns>
        private Win32.MINMAXINFO GetMaxInfo(IntPtr hwnd)
        {
            System.Windows.Forms.Screen screen = System.Windows.Forms.Screen.FromHandle(hwnd);
            Win32.MINMAXINFO            info   = new Win32.MINMAXINFO();
            info.ptMaxPosition.x = Math.Abs(screen.WorkingArea.Left - screen.Bounds.Left);
            info.ptMaxPosition.y = Math.Abs(screen.WorkingArea.Top - screen.Bounds.Top);
            info.ptMaxSize.x     = screen.WorkingArea.Width;
            info.ptMaxSize.y     = screen.WorkingArea.Height;

            return(info);
        }
Пример #25
0
        public static WPFRect GetBounds(WPFPoint p)
        {
            var rect = WinScreen.GetBounds(
                new WinPoint(
                    (int)p.X,
                    (int)p.Y));

            return(new WPFRect(
                       new WPFPoint(rect.X, rect.Y),
                       new WPFSize(rect.Width, rect.Height)));
        }
Пример #26
0
        public void NewWindow(System.Windows.Forms.Screen screen)
        {
            // Create a new shortcut window
            WindowItemVM    windowItemVM    = ContextHelper.NewWindow(screen);
            ShortcutsWindow shortcutsWindow = new ShortcutsWindow();

            WindowItemVMs.Add(windowItemVM);
            shortcutsWindow.DataContext = windowItemVM;
            shortcutsWindow.Show();
            SaveData.SaveShortcuts(false);
        }
Пример #27
0
        public static List <WpfScreen> AllScreens()
        {
            List <WpfScreen> screens = new List <WpfScreen>();

            for (int i = 0; i < System.Windows.Forms.Screen.AllScreens.Length; i++)
            {
                System.Windows.Forms.Screen screen = System.Windows.Forms.Screen.AllScreens[i];
                screens.Add(new WpfScreen(i, screen));
            }
            return(screens);
        }
        /// <summary>
        /// Just a helper method for AlignToParent
        /// </summary>
        /// <param name="dialog">the Window to align</param>
        /// <returns>true if successful, false if there wasn't sufficient space on the display</returns>
        private static bool AlignToLeft(Window dialog)
        {
            //TODO  ?
#if SILVERLIGHT
            return(true);
#else
            Window parent                = dialog.Owner as Window;
            double Separation            = 2;
            double VirtualScreenBottom   = SystemParameters.VirtualScreenTop + SystemParameters.VirtualScreenHeight;
            double ScreenLeft            = SystemParameters.VirtualScreenLeft;
            bool   isMultipleScreensHorz = (SystemParameters.VirtualScreenWidth > SystemParameters.PrimaryScreenWidth);

            if (isMultipleScreensHorz)
            {
                System.Windows.Forms.Screen[] allScreens = System.Windows.Forms.Screen.AllScreens;
                if (allScreens.Count() > 1)
                {
                    System.Windows.Forms.Screen s2 = allScreens[1];
                    double left2  = s2.Bounds.Left;
                    double right2 = s2.Bounds.Right;

                    if (parent.Left.IsInRange(left2, right2))
                    {
                        // Evidently, this Window is on Screen 2, so use it's area.
                        double xToLeftOfParent = parent.Left - left2;
                        if (xToLeftOfParent > dialog.Width)
                        {
                            dialog.Left = parent.Left - dialog.Width - Separation;
                            dialog.Top  = Math.Min(parent.Top, VirtualScreenBottom - dialog.Height);
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }
            }

            // Try the left side.
            //TODO: Check this for various positions of secondary display.

            if ((parent.Left - ScreenLeft) > dialog.Width)
            {
                dialog.Left = parent.Left - dialog.Width - Separation;
                dialog.Top  = Math.Min(parent.Top, VirtualScreenBottom - dialog.Height);
                return(true);
            }
            else
            {
                return(false);
            }
#endif
        }
Пример #29
0
        public static Size GetSize(System.Windows.Forms.Screen screen)
        {
            //uint xDpi, yDpi;
            ScreenExtensions.Dpi dpi = screen.GetDpi(DpiType.Effective);
            var size = new Size();

            size.Width  = screen.Bounds.Width / (dpi.x / 96.0);
            size.Height = screen.Bounds.Height / (dpi.y / 96.0);
            size.XDPI   = dpi.x;
            size.YDPI   = dpi.y;
            return(size);
        }
Пример #30
0
        private void CenterScreen()
        {
            double frm_width  = this.parent.Width;
            double frm_height = this.parent.Height;

            System.Windows.Forms.Screen src = System.Windows.Forms.Screen.PrimaryScreen;
            int src_height = src.Bounds.Height;
            int src_width  = src.Bounds.Width;

            //this.parent.Left = (src_width - frm_width) / 2;
            //this.parent.Top = (src_height - frm_height) / 2;
        }
Пример #31
0
        void InitializeCaptureWindows()
        {
            foreach (var sc in System.Windows.Forms.Screen.AllScreens)
            {
                Trace.WriteLine("Screen: " + sc.Bounds);
            }

            m_screen        = System.Windows.Forms.Screen.AllScreens.First(s => s.Bounds.Height == 1080);
            m_primaryScreen = System.Windows.Forms.Screen.PrimaryScreen;

            Setup_A5_FS2020();
        }
Пример #32
0
        public static WpfScreen GetScreenFrom(int x, int y)
        {
            //int x = (int)Math.Round(X);
            //int y = (int)Math.Round(Y);

            // are x,y device-independent-pixels ??
            System.Drawing.Point        drawingPoint = new System.Drawing.Point(x, y);
            System.Windows.Forms.Screen screen       = System.Windows.Forms.Screen.FromPoint(drawingPoint);
            WpfScreen wpfScreen = new WpfScreen(-1, screen);

            return(wpfScreen);
        }
        private void App_Closing()
        {
            var currentScreen = GDIScreen.FromHandle(_app.WindowHandle);

            _settings.ActiveMonitor = currentScreen.DeviceName;

            var top  = _app.Top - currentScreen.Bounds.Top;
            var left = _app.Left - currentScreen.Bounds.Left;

            _settings.WindowTopPerc  = top / currentScreen.WorkingArea.Height;
            _settings.WindowLeftPerc = left / currentScreen.WorkingArea.Width;
        }
Пример #34
0
        static TuioContact()
        {
            //get monitor settings 
            // Try to position application to first non-primary monitor
            foreach (var screen in System.Windows.Forms.Screen.AllScreens)
            {
                if (!screen.Primary)
                {
                    secondaryScreen = screen;

                    Console.WriteLine("TUIO Contacts: Secondary screen found at " + secondaryScreen.WorkingArea.ToString());
                    break;
                }
            }
        }
Пример #35
0
        private OverlayWindow()
        {
            InitializeComponent();

            primaryScreen = DeviceUtil.GetScreen(Settings.Default.primaryMonitor);

            Settings.Default.PropertyChanged += SettingsChanged;
            SystemEvents.DisplaySettingsChanged += SystemEvents_DisplaySettingsChanged;

            this.baseGrid.Visibility = Visibility.Hidden;
            this.layoutChooserOverlay.Visibility = Visibility.Hidden;

            //Compensate for DPI settings

            Loaded += (o, e) =>
            {
                //PresentationSource source = PresentationSource.FromVisual(this);
                //CompositionTarget ct = source.CompositionTarget;
                //Matrix transformMatrix = ct.TransformFromDevice;
                //this.baseCanvas.RenderTransform = new MatrixTransform(transformMatrix);

                this.updateWindowToScreen(primaryScreen);
            };
        }
Пример #36
0
 private Screen(System.Windows.Forms.Screen screen)
 {
     this.screen = screen;
 }
Пример #37
0
 private void SettingsChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
 {
     if (e.PropertyName == "primaryMonitor")
     {
         primaryScreen = DeviceUtil.GetScreen(Settings.Default.primaryMonitor);
         Dispatcher.BeginInvoke(new Action(delegate()
         {
             this.updateWindowToScreen(primaryScreen);
         }));
     }
 }
Пример #38
0
 private void SystemEvents_DisplaySettingsChanged(object sender, EventArgs e)
 {
     this.primaryScreen = DeviceUtils.DeviceUtil.GetScreen(Settings.Default.primaryMonitor);
     Dispatcher.BeginInvoke(new Action(delegate()
     {
         this.updateWindowToScreen(primaryScreen);
     }));
 }