Exemplo n.º 1
0
        public WindowMessage(string text, WindowPosition position = WindowPosition.Down,
                             bool slowText = false)
        {
            Height = 40;
            Width = 150;

            switch (position)
            {
                    case WindowPosition.Up:
                    Position = new Vector2(5,5);
                    break;

                    case WindowPosition.Down:
                    Position = new Vector2(5,85);
                    break;
            }

            SplitMessage(text);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Docks the form to the scanner form in the relative
        /// position specified
        /// </summary>
        /// <param name="form">form to dock</param>
        /// <param name="scanner">scanner form to dock to</param>
        /// <param name="scannerPosition">relative position</param>
        public static void DockWithScanner(Form form, Form scanner, WindowPosition scannerPosition)
        {
            if (form == scanner)
            {
                return;
            }

            switch (scannerPosition)
            {
                case WindowPosition.TopRight:
                    form.Location = new Point(scanner.Left - form.Width, scanner.Top);
                    break;

                case WindowPosition.TopLeft:
                    form.Location = new Point(scanner.Left + scanner.Width, scanner.Top);
                    break;

                case WindowPosition.BottomLeft:
                    form.Location = new Point(scanner.Left + scanner.Width, Screen.PrimaryScreen.WorkingArea.Height - form.Height);
                    break;

                case WindowPosition.BottomRight:
                    form.Location = new Point(scanner.Left - form.Width, Screen.PrimaryScreen.WorkingArea.Height - form.Height);
                    break;

                case WindowPosition.MiddleRight:
                    form.Location = new Point(scanner.Left - form.Width, (Screen.PrimaryScreen.WorkingArea.Height - form.Height) / 2);
                    break;

                case WindowPosition.MiddleLeft:
                    form.Location = new Point(scanner.Width, (Screen.PrimaryScreen.WorkingArea.Height - form.Height) / 2);
                    break;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Partial maximize.  Sets the window width to
        /// a percent of the display width.
        /// </summary>
        /// <param name="handle">handle of the window</param>
        /// <param name="scannerPosition">which corner should the window be positioned at?</param>
        /// <param name="percent">percentage of display monitor width</param>
        public static void SetWindowSizePercent(IntPtr handle, WindowPosition scannerPosition, int percent)
        {
            Log.Debug("Entering...scannerPosition=" + scannerPosition.ToString() + " percent=" + percent.ToString());
            int screenOffset = 0;
            int moveX = 0;
            int moveY = 0;  // not really using Y-axis yet but something to keep in mind for the future

            if (percent <= 10)
            {
                return;
            }

            if (percent > 100)
                percent = 100;

            screenOffset = 100 - percent;

            if (handle != IntPtr.Zero)
            {
                Rectangle r = Screen.PrimaryScreen.WorkingArea;

                if (r.Width > 0 && r.Height > 0)
                {
                    Log.Debug("Resize window to " + (r.Width * percent) / 100 + ", " + r.Height);

                    switch (scannerPosition)
                    {
                        case WindowPosition.TopRight:
                            moveX = 0;
                            moveY = 0;
                            break;

                        case WindowPosition.TopLeft:
                            moveX = (r.Width * screenOffset) / 100;
                            moveY = 0;
                            break;

                        case WindowPosition.BottomLeft:
                            moveX = (r.Width * screenOffset) / 100;
                            moveY = 0;
                            break;

                        case WindowPosition.BottomRight:
                            moveX = 0;
                            moveY = 0;
                            break;
                    }

                    Log.Debug("screenOffset=" + screenOffset + " moveX=" + moveX.ToString() + " moveY=" + moveY.ToString());
                    User32Interop.SetWindowPos(handle.ToInt32(), 0, moveX, moveY, (r.Width * percent) / 100, r.Height, 0x0040 | 0x0004);
                }
            }
            else
            {
                Log.Debug("fgWnd is zero");
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Set window pos to the specified position and notify when window position
        /// has changed
        /// </summary>
        /// <param name="form">The form</param>
        /// <param name="position">Where to set the position</param>
        public static void SetWindowPositionAndNotify(Form form, WindowPosition position)
        {
            Log.Debug("Setting position to " + position);
            SetWindowPosition(form, position);
            if (EvtWindowPositionChanged != null)
            {
                Log.Debug("Calling evtpositionchanged with " + position);

                EvtWindowPositionChanged(form, position);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Set the window position
        /// </summary>
        /// <param name="form">form to reposition</param>
        /// <param name="position">the new position</param>
        public static void SetWindowPosition(Form form, WindowPosition position)
        {
            form.StartPosition = FormStartPosition.Manual;

            Log.Debug("Before setposition " + position);

            switch (position)
            {
                case WindowPosition.TopRight:
                    form.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - form.Width, 0);
                    break;

                case WindowPosition.TopLeft:
                    form.Location = new Point(0, 0);
                    break;

                case WindowPosition.BottomRight:
                    form.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - form.Width,
                                            Screen.PrimaryScreen.WorkingArea.Height - form.Height);
                    break;

                case WindowPosition.BottomLeft:
                    form.Location = new Point(0, Screen.PrimaryScreen.WorkingArea.Height - form.Height);
                    break;

                case WindowPosition.MiddleRight:
                    form.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - form.Width, (Screen.PrimaryScreen.WorkingArea.Height - form.Height) / 2);
                    break;

                case WindowPosition.MiddleLeft:
                    form.Location = new Point(0, (Screen.PrimaryScreen.WorkingArea.Height - form.Height) / 2);
                    break;

                case WindowPosition.CenterScreen:
                    form.Location = new Point((Screen.PrimaryScreen.WorkingArea.Width - form.Width) / 2,
                                        (Screen.PrimaryScreen.WorkingArea.Height - form.Height) / 2);
                    break;
            }
            Log.Debug("After setposition " + position);
        }
Exemplo n.º 6
0
 public static void MoveWindow( WindowPosition p )
 {
     MoveWindow(p, 0, 0);
 }
Exemplo n.º 7
0
        public static void MoveWindow( WindowPosition p )
        {
            if (p == WindowPosition.NotSet) {
                return;
            } else if (p == WindowPosition.Minimized) {
                // TODO
                throw new NotImplementedException();
            } else if (p == WindowPosition.Restore) {
                // TODO
                throw new NotImplementedException();
            }

            IntPtr hWin;
            Rect rc;
            Screen scr;
            int maxColWidth = Console.LargestWindowWidth - 4,
                maxColHeight = Console.LargestWindowHeight - 1;

            hWin = GetConsoleWindow();
            GetWindowRect(hWin, out rc);
            scr = Screen.FromPoint(new Point(rc.left, rc.top));

            int cols = Console.WindowWidth, rows = Console.WindowHeight;
            int x = rc.left, y = rc.top;

            // Figure out the window size.
            if (p == WindowPosition.Center) {
                cols = Console.WindowWidth;
            } else if (p == WindowPosition.Top || p == WindowPosition.Bottom || p == WindowPosition.Maximized) {
                cols = maxColWidth;
            } else if (p == WindowPosition.TopRight || p == WindowPosition.Right || p == WindowPosition.BottomRight
                    || p == WindowPosition.TopLeft || p == WindowPosition.Left || p == WindowPosition.BottomLeft) {
                cols = (int)Math.Round(maxColWidth / 2F, 0);
            }

            if (p == WindowPosition.Center) {
                rows = Console.WindowHeight;
            } else if (p == WindowPosition.Left || p == WindowPosition.Right || p == WindowPosition.Maximized) {
                rows = maxColHeight;
            } else if (p == WindowPosition.TopLeft || p == WindowPosition.Top || p == WindowPosition.TopRight
                    || p == WindowPosition.BottomLeft || p == WindowPosition.Bottom || p == WindowPosition.BottomRight) {
                rows = (int)Math.Round(maxColHeight / 2F, 0);
            }

            // Set the window size..
            if (cols > Console.BufferWidth) {
                Console.BufferWidth = cols;
            }
            Console.WindowWidth = cols;
            Console.BufferWidth = cols;

            if (rows > Console.BufferHeight) {
                Console.BufferHeight = rows;
            }
            Console.WindowHeight = rows;

            if (p == WindowPosition.Maximized || p == WindowPosition.Center) {
                ConsoleUtils.CenterWindow();
            } else {
                // Figure out the window location.
                if (p == WindowPosition.Top || p == WindowPosition.Bottom
                        || p == WindowPosition.TopLeft || p == WindowPosition.Left || p == WindowPosition.BottomLeft) {
                    x = scr.WorkingArea.Left;
                } else if (p == WindowPosition.TopRight || p == WindowPosition.Right || p == WindowPosition.BottomRight) {
                    x = (int)Math.Round(scr.WorkingArea.Width / 2F, 0);
                }

                if (p == WindowPosition.Left || p == WindowPosition.Right
                        || p == WindowPosition.TopLeft || p == WindowPosition.Top || p == WindowPosition.TopRight) {
                    y = scr.WorkingArea.Top;
                } else if (p == WindowPosition.BottomLeft || p == WindowPosition.Bottom || p == WindowPosition.BottomRight) {
                    y = (int)Math.Round(scr.WorkingArea.Height / 2F, 0);
                }

                // Set the window location..
                MoveWindow(x, y);
            }
        }
 public static void SetNegativePosition(DependencyObject obj, WindowPosition value)
 {
     obj.SetValue(NegativePositionProperty, value);
 }
Exemplo n.º 9
0
        private EventHandler GetWindowPositionEventHandler(WindowPosition position)
        {
            switch (position)
            {
                case WindowPosition.LeftOneThird:
                    return LeftThird_EventHandler;
                case WindowPosition.LeftHalf:
                    return LeftHalf_EventHandler;
                case WindowPosition.LeftTwoThirds:
                    return LeftTwoThirds_EventHandler;

                case WindowPosition.RightOneThird:
                    return RightThird_EventHandler;
                case WindowPosition.RightHalf:
                    return RightHalf_EventHandler;
                case WindowPosition.RightTwoThirds:
                    return RightTwoThirds_EventHandler;

                case WindowPosition.TopHalf:
                    return TopHalf_EventHandler;
                case WindowPosition.BottomHalf:
                    return BottomHalf_EventHandler;

                case WindowPosition.Center:
                    return Center_EventHandler;
                case WindowPosition.Fill:
                    return Fill_EventHandler;

                default:
                    return Fill_EventHandler;
            }
        }
Exemplo n.º 10
0
 public static extern void gtk_window_set_position(IntPtr self, WindowPosition window);
Exemplo n.º 11
0
        private static void WindowParametryChanged(DependencyObject d, DependencyPropertyChangedEventArgs a)
        {
            if (d is Window)
            {
                Window w = d as Window;

                var size     = System.Windows.Forms.Screen.AllScreens[GetWindowScreen(w)].Bounds.Size;
                var location = System.Windows.Forms.Screen.AllScreens[GetWindowScreen(w)].Bounds.Location;

                WindowPosition position = GetWindowPosition(d);

                w.SizeChanged -= WindowRight_SizeChanged;
                w.SizeChanged -= WindowBottom_SizeChanged;

                Thickness th     = GetWindowThickness(w);
                Point     indent = new Point();
                if (w.Owner != null)
                {
                    position = WindowPositionBehaviour.GetWindowPosition(w.Owner);
                    switch (WindowPositionBehaviour.GetWindowPosition(w.Owner))
                    {
                    case WindowPosition.Left:
                    case WindowPosition.LeftBottom:
                    case WindowPosition.LeftTop:
                        indent.X = w.Owner.Width + (HideButtonBehaviour.GetUseHideButton(w.Owner) ? -30 + w.Owner.Left - location.X - 6 : 0);
                        break;

                    case WindowPosition.Right:
                    case WindowPosition.RightBottom:
                    case WindowPosition.RightTop:
                        indent.X = -(w.Owner.Width - (HideButtonBehaviour.GetUseHideButton(w.Owner) ? 30 : 0));
                        break;

                    case WindowPosition.Top:
                        indent.Y = w.Owner.Height + (HideButtonBehaviour.GetUseHideButton(w.Owner) ? -30 + w.Owner.Top - location.Y - 6 : 0);
                        break;

                    case WindowPosition.Bottom:
                        indent.Y = -w.Owner.Height + (HideButtonBehaviour.GetUseHideButton(w.Owner) ? 30 : 0);
                        break;
                    }
                }

                switch (position)
                {
                case WindowPosition.Left:
                    w.SizeToContent = SizeToContent.Height;
                    w.Left          = location.X + th.Left + indent.X;
                    w.Top           = location.Y + th.Top + indent.Y;;

                    w.SizeChanged -= WindowRightBottom_SizeChanged;
                    w.SizeChanged -= WindowRight_SizeChanged;
                    w.SizeChanged -= WindowBottom_SizeChanged;
                    break;

                case WindowPosition.Right:
                    w.SizeToContent = SizeToContent.Height;

                    w.Left = location.X + size.Width + th.Left - th.Right - NTW.Common.GetIndentTaskBar(false) + indent.X;
                    w.Top  = location.Y + th.Top + indent.Y;

                    w.SizeChanged -= WindowRightBottom_SizeChanged;
                    w.SizeChanged -= WindowBottom_SizeChanged;

                    w.SizeChanged += WindowRight_SizeChanged;
                    break;

                case WindowPosition.Top:
                    w.SizeToContent = SizeToContent.Width;

                    w.Left = location.X + th.Left + indent.X;
                    w.Top  = location.Y + th.Top + indent.Y;

                    w.SizeChanged -= WindowRightBottom_SizeChanged;
                    w.SizeChanged -= WindowRight_SizeChanged;
                    w.SizeChanged -= WindowBottom_SizeChanged;
                    break;

                case WindowPosition.Bottom:
                    w.SizeToContent = SizeToContent.Width;

                    w.Left = location.X + th.Left + indent.X;
                    w.Top  = location.Y * 2 + size.Height + th.Top - th.Bottom - NTW.Common.GetIndentTaskBar(true) + indent.Y;

                    w.SizeChanged -= WindowRightBottom_SizeChanged;
                    w.SizeChanged -= WindowRight_SizeChanged;

                    w.SizeChanged += WindowBottom_SizeChanged;
                    break;

                case WindowPosition.None:
                    break;

                case WindowPosition.LeftTop:
                    w.SizeToContent = SizeToContent.WidthAndHeight;

                    w.Left = location.X + th.Left + indent.X;
                    w.Top  = location.Y + th.Top + indent.Y;

                    w.SizeChanged -= WindowRightBottom_SizeChanged;
                    w.SizeChanged -= WindowRight_SizeChanged;
                    w.SizeChanged -= WindowBottom_SizeChanged;
                    break;

                case WindowPosition.LeftBottom:
                    w.SizeToContent = SizeToContent.WidthAndHeight;

                    w.Left = location.X + th.Left + indent.X;
                    w.Top  = location.Y + size.Height + th.Top - th.Bottom - NTW.Common.GetIndentTaskBar(true) + indent.Y;

                    w.SizeChanged -= WindowRightBottom_SizeChanged;
                    w.SizeChanged -= WindowRight_SizeChanged;

                    w.SizeChanged += WindowBottom_SizeChanged;
                    break;

                case WindowPosition.RightTop:
                    w.SizeToContent = SizeToContent.WidthAndHeight;

                    w.Left = location.X + size.Width + th.Left - th.Right - NTW.Common.GetIndentTaskBar(false) + indent.X;
                    w.Top  = location.Y + th.Top + indent.Y;

                    w.SizeChanged -= WindowBottom_SizeChanged;
                    w.SizeChanged -= WindowRightBottom_SizeChanged;

                    w.SizeChanged += WindowRight_SizeChanged;
                    break;

                case WindowPosition.RightBottom:
                    w.SizeToContent = SizeToContent.WidthAndHeight;

                    w.Left = location.X + size.Width + th.Left - th.Right - NTW.Common.GetIndentTaskBar(false) + indent.X;
                    w.Top  = location.Y + size.Height + th.Top - th.Bottom - NTW.Common.GetIndentTaskBar(true) + indent.Y;

                    w.SizeChanged -= WindowRight_SizeChanged;
                    w.SizeChanged -= WindowBottom_SizeChanged;

                    w.SizeChanged += WindowRightBottom_SizeChanged;
                    break;
                }
            }
        }
 public static void SetMinOnParentPosition(DependencyObject element, WindowPosition value)
 {
     element.SetValue(MinOnParentPositionProperty, value);
 }
Exemplo n.º 13
0
		/// <summary>
		/// Sets the window position, z-order.
		/// </summary>
		/// <param name="handle">The window handle.</param>
		/// <param name="insertAfter">Z-Order flags</param>
		/// <param name="bounds">The new position and size.</param>
		/// <param name="flags">Options for showing the window.</param>
		/// <returns></returns>
		public static bool SetWindowPos(IWin32Window handle, IntPtr insertAfter, Rectangle bounds, WindowPosition flags)
		{
			return UnsafeNativeMethods.SetWindowPos(new HandleRef(handle, handle.Handle), new HandleRef(handle, insertAfter), bounds.X, bounds.Y, bounds.Width, bounds.Height, (int) flags);
		}
Exemplo n.º 14
0
 void WritePos(WindowPosition pos, int buf)
 {
     if (1 == pos.Offset)
     {
         uint pixel = m_input[buf];
         if (1 == pos.Length || -1 == Array.FindIndex (m_input, buf+1, pos.Length-1, x => x != pixel))
         {
             m_out.Write ((byte)0);
             m_out.Write ((byte)pos.Length);
         }
         else
         {
             m_out.Write ((byte)1);
             m_out.Write ((byte)pos.Length);
             m_out.Write ((byte)1);
         }
     }
     else if (1 == pos.Length)
     {
         if (pos.Offset < 0x100)
         {
             m_out.Write ((byte)3);
             m_out.Write ((byte)pos.Offset);
         }
         else
         {
             m_out.Write ((byte)4);
             m_out.Write (pos.Offset);
         }
     }
     else if (pos.Offset < 0x100)
     {
         m_out.Write ((byte)1);
         m_out.Write ((byte)pos.Length);
         m_out.Write ((byte)pos.Offset);
     }
     else
     {
         m_out.Write ((byte)2);
         m_out.Write ((byte)pos.Length);
         m_out.Write (pos.Offset);
     }
 }
Exemplo n.º 15
0
 public static void SetTargetPosition(DependencyObject obj, WindowPosition value)
 {
     obj.SetValue(TargetPositionProperty, value);
 }
        protected override void OnInitialized(EventArgs e)
        {
            WindowPosition.Move(this);

            base.OnInitialized(e);
        }
        /// <summary>
        /// Set media window
        /// </summary>
        /// <param name="MediaWindow">Media window</param>
        /// <param name="Width">Floating window width</param>
        /// <param name="Height">Floating window height</param>
        /// <param name="Position">Floating window position</param>
        /// <param name="TitleBar">Floating window title bar</param>
        /// <param name="Resize">Floating window resize</param>
        /// <param name="Title">Floating window title</param>
        /// <remarks>
        /// <para>
        /// All optional arguments are applicable to floating window only.
        /// </para>
        /// </remarks>
        public void SetMediaWindow(
			MediaWindow			MediaWindow,
			Int32				Width = 0,
			Int32				Height = 0,
			WindowPosition		Position = WindowPosition.Center,
			WindowTitleBar		TitleBar = WindowTitleBar.TitleBarWithCloseButton,
			WindowResize		Resize = WindowResize.KeepAspectRatio,
			String				Title = null
			)
        {
            // set media play window code
            MediaScreenParamBE.AddInteger("/W", (Int32) MediaWindow);

            // all choices but floating window
            if(MediaWindow != MediaWindow.Floating)
            {
            MediaScreenParamBE.Remove("/F");
            return;
            }

            // play rendition in floating window
            // Table 9.19 page 774
            PdfDictionary FloatingWindow = new PdfDictionary(this);
            MediaScreenParamBE.AddDictionary("/F", FloatingWindow);

            // window's dimensions
            if(Width == 0 || Height == 0)
            {
            Width = 320;
            Height = 180;
            }
            FloatingWindow.AddFormat("/D", "[{0} {1}]", Width, Height);

            FloatingWindow.AddInteger("/P", (Int32) Position);

            FloatingWindow.AddBoolean("/T", TitleBar != WindowTitleBar.NoTitleBar);
            if(TitleBar == WindowTitleBar.NoTitleBar) return;

            FloatingWindow.AddInteger("/R", (Int32) Resize);

            if(Title != null)
            {
            //			if(Document.Encryption == null)
            //				{
            //				FloatingWindow.AddFormat("/TT", "[() ({0})]", Title);
            //				}
            //			else
            //				{
            FloatingWindow.AddFormat("/TT", "[{0} {1}]", Document.TextToPdfString(String.Empty, this), Document.TextToPdfString(Title, this));
            //				}
            }

            return;
        }
Exemplo n.º 18
0
        private void Load(XmlReader reader, Form mainForm)
        {
            var comparer = StringComparison.OrdinalIgnoreCase;

            List <SvgTestSuite> testSuites = new List <SvgTestSuite>(SvgTestSuite.TestSuiteCount);

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (string.Equals(reader.Name, "option", comparer))
                    {
                        string optionName = reader.GetAttribute("name");
                        string optionType = reader.GetAttribute("type");
                        if (string.Equals(optionType, "String", comparer))
                        {
                            string optionValue = reader.ReadElementContentAsString();

                            switch (optionName)
                            {
                            //case "WebSuitePath":
                            //    _webSuitePath = optionValue;
                            //    break;
                            //case "LocalSuitePath":
                            //    if (optionValue.StartsWith(ParentSymbol, comparer))
                            //    {
                            //        var inputPath = string.Copy(_localSuitePath);
                            //        int indexOf = inputPath.IndexOf(SharpVectors, comparer);

                            //        if (indexOf > 0)
                            //        {
                            //            var basePath    = inputPath.Substring(0, indexOf);
                            //            _localSuitePath = Path.Combine(basePath, optionValue.Replace(ParentSymbol, ""));
                            //        }
                            //        else
                            //        {
                            //            _localSuitePath = optionValue;
                            //        }
                            //    }
                            //    else
                            //    {
                            //        _localSuitePath = optionValue;
                            //    }

                            //    // Ignore old test suite directory, if found
                            //    if (string.IsNullOrWhiteSpace(_localSuitePath) ||
                            //        !this.IsLocalSuitePathChanged(Path.GetFullPath(TestsSvg)))
                            //    {
                            //        _localSuitePath = Path.GetFullPath(TestsSvg10);
                            //    }
                            //    break;
                            case "SelectedValuePath":
                                _selectedValuePath = optionValue;
                                break;
                            }
                        }
                        else if (string.Equals(optionType, "Boolean", comparer))
                        {
                            bool optionValue = reader.ReadElementContentAsBoolean();
                            switch (optionName)
                            {
                            case "HidePathsRoot":
                                _hidePathsRoot = optionValue;
                                break;
                            }
                        }
                        else if (string.Equals(optionType, "Other", comparer))
                        {
                            string optionValue = reader.ReadElementContentAsString();
                            switch (optionName)
                            {
                            case "Theme":
                                _theme = (DockingTheme)Enum.Parse(typeof(DockingTheme), optionValue, true);
                                break;
                            }
                        }
                    }
                    else if (string.Equals(reader.Name, "testSuite", comparer))
                    {
                        if (!reader.IsEmptyElement)
                        {
                            SvgTestSuite testSuite = new SvgTestSuite(reader);
                            if (testSuite.IsValid())
                            {
                                testSuites.Add(testSuite);
                            }
                        }
                    }
                    else if (string.Equals(reader.Name, "placements", comparer))
                    {
                        if (reader.IsEmptyElement == false)
                        {
                            if (reader.ReadToFollowing("WindowPosition"))
                            {
                                var xs = new XmlSerializer(typeof(WindowPosition));
                                _winPosition = xs.Deserialize(reader) as WindowPosition;
                            }
                        }
                    }
                }
            }

            if (testSuites.Count == SvgTestSuite.TestSuiteCount)
            {
                var selectedSuite = SvgTestSuite.GetSelected(testSuites);
                if (selectedSuite != null)
                {
                    _localSuitePath = selectedSuite.LocalSuitePath;
                    _webSuitePath   = selectedSuite.WebSuitePath;

                    _testSuites = testSuites;
                }
            }

            if (mainForm != null && _winPosition != null)
            {
                try
                {
                    switch (_winPosition.WindowState)
                    {
                    case FormWindowState.Maximized:
                        mainForm.Location      = _winPosition.MaximisedPoint;
                        mainForm.StartPosition = FormStartPosition.Manual;
                        break;

                    case FormWindowState.Normal:
                        if (_winPosition.IsIdenticalScreen())
                        {
                            mainForm.Location      = _winPosition.Location;
                            mainForm.Size          = _winPosition.Size;
                            mainForm.StartPosition = FormStartPosition.Manual;
                        }
                        break;

                    case FormWindowState.Minimized:
                        _winPosition.WindowState = FormWindowState.Normal;
                        break;

                    default:
                        break;
                    }
                    mainForm.WindowState = _winPosition.WindowState;
                }
                catch (Exception ex)
                {
                    Trace.TraceError(ex.ToString());
                }
            }
        }
Exemplo n.º 19
0
            public WindowPosition Clone()
            {
                WindowPosition cloned = new WindowPosition(this);

                return(cloned);
            }
Exemplo n.º 20
0
 public static void SetHideButtonPosition(DependencyObject element, WindowPosition value)
 {
     element.SetValue(HideButtonPositionProperty, value);
 }
Exemplo n.º 21
0
 WindowPosition FindLongest(int win_begin, int win_end, int buf_begin, int buf_end)
 {
     buf_end = Math.Min (buf_begin + MaxMatchSize, buf_end);
     WindowPosition pos = new WindowPosition { Offset = 0, Length = 0 };
     if (win_begin == win_end)
         return pos;
     SortedSet<int> found;
     if (m_dict.TryGetValue (m_input[buf_begin], out found))
     {
         foreach (var win_pos in found.Reverse())
         {
             var match_end = Mismatch (buf_begin+1, buf_end, win_pos+1);
             int weight = match_end - win_pos;
             int distance = buf_begin - win_pos;
             if (weight > pos.Length)
             {
                 pos.Offset = (ushort)distance;
                 pos.Length = (ushort)weight;
                 if (MaxMatchSize == weight)
                     break;
             }
         }
     }
     return pos;
 }
Exemplo n.º 22
0
        public static void MoveWindow(WindowPosition p)
        {
            if (p == WindowPosition.NotSet)
            {
                return;
            }
            else if (p == WindowPosition.Minimized)
            {
                // TODO
                throw new NotImplementedException();
            }
            else if (p == WindowPosition.Restore)
            {
                // TODO
                throw new NotImplementedException();
            }

            IntPtr hWin;
            Rect   rc;
            Screen scr;
            int    maxColWidth  = Console.LargestWindowWidth - 4,
                   maxColHeight = Console.LargestWindowHeight - 1;

            hWin = GetConsoleWindow();
            GetWindowRect(hWin, out rc);
            scr = Screen.FromPoint(new Point(rc.left, rc.top));

            int cols = Console.WindowWidth, rows = Console.WindowHeight;
            int x = rc.left, y = rc.top;

            // Figure out the window size.
            if (p == WindowPosition.Center)
            {
                cols = Console.WindowWidth;
            }
            else if (p == WindowPosition.Top || p == WindowPosition.Bottom || p == WindowPosition.Maximized)
            {
                cols = maxColWidth;
            }
            else if (p == WindowPosition.TopRight || p == WindowPosition.Right || p == WindowPosition.BottomRight ||
                     p == WindowPosition.TopLeft || p == WindowPosition.Left || p == WindowPosition.BottomLeft)
            {
                cols = (int)Math.Round(maxColWidth / 2F, 0);
            }

            if (p == WindowPosition.Center)
            {
                rows = Console.WindowHeight;
            }
            else if (p == WindowPosition.Left || p == WindowPosition.Right || p == WindowPosition.Maximized)
            {
                rows = maxColHeight;
            }
            else if (p == WindowPosition.TopLeft || p == WindowPosition.Top || p == WindowPosition.TopRight ||
                     p == WindowPosition.BottomLeft || p == WindowPosition.Bottom || p == WindowPosition.BottomRight)
            {
                rows = (int)Math.Round(maxColHeight / 2F, 0);
            }

            // Set the window size..
            if (cols > Console.BufferWidth)
            {
                Console.BufferWidth = cols;
            }
            Console.WindowWidth = cols;
            Console.BufferWidth = cols;

            if (rows > Console.BufferHeight)
            {
                Console.BufferHeight = rows;
            }
            Console.WindowHeight = rows;

            if (p == WindowPosition.Maximized || p == WindowPosition.Center)
            {
                ConsoleUtils.CenterWindow();
            }
            else
            {
                // Figure out the window location.
                if (p == WindowPosition.Top || p == WindowPosition.Bottom ||
                    p == WindowPosition.TopLeft || p == WindowPosition.Left || p == WindowPosition.BottomLeft)
                {
                    x = scr.WorkingArea.Left;
                }
                else if (p == WindowPosition.TopRight || p == WindowPosition.Right || p == WindowPosition.BottomRight)
                {
                    x = (int)Math.Round(scr.WorkingArea.Width / 2F, 0);
                }

                if (p == WindowPosition.Left || p == WindowPosition.Right ||
                    p == WindowPosition.TopLeft || p == WindowPosition.Top || p == WindowPosition.TopRight)
                {
                    y = scr.WorkingArea.Top;
                }
                else if (p == WindowPosition.BottomLeft || p == WindowPosition.Bottom || p == WindowPosition.BottomRight)
                {
                    y = (int)Math.Round(scr.WorkingArea.Height / 2F, 0);
                }

                // Set the window location..
                MoveWindow(x, y);
            }
        }
Exemplo n.º 23
0
 /// <summary>
 /// Sets the window position, z-order.
 /// </summary>
 /// <param name="handle">The window handle.</param>
 /// <param name="insertAfter">Z-Order flags</param>
 /// <param name="bounds">The new position and size.</param>
 /// <param name="flags">Options for showing the window.</param>
 /// <returns></returns>
 public static bool SetWindowPos(IWin32Window handle, IntPtr insertAfter, Rectangle bounds, WindowPosition flags)
 {
     return(UnsafeNativeMethods.SetWindowPos(new HandleRef(handle, handle.Handle), new HandleRef(handle, insertAfter), bounds.X, bounds.Y, bounds.Width, bounds.Height, (int)flags));
 }
Exemplo n.º 24
0
        private void UpdateWindowPlacement()
        {
            Window window = Form.Tag as Window;

            if (window == null)
            {
                return;
            }

            Rect2i         oldbounds = null;
            Point2i        pos       = null;
            Size2i         size      = null;
            WindowSize     initsize  = window.InitialSize;
            WindowPosition initpos   = window.InitialPosition;

            if (initsize == WindowSize.Minimal)
            {
                if (oldbounds == null)
                {
                    window.Refresh();
                    oldbounds = window.Bounds;
                }
                size = oldbounds.Size; // window.LayoutInfo.MinSize;
            }
            else if (initsize == WindowSize.Current)
            {
                if (oldbounds == null)
                {
                    oldbounds = window.Bounds;
                }
                size = oldbounds.Size;
            }
            else
            {
                throw new Exception("Unimplemented initial size");
            }



            if (pos == null && initpos == WindowPosition.Current)
            {
                //if (oldbounds == null) oldbounds = Bounds;
                pos = new Point2i(oldbounds.X, oldbounds.Y);
            }
            if (pos == null && initpos == WindowPosition.CenterParent)
            {
                Form frm = Form.ActiveForm; //form to center to

                //Dont center invisible windows, this is actually a hack
                //around centering to visual studios so called 'parking window' if this
                //is the app:s first window shown
                if (frm != null && frm.Visible == false)
                {
                    frm = null;
                }

                //now we got a form to center to?
                if (frm != null)
                {
                    var fb = frm.Bounds;
                    int x  = fb.Left + fb.Width / 2 - size.Width / 2;
                    int y  = fb.Top + fb.Height / 2 - size.Height / 2;
                    pos = new Point2i(x, y);
                }
                else //no active window, fallback to screen center
                {
                    initpos = WindowPosition.CenterScreen;
                }
            }
            if (pos == null && initpos == WindowPosition.CenterScreen)
            {
                var rs = Guppy.ScreenResolution;
                int x  = rs.Width / 2 - size.Width / 2;
                int y  = rs.Height / 2 - size.Height / 2;

                pos = new Point2i(x, y);
            }
            if (pos == null) //unresolvable
            {
                throw new Exception("Unimplemented initial position");
            }

            //next time we show, use the current size and position
            window.InitialPosition = WindowPosition.Current;
            window.InitialSize     = WindowSize.Current;

            Bounds = new Rect2i(pos, size);
        } //End UpdateWindowPlacement
Exemplo n.º 25
0
        /// <summary>
        /// Set the window position
        /// </summary>
        /// <param name="form">form to reposition</param>
        /// <param name="insertAfter">insert after this window</param>
        /// <param name="position">new position</param>
        public static void SetWindowPosition(Form form, IntPtr insertAfter, WindowPosition position)
        {
            form.StartPosition = FormStartPosition.Manual;
            var location = new Point(0, 0);

            switch (position)
            {
                case WindowPosition.TopRight:
                    location = new Point(Screen.PrimaryScreen.WorkingArea.Width - form.Width, 0);
                    break;

                case WindowPosition.TopLeft:
                    location = new Point(0, 0);
                    break;

                case WindowPosition.BottomRight:
                    location = new Point(Screen.PrimaryScreen.WorkingArea.Width - form.Width,
                                            Screen.PrimaryScreen.WorkingArea.Height - form.Height);
                    break;

                case WindowPosition.BottomLeft:
                    location = new Point(0, Screen.PrimaryScreen.WorkingArea.Height - form.Height);
                    break;

                case WindowPosition.CenterScreen:
                    location = new Point((Screen.PrimaryScreen.WorkingArea.Width - form.Width) / 2,
                                            (Screen.PrimaryScreen.WorkingArea.Height - form.Height) / 2);
                    break;
            }

            User32Interop.SetWindowPos(form.Handle.ToInt32(), insertAfter.ToInt32(), location.X, location.Y, 0, 0, 0x0040 | 0x0001);
        }
Exemplo n.º 26
0
 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     Program.WriteSetting("WindowPosition", WindowPosition.SerializePosition(this));
 }
Exemplo n.º 27
0
 /// <summary>
 /// Set window pos to the specified position and notify when window position
 /// has changed
 /// </summary>
 /// <param name="form">The form</param>
 /// <param name="position">Where to set the position</param>
 public static void SetWindowPositionAndNotify(Form form, IntPtr insertAfter, WindowPosition position)
 {
     SetWindowPosition(form, insertAfter, position);
     if (EvtWindowPositionChanged != null)
     {
         EvtWindowPositionChanged(form, position);
     }
 }
Exemplo n.º 28
0
 public Window(string title, WindowPosition x, int y, int width, int height, WindowOptions options)
     : this(title, (int)x, y, width, height, options)
 {
 }
Exemplo n.º 29
0
 /// <summary>
 /// Toggles size of the fg window between maximized to partially
 /// maximized
 /// </summary>
 /// <param name="scannerPosition">where to position the window</param>
 /// <param name="percent">the partial maximize percentage</param>
 public static void ToggleFgWindowMaximizeAndPartialMaximize(WindowPosition scannerPosition, int percent)
 {
     IntPtr fgWindow = GetForegroundWindow();
     if (fgWindow != IntPtr.Zero)
     {
         if (IsMaximized(fgWindow))
         {
             RestoreWindow(fgWindow);
             SetForegroundWindowSizePercent(scannerPosition, percent);
         }
         else
         {
             MaximizeWindow(fgWindow);
         }
     }
 }
Exemplo n.º 30
0
 public Window(string title, int x, WindowPosition y, int width, int height, WindowOptions options)
     : this(title, x, (int)y, width, height, options)
 {
 }
Exemplo n.º 31
0
 /// <summary>
 /// Sets the width of the foreground window to a certain
 /// percentage of the display monitor width.
 /// </summary>
 /// <param name="scannerPosition">where to position the window?</param>
 /// <param name="percent">the percent width</param>
 public static void SetForegroundWindowSizePercent(WindowPosition scannerPosition, int percent)
 {
     SetWindowSizePercent(User32Interop.GetForegroundWindow(), scannerPosition, percent);
 }
Exemplo n.º 32
0
 public Window(string title, WindowPosition position, int width, int height, WindowOptions options)
     : this(title, (int)position, (int)position, width, height, options)
 {
 }
        private async Task MoveApplication()
        {
            if (String.IsNullOrWhiteSpace(Settings.Screen))
            {
                Logger.Instance.LogMessage(TracingLevel.WARN, $"Screen not specified.");
                await Connection.ShowAlert();

                return;
            }

            if (Settings.AppSpecific && String.IsNullOrWhiteSpace(Settings.ApplicationName))
            {
                Logger.Instance.LogMessage(TracingLevel.WARN, $"Application not specified.");
                await Connection.ShowAlert();

                return;
            }

            if (String.IsNullOrWhiteSpace(Settings.XPosition) || String.IsNullOrWhiteSpace(Settings.YPosition))
            {
                Logger.Instance.LogMessage(TracingLevel.WARN, $"X or Y position not specified.");
                await Connection.ShowAlert();

                return;
            }


            if (!int.TryParse(Settings.XPosition, out int xPosition))
            {
                Logger.Instance.LogMessage(TracingLevel.WARN, $"Invalid X position: {Settings.XPosition}");
                await Connection.ShowAlert();

                return;
            }

            if (!int.TryParse(Settings.YPosition, out int yPosition))
            {
                Logger.Instance.LogMessage(TracingLevel.WARN, $"Invalid Y position: {Settings.YPosition}");
                await Connection.ShowAlert();

                return;
            }

            WindowSize   windowSize   = null;
            WindowResize windowResize = WindowResize.NoResize;

            if (Settings.ResizeWindow)
            {
                windowResize = WindowResize.ResizeWindow;

                if (String.IsNullOrWhiteSpace(Settings.Height) || String.IsNullOrWhiteSpace(Settings.Width))
                {
                    Logger.Instance.LogMessage(TracingLevel.WARN, $"Height or Width position not specified.");
                    await Connection.ShowAlert();

                    return;
                }

                if (!int.TryParse(Settings.Height, out int height))
                {
                    Logger.Instance.LogMessage(TracingLevel.WARN, $"Invalid height: {Settings.Height}");
                    await Connection.ShowAlert();

                    return;
                }

                if (!int.TryParse(Settings.Width, out int width))
                {
                    Logger.Instance.LogMessage(TracingLevel.WARN, $"Invalid width: {Settings.Width}");
                    await Connection.ShowAlert();

                    return;
                }

                windowSize = new WindowSize(height, width);
            }
            else if (Settings.MaximizeWindow)
            {
                windowResize = WindowResize.Maximize;
            }
            else if (Settings.MinimizeWindow)
            {
                windowResize = WindowResize.Minimize;
            }
            else if (Settings.OnlyTopmost)
            {
                windowResize = WindowResize.OnlyTopmost;
            }

            Screen screen = MonitorManager.Instance.GetScreenFromUniqueValue(Settings.Screen);

            if (screen == null)
            {
                Logger.Instance.LogMessage(TracingLevel.ERROR, $"Could not find screen {Settings.Screen}");
                await Connection.ShowAlert();

                return;
            }

            var processCount = WindowPosition.MoveProcess(new MoveProcessSettings()
            {
                AppSpecific       = Settings.AppSpecific,
                Name              = Settings.ApplicationName,
                DestinationScreen = screen,
                Position          = new System.Drawing.Point(xPosition, yPosition),
                WindowResize      = windowResize,
                WindowSize        = windowSize,
                MakeTopmost       = Settings.TopmostWindow,
                LocationFilter    = Settings.ShouldFilterLocation ? Settings.LocationFilter : null,
                TitleFilter       = Settings.ShouldFilterTitle ? Settings.TitleFilter : null
            });

            if (processCount > 0)
            {
                tmrRetryProcess.Stop();
            }
            else if (processCount == 0 && !tmrRetryProcess.Enabled)
            {
                if (!Int32.TryParse(Settings.RetryAttempts, out retryAttempts))
                {
                    Logger.Instance.LogMessage(TracingLevel.WARN, $"Invalid RetryAttempts: {Settings.RetryAttempts}");
                    return;
                }
                tmrRetryProcess.Start();
            }
        }
Exemplo n.º 34
0
 public Window(string title, int x, WindowPosition y, ScreenResolution resolution, WindowOptions options)
     : this(title, x, (int)y, resolution.Width(), resolution.Height(), options)
 {
 }
Exemplo n.º 35
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     WindowPosition.Move(this);
 }
