DragMove() public method

public DragMove ( ) : void
return void
Beispiel #1
0
        private void SetupShell(Window window)
        {
            //Source: http://code-inside.de/blog/2012/11/11/howto-rahmenlose-wpf-apps-mit-schattenwurf/
            window.WindowStyle = WindowStyle.None;
            window.ResizeMode = ResizeMode.NoResize;
            window.ShowInTaskbar = false;
            window.Topmost = true;
            window.SourceInitialized += (o, e) => {
                                            if (!Helper.IsWindows7)
                                                return;
                                            var helper = new WindowInteropHelper(window);
                                            var val = 2;
                                            DwmSetWindowAttribute(helper.Handle, 2, ref val, 4);
                                            var m = new Margins { bottomHeight = -1, leftWidth = -1, rightWidth = -1, topHeight = -1 };
                                            DwmExtendFrameIntoClientArea(helper.Handle, ref m);
                                            var hwnd = new WindowInteropHelper(window).Handle;
                                        };
            window.MouseLeftButtonDown += (o, e) => window.DragMove();

            //Track changes on TopMost-settings
            _Settings.PropertyChanged += (o, e) => {
                                             if (e.PropertyName == "AlwaysOnTop")
                                                 window.Topmost = _Settings.AlwaysOnTop;
                                         };
        }
Beispiel #2
0
        public MessageBoxView()
        {
            InitializeComponent();

            MessageBoxViewModel vm = (MessageBoxViewModel)DataContext;

            vm.PropertyChanged += (_, args) => {
                if (args.PropertyName == nameof(vm.Message))
                {
                    InlineExpression.SetInlineExpression(MessageBlock, vm.Message);
                }
            };

            Loaded += (_, _) => {
                // Window Setup
                _window = Window.GetWindow(this);
                Debug.Assert(_window != null, nameof(_window) + " != null");

                _window.Background = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0));

                (double dpiWidthFactor, double dpiHeightFactor) = WindowHelpers.GetDpiFactors(_window);
                Rect screen = vm.openOnScreen?.WorkingArea ?? _window.CurrentScreen().WorkingArea;
                _window.CenterOnScreen(screen, dpiWidthFactor, dpiHeightFactor);


                //Set the window style to noactivate.
                if (!vm.getsFocus)
                {
                    var helper = new WindowInteropHelper(_window);
                    SetWindowLong(helper.Handle, GWL_EXSTYLE, GetWindowLong(helper.Handle, GWL_EXSTYLE) | WS_EX_NOACTIVATE);
                }
            };

            MouseDown += (_, e) => {
                if (e.ChangedButton == MouseButton.Left)
                {
                    _window.DragMove();
                }
            };
        }
 private void MoreColorsClicked(object sender, RoutedEventArgs e)
 {
     popup.IsOpen = false;
     var advancedColorPickerDialog = new AdvancedColorPickerDialog();
     _advancedPickerWindow = new Window
                                 {
                                     AllowsTransparency = true,
                                     Content = advancedColorPickerDialog,
                                     WindowStyle = WindowStyle.None,
                                     ShowInTaskbar = false,
                                     Background = new SolidColorBrush(Colors.Transparent),
                                     Padding = new Thickness(0),
                                     Margin = new Thickness(0),
                                     WindowState = WindowState.Normal,
                                     WindowStartupLocation = WindowStartupLocation.CenterOwner,
                                     SizeToContent = SizeToContent.WidthAndHeight
                                 };
     _advancedPickerWindow.DragMove();
     _advancedPickerWindow.KeyDown += AdvancedPickerPopUpKeyDown;
     advancedColorPickerDialog.DialogResultEvent += AdvancedColorPickerDialogDialogResultEvent;
     advancedColorPickerDialog.Drag += AdvancedColorPickerDialogDrag;
     ShowModal(_advancedPickerWindow);
 }
Beispiel #4
0
        private void ToggleButtonMouseMove(object sender, MouseEventArgs e)
        {
            if (e.LeftButton != MouseButtonState.Pressed)
            {
                return;
            }
            Point pt = e.GetPosition(this);

            pt = this.PointToScreen(pt);

            if ((Popup == null) || (Popup.Visibility != Visibility.Visible))
            {
                CreatePopupWindow();
                Popup.Left = pt.X;
                Popup.Top  = pt.Y;
                Popup.Show();
                Popup.DragMove();


                DataObject data = selectedToolBoxItem.GetData(SelectedType);
                DragDrop.DoDragDrop(this, data, DragDropEffects.Copy);
            }
        }
        private void MoveWindow(Window win, Point pt)
        {
            //Use a BeginInvoke to delay the execution slightly, else we can have problems grabbing the newly opened window.
            this.Dispatcher.BeginInvoke(new Action(() =>
            {
                win.Topmost = true;
                //We position the window at the mouse position
                win.Left = pt.X - win.Width + 200;
                win.Top = pt.Y - 20;
                Debug.WriteLine(DateTime.Now.ToShortTimeString() + " dragging window");

                if (Mouse.LeftButton == MouseButtonState.Pressed)
                {
                    win.DragMove();//capture the movement to the mouse, so it can be dragged around
                }

                win.Topmost = false;
            }));
        }
