当前位置: 首页>>代码示例>>C#>>正文


C# Border.CaptureMouse方法代码示例

本文整理汇总了C#中System.Windows.Controls.Border.CaptureMouse方法的典型用法代码示例。如果您正苦于以下问题:C# Border.CaptureMouse方法的具体用法?C# Border.CaptureMouse怎么用?C# Border.CaptureMouse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Controls.Border的用法示例。


在下文中一共展示了Border.CaptureMouse方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InitInfoBar

        private void InitInfoBar()
        {
            #region Main Infor Bar
            bdrInfo.ToolTip = Comisor.Resource.Info_c;
            bdrInfo.CornerRadius = new CornerRadius(3);
            bdrInfo.BorderThickness = new Thickness(1);
            bdrInfo.BorderBrush = new SolidColorBrush(colorBorder);
            bdrInfo.Opacity = 0;
            bdrInfo.Visibility = Visibility.Hidden;

            Border bdrContent = new Border();
            StackPanel stpContent = new StackPanel();
            TextBlock txtTitle = new TextBlock();
            Border bdrTitle = new Border();
            bdrContent.Background = new SolidColorBrush(colorInfoBg);
            bdrContent.CornerRadius = new CornerRadius(2);
            bdrContent.Margin = new Thickness(2);

            txtTitle.Text = Comisor.Resource.Info_Title;
            txtTitle.Foreground = new SolidColorBrush(colorFont);
            txtTitle.FontSize = 12;
            bdrTitle.Padding = new Thickness(5, 5, 5, 3);
            bdrTitle.BorderThickness = new Thickness(0, 0, 0, 1);
            bdrTitle.BorderBrush = new LinearGradientBrush(Color.FromArgb(100, 255, 255, 255), Color.FromArgb(0, 255, 255, 255), 0);
            bdrTitle.Child = txtTitle;
            bdrTitle.Cursor = main.resource.curHand_Over;

            txtInfo.IsReadOnly = true;
            txtInfo.BorderThickness = new Thickness(0);
            txtInfo.Padding = new Thickness(3);
            txtInfo.Background = Brushes.Transparent;
            txtInfo.Foreground = new SolidColorBrush(colorFont);
            txtInfo.FontSize = 12;

            stpContent.Children.Add(bdrTitle);
            stpContent.Children.Add(txtInfo);
            bdrContent.Child = stpContent;
            bdrInfo.Child = bdrContent;

            MouseEventHandler InfoDragOn = (o, e) =>
            {
                Point pt = Mouse.GetPosition(cavStage);
                pt.Offset(-ptDragOffset.X, -ptDragOffset.Y);
                TranslateInCanvas(ref bdrInfo, pt, false);
            };

            bdrTitle.PreviewMouseLeftButtonDown += (o, e) =>
            {
                bdrTitle.CaptureMouse();
                bdrTitle.Cursor = main.resource.curHand_Drag;

                ptDragOffset = Mouse.GetPosition(bdrInfo);
                bdrTitle.MouseMove += InfoDragOn;
                e.Handled = true;
            };

            bdrTitle.PreviewMouseLeftButtonUp += (o, e) =>
            {
                bdrTitle.ReleaseMouseCapture();
                bdrTitle.Cursor = main.resource.curHand_Over;
                bdrTitle.MouseMove -= InfoDragOn;
                e.Handled = true;
            };

            bdrInfo.PreviewMouseRightButtonUp += (o, e) =>
            {
                string info = txtInfo.SelectedText.Replace("\t", "\r\n");
                if (info == "") info = txtInfo.Text;
                Clipboard.SetText(info);
                txtPopup.Text = Comisor.Resource.Copied;
                ShowPopup();

                DispatcherTimer tmr = new DispatcherTimer();
                tmr.Interval = TimeSpan.FromMilliseconds(1000);
                EventHandler tmrHidePopup = (oo, ee) =>
                {
                    tmr.Stop();
                    HidePopup();
                };
                tmr.Tick += tmrHidePopup;
                tmr.Start();

                e.Handled = true;
            };

            bdrInfo.PreviewMouseRightButtonDown += (o, e) => { e.Handled = true; };	// Fix the right button up Zoom trigger.

            cavStage.Children.Add(bdrInfo);
            Canvas.SetLeft(bdrInfo, 5);
            Canvas.SetTop(bdrInfo, 5);
            #endregion

            #region Ratio Info Bar
            txtPopup = new TextBlock();
            txtPopup.FontFamily = new FontFamily("Arial");
            txtPopup.FontWeight = FontWeights.Bold;
            txtPopup.FontSize = 14;
            txtPopup.TextAlignment = TextAlignment.Center;
            txtPopup.Foreground = new SolidColorBrush(colorFont);

//.........这里部分代码省略.........
开发者ID:ysmood,项目名称:Comisor,代码行数:101,代码来源:ViewerInfoBar.cs

示例2: RegisterBorderEvents

        /// <summary>
        /// Registers the events for a draggable (outer) border
        /// </summary>
        /// <param name="borderEdge"></param>
        /// <param name="border"></param>
        void RegisterBorderEvents(WindowBorderEdge borderEdge, Border border)
        {
            border.MouseEnter += (sender, e) => {
                if(WindowState != WindowState.Maximized && ResizeMode == ResizeMode.CanResize) {
                    switch(borderEdge) {
                        case WindowBorderEdge.Left:
                        case WindowBorderEdge.Right:
                            border.Cursor = Cursors.SizeWE;
                            break;
                        case WindowBorderEdge.Top:
                        case WindowBorderEdge.Bottom:
                            border.Cursor = Cursors.SizeNS;
                            break;
                        case WindowBorderEdge.TopLeft:
                        case WindowBorderEdge.BottomRight:
                            border.Cursor = Cursors.SizeNWSE;
                            break;
                        case WindowBorderEdge.TopRight:
                        case WindowBorderEdge.BottomLeft:
                            border.Cursor = Cursors.SizeNESW;
                            break;
                    }
                }
                else
                    border.Cursor = Cursors.Arrow;
            };

            border.MouseLeftButtonDown += (sender, e) => {
                if(WindowState != WindowState.Maximized && ResizeMode == ResizeMode.CanResize) {
                    var cursorLocation = e.GetPosition(this);
                    var cursorOffset = new Point();

                    switch(borderEdge) {
                        case WindowBorderEdge.Left:
                            cursorOffset.X = cursorLocation.X;
                            break;
                        case WindowBorderEdge.TopLeft:
                            cursorOffset.X = cursorLocation.X;
                            cursorOffset.Y = cursorLocation.Y;
                            break;
                        case WindowBorderEdge.Top:
                            cursorOffset.Y = cursorLocation.Y;
                            break;
                        case WindowBorderEdge.TopRight:
                            cursorOffset.X = (Width - cursorLocation.X);
                            cursorOffset.Y = cursorLocation.Y;
                            break;
                        case WindowBorderEdge.Right:
                            cursorOffset.X = (Width - cursorLocation.X);
                            break;
                        case WindowBorderEdge.BottomRight:
                            cursorOffset.X = (Width - cursorLocation.X);
                            cursorOffset.Y = (Height - cursorLocation.Y);
                            break;
                        case WindowBorderEdge.Bottom:
                            cursorOffset.Y = (Height - cursorLocation.Y);
                            break;
                        case WindowBorderEdge.BottomLeft:
                            cursorOffset.X = cursorLocation.X;
                            cursorOffset.Y = (Height - cursorLocation.Y);
                            break;
                    }

                    _cursorOffset = cursorOffset;
                    border.CaptureMouse();
                }
            };

            border.MouseMove += (sender, e) => {
                if(WindowState == WindowState.Maximized || !border.IsMouseCaptured || ResizeMode != ResizeMode.CanResize)
                    return;

                var cursorLocation = e.GetPosition(this);

                var nHorizontalChange = (cursorLocation.X - _cursorOffset.X);
                var pHorizontalChange = (cursorLocation.X + _cursorOffset.X);
                var nVerticalChange = (cursorLocation.Y - _cursorOffset.Y);
                var pVerticalChange = (cursorLocation.Y + _cursorOffset.Y);

                switch(borderEdge) {
                    case WindowBorderEdge.Left:
                        if(Width - nHorizontalChange <= MinWidth)
                            break;
                        Left += nHorizontalChange;
                        Width -= nHorizontalChange;
                        break;
                    case WindowBorderEdge.TopLeft:
                        if(Width - nHorizontalChange <= MinWidth)
                            break;
                        Left += nHorizontalChange;
                        Width -= nHorizontalChange;
                        if(Height - nVerticalChange <= MinHeight)
                            break;
                        Top += nVerticalChange;
                        Height -= nVerticalChange;
//.........这里部分代码省略.........
开发者ID:iFaxity,项目名称:FaxLib,代码行数:101,代码来源:UIWindow.cs


注:本文中的System.Windows.Controls.Border.CaptureMouse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。