Exemplo n.º 36
0
 public Window(string title, WindowPosition position, ScreenResolution resolution, WindowOptions options)
     : this(title, (int)position, (int)position, resolution.Width(), resolution.Height(), options)
 {
 }
Exemplo n.º 37
0
        private void Load(XmlReader reader, Form mainForm)
        {
            var comparer = StringComparison.OrdinalIgnoreCase;

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (string.Equals(reader.Name, "option", comparer))
                    {
                        string optionName = reader.GetAttribute("name");
                        string optionType = reader.GetAttribute("type");
                        if (string.Equals(optionType, "String", comparer))
                        {
                            string optionValue = reader.ReadElementContentAsString();

                            switch (optionName)
                            {
                            case "WebSuitePath":
                                _webSuitePath = optionValue;
                                break;

                            case "LocalSuitePath":
                                if (optionValue.StartsWith(ParentSymbol, comparer))
                                {
                                    var inputPath = string.Copy(_localSuitePath);
                                    int indexOf   = inputPath.IndexOf(SharpVectors, comparer);

                                    if (indexOf > 0)
                                    {
                                        var basePath = inputPath.Substring(0, indexOf);
                                        _localSuitePath = Path.Combine(basePath, optionValue.Replace(ParentSymbol, ""));
                                    }
                                    else
                                    {
                                        _localSuitePath = optionValue;
                                    }
                                }
                                else
                                {
                                    _localSuitePath = optionValue;
                                }
                                break;

                            case "SelectedValuePath":
                                _selectedValuePath = optionValue;
                                break;
                            }
                        }
                        else if (string.Equals(optionType, "Boolean", comparer))
                        {
                            bool optionValue = reader.ReadElementContentAsBoolean();
                            switch (optionName)
                            {
                            case "HidePathsRoot":
                                _hidePathsRoot = optionValue;
                                break;
                            }
                        }
                    }
                    else if (string.Equals(reader.Name, "placements", StringComparison.OrdinalIgnoreCase))
                    {
                        if (reader.IsEmptyElement == false)
                        {
                            if (reader.ReadToFollowing("WindowPosition"))
                            {
                                var xs = new XmlSerializer(typeof(WindowPosition));
                                _winPosition = xs.Deserialize(reader) as WindowPosition;
                            }
                        }
                    }
                }
            }

            if (mainForm != null && _winPosition != null)
            {
                try
                {
                    switch (_winPosition.WindowState)
                    {
                    case FormWindowState.Maximized:
                        mainForm.Location      = _winPosition.MaximisedPoint;
                        mainForm.StartPosition = FormStartPosition.Manual;
                        break;

                    case FormWindowState.Normal:
                        if (_winPosition.IsIdenticalScreen())
                        {
                            mainForm.Location      = _winPosition.Location;
                            mainForm.Size          = _winPosition.Size;
                            mainForm.StartPosition = FormStartPosition.Manual;
                        }
                        break;

                    case FormWindowState.Minimized:
                        _winPosition.WindowState = FormWindowState.Normal;
                        break;

                    default:
                        break;
                    }
                    mainForm.WindowState = _winPosition.WindowState;
                }
                catch (Exception ex)
                {
                    Trace.TraceError(ex.ToString());
                }
            }
        }