Beispiel #6
0
        // Call on MainWindow.Loaded event to check on start-up.
        public static async Task CheckForUpdates(bool Silent)
        {
            if (ServiceURI == null || RemoteFileURI == null)
            {
                throw new Exception("AutoUpdater - RemoteFileURI and ServiceURI must be set.");
            }
            try
            {
                System.Net.WebClient       webClient  = new System.Net.WebClient();
                System.Net.Http.HttpClient httpClient = new System.Net.Http.HttpClient();
                var result = await httpClient.GetAsync(ServiceURI);

                var strServerVersion = await result.Content.ReadAsStringAsync();

                var serverVersion = Version.Parse(strServerVersion);
                var thisVersion   = Application.ResourceAssembly.ManifestModule.Assembly.GetName().Version;
                if (serverVersion > thisVersion)
                {
                    var strFilePath  = System.IO.Path.GetTempPath() + FileName;
                    var dialogResult = System.Windows.MessageBox.Show("A new version of " + AppName + " is available!  Would you like to download it now?  It's a no-fuss, instant process.", "New Version Available", MessageBoxButton.YesNo, MessageBoxImage.Question);
                    if (dialogResult == MessageBoxResult.Yes)
                    {
                        if (System.IO.File.Exists(strFilePath))
                        {
                            System.IO.File.Delete(strFilePath);
                        }
                        var windowProgress = new System.Windows.Window();
                        windowProgress.DragMove();
                        windowProgress.Height                = 150;
                        windowProgress.Width                 = 400;
                        windowProgress.WindowStyle           = WindowStyle.None;
                        windowProgress.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                        var progressControl = new DownloadProgressControl();
                        windowProgress.Content             = progressControl;
                        webClient.DownloadProgressChanged += (sender, args) => {
                            progressControl.progressBar.Value = args.ProgressPercentage;
                        };
                        windowProgress.Show();
                        await webClient.DownloadFileTaskAsync(new Uri(RemoteFileURI), strFilePath);

                        windowProgress.Close();
                        var psi = new ProcessStartInfo(strFilePath, "-wpfautoupdate \"" + Application.ResourceAssembly.ManifestModule.Assembly.Location + "\"");

                        // Check if target directory is writable with current privileges.  If not, start update process as admin.
                        try
                        {
                            var installPath = Path.GetDirectoryName(Application.ResourceAssembly.ManifestModule.Assembly.Location);
                            var fi          = new FileInfo(Path.Combine(installPath, "Test.txt"));
                            fi.Create();
                            fi.Delete();
                        }
                        catch
                        {
                            psi.Verb = "runas";
                        }
                        Process.Start(psi);
                        Application.Current.Shutdown();
                        return;
                    }
                }
                else
                {
                    if (!Silent)
                    {
                        MessageBox.Show(AppName + " is up-to-date.", "No Updates", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                }
            }
            catch
            {
                if (!Silent)
                {
                    MessageBox.Show("Unable to contact the server.  Check your network connection or try again later.", "Server Unreachable", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                }
                return;
            }
        }
Beispiel #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DockedTabHotArea" /> class.
        /// </summary>
        /// <param name="parent">The parent.</param>
        public DockedTabHotArea(DockContainer parent)
            : base(parent)
        {
            SpecialMouseCursor = Cursors.Hand;

            MouseClick += (sender, args) =>
            {
                switch (Position)
                {
                    case DockPosition.Main:
                        Parent.MainDockSelectedIndex = NewIndex;
                        break;
                    case DockPosition.Left:
                        Parent.LeftDockSelectedIndex = NewIndex;
                        break;
                    case DockPosition.Top:
                        Parent.TopDockSelectedIndex = NewIndex;
                        break;
                    case DockPosition.Right:
                        Parent.RightDockSelectedIndex = NewIndex;
                        break;
                    case DockPosition.Bottom:
                        Parent.BottomDockSelectedIndex = NewIndex;
                        break;
                }
            };

            MouseDown += (sender, args) =>
            {
                if (args.LeftButton != MouseButtonState.Pressed) return;
                var downPosition = args.GetPosition(Parent);
                Mouse.Capture(Parent);

                Parent.MouseDownAndMoveOverride = e =>
                {
                    if (e.LeftButton != MouseButtonState.Pressed) return;
                    var currentPosition = e.GetPosition(Parent);
                    if (currentPosition.X < downPosition.X - 20d || currentPosition.X > downPosition.X + 20d ||
                        currentPosition.Y < downPosition.Y - 20d || currentPosition.Y > downPosition.Y + 20d)
                    {
                        // The mouse moved far enough in the down position for us to consider this a drag operation
                        // Note: We may want to handle this differently in the future
                        if (_currentDragWindow == null)
                        {
                            var dockedElements = Parent.SecondaryDockWell.Where(d => d.Position == Position && d.IsDocked).ToList();
                            if (NewIndex >= dockedElements.Count) return;
                            var dockedElement = dockedElements[NewIndex];
                            if (dockedElement == null) return;
                            _currentDragWindow = new DockWellFloatWindow(Parent, dockedElement, Parent.DockWellRenderer, Parent.DockWellRenderer.DockWellHeaderHeight, Parent.DockWellRenderer.DockWellFooterHeight);
                            switch (Position)
                            {
                                case DockPosition.Left:
                                    _currentDragWindow.Height = Parent.ActualHeight;
                                    _currentDragWindow.Width = Parent.LeftDockWidth;
                                    var totalDocked = Parent.SecondaryDockWell.Count(d => d.Position == Position && d.IsDocked);
                                    if (totalDocked > 0 && Parent.LeftDockSelectedIndex >= totalDocked) Parent.LeftDockSelectedIndex = totalDocked - 1;
                                    break;
                                case DockPosition.Top:
                                    _currentDragWindow.Height = Parent.TopDockHeight;
                                    _currentDragWindow.Width = Parent.ActualWidth - Parent.LeftDockWidth - Parent.RightDockWidth;
                                    var totalDocked2 = Parent.SecondaryDockWell.Count(d => d.Position == Position && d.IsDocked);
                                    if (totalDocked2 > 0 && Parent.TopDockSelectedIndex >= totalDocked2) Parent.TopDockSelectedIndex = totalDocked2 - 1;
                                    break;
                                case DockPosition.Right:
                                    _currentDragWindow.Height = Parent.ActualHeight;
                                    _currentDragWindow.Width = Parent.RightDockWidth;
                                    var totalDocked3 = Parent.SecondaryDockWell.Count(d => d.Position == Position && d.IsDocked);
                                    if (totalDocked3 > 0 && Parent.RightDockSelectedIndex >= totalDocked3) Parent.RightDockSelectedIndex = totalDocked3 - 1;
                                    break;
                                case DockPosition.Bottom:
                                    _currentDragWindow.Height = Parent.BottomDockHeight;
                                    _currentDragWindow.Width = Parent.ActualWidth - Parent.LeftDockWidth - Parent.RightDockWidth;
                                    var totalDocked4 = Parent.SecondaryDockWell.Count(d => d.Position == Position && d.IsDocked);
                                    if (totalDocked4 > 0 && Parent.BottomDockSelectedIndex >= totalDocked4) Parent.BottomDockSelectedIndex = totalDocked4 - 1;
                                    break;
                            }
                            Mouse.Capture(null);
                            _currentDragWindow.DragMove();
                        }
                    }
                };
            };
        }
 public static bool EnableGlassEffect(Window window)
 {
     window.MouseLeftButtonDown += (s, e) =>
         {
             window.DragMove();
         };
         return EnableGlassEffect(window, true);
 }
Beispiel #9
0
        //public static void DragMoveWindow(System.Windows.Window window)
        //{
        //    DragMoveWindow(window, null);
        //}

        public static void DragMoveWindow(System.Windows.Window window,
                                          Func <bool> condition, Action dragStartCallback, Action <bool> dragEndCallback, UIElement[] excludedUiElements)
        {
            Point startPoint = new Point();
            bool  hasMoved   = false;

            window.PreviewMouseLeftButtonDown += (object sender, MouseButtonEventArgs e) =>
            {
                if (condition != null)
                {
                    if (!condition())
                    {
                        return;
                    }
                }
                hasMoved   = false;
                startPoint = e.GetPosition(window);
                //int a = 10;
            };

            window.MouseLeftButtonUp += (object sender, MouseButtonEventArgs e) =>
            {
                if (dragEndCallback != null)
                {
                    dragEndCallback(hasMoved);
                }
            };

            window.PreviewMouseMove += (object sender, MouseEventArgs e) =>
            {
                var currentPoint = e.GetPosition(window);

                if (excludedUiElements != null)
                {
                    foreach (UIElement uiElem in excludedUiElements)
                    {
                        if (uiElem.IsMouseDirectlyOver)
                        {
                            e.Handled = false;
                            return;
                        }
                    }
                }

                if (e.LeftButton == MouseButtonState.Pressed)
                {
                    if ((Math.Abs(currentPoint.X - startPoint.X) > SystemParameters.MinimumHorizontalDragDistance ||
                         Math.Abs(currentPoint.Y - startPoint.Y) > SystemParameters.MinimumVerticalDragDistance))
                    {
                        if (dragStartCallback != null)
                        {
                            dragStartCallback();
                        }
                        // Prevent Click from firing
                        window.ReleaseMouseCapture();
                        hasMoved = true;
                        window.DragMove();
                    }
                }
            };
        }