Exemplo n.º 38
0
 public void ResizeAndPositionWindow(WindowSize windowSize, WindowPosition windowPosition)
 {
     RunOnHandle(handle => ResizeAndPositionWindow(handle, windowSize, windowPosition));
 }
 public PlayerStatsGui(WindowPosition windowPosition = WindowPosition.Down)
 {
     if (windowPosition == WindowPosition.Up)
         _lessY = 128;
 }
Exemplo n.º 40
0
 static extern IntPtr SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int Y, int cx, int cy, WindowPosition uFlags);
Exemplo n.º 41
0
        /// -------------------------------------------------------------------
        /// <summary></summary>
        /// -------------------------------------------------------------------
        void TestMove1(bool canMove, CheckType checkType, Type expectedException, WindowPosition placement, EventFired eventFired, Point point, bool moveWindowBackToOriginalPostion, HasFocus hasFocus)
        {
            Point oldPoint = new Point(m_le.Current.BoundingRectangle.Left, m_le.Current.BoundingRectangle.Top);

            try
            {
                //"Precondition: TransformPattern.CanMove == true", 
                TSC_VerifyPropertyEqual(pCanMove, canMove, TransformPattern.CanMoveProperty, CheckType.IncorrectElementConfiguration);

                //"Step: Ensure the AutomationElement does not have focus by calling SetFocus(AutomationElement.RootElement.FirstChild) - "OS's Start Button"",
                switch (hasFocus)
                {
                    case HasFocus.No:
                        TSC_SetFocusVerifyWithEvent(ControlFirstChild(AutomationElement.RootElement), CheckType.Verification);
                        break;

                    case HasFocus.DontCare:
                        break;

                    default:
                        throw new ArgumentException("Need to handle a HasFocus enum");
                }

                //"Step: Setup a BoundingRectangle PropertyChange event", 
                TSC_AddPropertyChangedListener(m_le, TreeScope.Element, new AutomationProperty[] { AutomationElement.BoundingRectangleProperty }, CheckType.Verification);

                //"Step: Verify that Move with the random point is called successfully", 
                TS_Move(point, expectedException, CheckType.Verification);

                //"Step: Wait for event to get fired",
                TSC_WaitForEvents(2);

                if (placement == WindowPosition.Exact)
                {
                    //"Verify: The BoundingRectangle PropertyChange event is fired",
                    TSC_VerifyPropertyChangedListener(m_le, new EventFired[] { eventFired }, new AutomationProperty[] { AutomationElement.BoundingRectangleProperty }, CheckType.Verification);
                    if (eventFired == EventFired.True)
                    {
                        // Verify element was moved to the correct position by validating the BoundingRectangle
                        TS_VerifyBoundingRect(new Rect(point.X, point.Y, m_le.Current.BoundingRectangle.Width, m_le.Current.BoundingRectangle.Height), m_le.Current.BoundingRectangle, CheckType.Verification);
                    }
                    else
                    {
                        // Verify element was not moved to the correct position by validating the BoundingRectangle
                        TS_VerifyBoundingRect(new Rect(oldPoint.X, oldPoint.Y, m_le.Current.BoundingRectangle.Width, m_le.Current.BoundingRectangle.Height), m_le.Current.BoundingRectangle, CheckType.Verification);
                    }
                }
                else if (placement == WindowPosition.Within)
                {
                    // "Verify: The BoundingRectangle PropertyChange event is fired if the element is moved",
                    if (m_le.Current.BoundingRectangle.Left == point.X && m_le.Current.BoundingRectangle.Top == point.Y)
                    {
                        TSC_VerifyPropertyChangedListener(m_le, new EventFired[] { EventFired.False }, new AutomationProperty[] { AutomationElement.BoundingRectangleProperty }, CheckType.Verification);
                    }
                    else
                    {
                        TSC_VerifyPropertyChangedListener(m_le, new EventFired[] { EventFired.True }, new AutomationProperty[] { AutomationElement.BoundingRectangleProperty }, CheckType.Verification);
                    }

                    // OS does not allow off the screen so will move it back to a good location
                    TS_VerifyPlacedWithinScreen(CheckType.Verification);

                }

            }
            finally // incase we throw expection, come back and clean up
            {
                if (moveWindowBackToOriginalPostion)
                {
                    //"Step: Move the window back to it's original position",
                    Comment("Moving window back to it's original position");
                    if (oldPoint != new Point(m_le.Current.BoundingRectangle.Left, m_le.Current.BoundingRectangle.Top))
                        TS_Move(oldPoint, null, CheckType.Verification);
                    else
                        m_TestStep++;
                }
            }
        }
Exemplo n.º 42
0
        public MainWindow()
        {
            InitializeComponent();
            // Set the viewmodel as this view isn't invoked by ReactiveUI
            ViewModel = new MainViewModel();

            this.OneWayBind(ViewModel, x => x.Title, x => x.Title);
            this.OneWayBind(ViewModel, x => x.Title, x => x.Tray.ToolTipText);

            // TaskbarIcon context menu bindings
            this.BindCommand(ViewModel, x => x.Profile, x => x.MenuProfile);
            this.BindCommand(ViewModel, x => x.Dashboard, x => x.MenuDash);
            this.BindCommand(ViewModel, x => x.Community, x => x.MenuForums);
            this.BindCommand(ViewModel, x => x.Exit, x => x.MenuExit);
            this.WhenAnyObservable(x => x.ViewModel.Exit).Subscribe(_ => Close());

            // Lowest level UserError handler, any UserError's thrown that aren't handled will hit this.
            UserError.RegisterHandler(error => {
                Tray.ShowBalloonTip("Error", error.ErrorMessage, BalloonIcon.Error);
                return(Observable.Return(RecoveryOptionResult.CancelOperation));
            });

            // Change the content in the ViewModelViewHost based on the `Content` property in the ViewModel
            this.WhenAnyValue(x => x.ViewModel.Content)
            .Where(x => x != null)
            .Subscribe(model => ContentView.ViewModel = model);

            // Sets the position of the window when the height changes.
            this.WhenAnyValue(x => x.Height)
            .Subscribe(_ => SetWindowLocation());

            // TaskbarIcon left-click handler
            // Will show the window, or do nothing, based on the `_shouldNotShow` property
            Observable.FromEventPattern <RoutedEventHandler, RoutedEventArgs>(
                h => Tray.TrayLeftMouseUp += h, h => Tray.TrayLeftMouseUp -= h)
            .Subscribe(_ => {
                if (!_shouldNotShow)
                {
                    SetWindowLocation();
                    Show();
                    Activate();
                }
                _shouldNotShow = false;
            });

            // TaskbarIcon right-click handler
            // Sets the `_shouldNotShow` property to false so that the window will show next left-click
            // Logic here:
            //  Right-click is outside the bounds of the window so the `Deactivated` event is fired
            //  `Deactivated` event will hide the window and set `_shouldNotShow` to true
            //  This event handler is hit and sets `_shouldNotShow` to false so the application works as expected.
            Observable.FromEventPattern <RoutedEventHandler, RoutedEventArgs>(
                h => Tray.TrayRightMouseDown += h, h => Tray.TrayRightMouseDown -= h)
            .Subscribe(_ => _shouldNotShow    = false);

            // Hides the window when the user clicks anywhere outside the Window
            // Sets the `_shouldNotShow` property based on whether the cursor is within the TaskbarIcon's rect.
            this.Events().Deactivated.Subscribe(_ => {
                _shouldNotShow = WindowPosition.IsCursorOverNotifyIcon(Tray) && WindowPosition.IsNotificationAreaActive;
                Hide();
            });

            this.Events().SourceInitialized.Subscribe(_ => {
                // The following code disables the ability to resize the window
                // while still retaining the chrome border
                var windowHandle = new WindowInteropHelper(this).Handle;
                var windowSource = HwndSource.FromHwnd(windowHandle);
                if (windowSource == null)
                {
                    return;
                }

                var resizeHook = new ResizeHook();
                windowSource.AddHook(resizeHook.WndProc);
            });
        }