소스 검색

zhao:1 增肌获取缩放后工作区域2修改截图最小宽高为50 超出禁止拖动

tags/录制修改前
耀 4 년 전
부모
커밋
415c81f55b
3개의 변경된 파일173개의 추가작업 그리고 24개의 파일을 삭제
  1. 16
    2
      Common/system/PrimaryScreen.cs
  2. 2
    2
      XHWK.WKTool/XHMicroLessonSystemWindow.xaml
  3. 155
    20
      XHWK.WKTool/XHMicroLessonSystemWindow.xaml.cs

+ 16
- 2
Common/system/PrimaryScreen.cs 파일 보기

@@ -142,9 +142,23 @@ namespace Common.system
142 142
         /// 缩放后的大小
143 143
         /// </summary>
144 144
         /// <returns></returns>
145
-        public static SizeF ScaleScreenSize()
145
+        public static SizeF ScaleScreenSize
146 146
         {
147
-            return new SizeF(((float)DESKTOP.Width) / (DpiX / 96f), ((float)DESKTOP.Height) / (DpiY / 96f));
147
+            get
148
+            {
149
+               return new SizeF(((float)DESKTOP.Width) / (DpiX / 96f), ((float)DESKTOP.Height) / (DpiY / 96f));
150
+            }
151
+        }
152
+        /// <summary>
153
+        /// 获取缩放后的工作区域大小
154
+        /// </summary>
155
+        public static RectangleF ScaleWorkingAreaSize
156
+        {
157
+            get
158
+            {
159
+                RectangleF rect = System.Windows.Forms.Screen.GetWorkingArea(new System.Drawing.Point((int)ScaleScreenSize.Width, (int)ScaleScreenSize.Height));
160
+                return new RectangleF(((float)rect.X) / (DpiX / 96f), ((float)rect.Y) / (DpiX / 96f), ((float)rect.Width) / (DpiX / 96f), ((float)rect.Height) / (DpiY / 96f));
161
+            }
148 162
         }
149 163
         #endregion
150 164
     }

+ 2
- 2
XHWK.WKTool/XHMicroLessonSystemWindow.xaml 파일 보기

@@ -9,7 +9,7 @@
9 9
         xmlns:local="clr-namespace:XHWK.WKTool"
10 10
         mc:Ignorable="d"
11 11
         Title="星火微课系统" Height="1036" Width="1276" 
12
-    WindowStyle="None"    AllowsTransparency="True"  Background="Transparent"    ShowInTaskbar="True" ResizeMode="CanMinimize" BorderThickness="7">
12
+    WindowStyle="None"    AllowsTransparency="True"  Background="Transparent"    ShowInTaskbar="True" ResizeMode="CanMinimize" BorderThickness="7" WindowStartupLocation="Manual" Margin="0,300,0,0">
13 13
     <Window.Effect>
14 14
         <DropShadowEffect BlurRadius="10" Color="#bababa" Direction="80" ShadowDepth="0"/>
15 15
     </Window.Effect>
@@ -255,7 +255,7 @@
255 255
                         </StackPanel>
256 256
                     </Button>
257 257
                 </StackPanel>
258
-            </Grid>
258
+                </Grid>
259 259
             <!--主内容-->
260 260
             <Grid Grid.Row="1" x:Name="GridMain" Width="1276" Visibility="Visible">
261 261
                 <ScrollViewer x:Name="scroMain" VerticalScrollBarVisibility="Visible">

+ 155
- 20
XHWK.WKTool/XHMicroLessonSystemWindow.xaml.cs 파일 보기

@@ -27,6 +27,7 @@ using System.Windows.Threading;
27 27
 using System.Diagnostics;
28 28
 using System.Runtime.InteropServices;
29 29
 using System.Windows.Controls.Primitives;
30
+using System.Linq;
30 31
 
31 32
 namespace XHWK.WKTool
32 33
 {
@@ -3371,11 +3372,29 @@ namespace XHWK.WKTool
3371 3372
             ShowAngleBorder();
3372 3373
         }
3373 3374
         System.Drawing.PointF imgRightDown;
3375
+        /// <summary>
3376
+        /// 设置控件最上层
3377
+        /// </summary>
3378
+        /// <param name="element"></param>
3379
+        public void BringToFront(Thumb element)//图片置于最顶层显示
3380
+        {
3381
+            if (element == null) return;
3382
+            
3383
+            Canvas parent = element.Parent as Canvas;
3384
+            if (parent == null) return;
3385
+            var maxZ = parent.Children.OfType<UIElement>()//linq语句,取Zindex的最大值
3386
+              .Where(x => x != element)
3387
+              .Select(x => Canvas.GetZIndex(x))
3388
+              .Max();
3389
+            Canvas.SetZIndex(element, maxZ + 1);
3390
+        }
3374 3391
         private void RectRightUp_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e)
3375 3392
         {
3376 3393
             try
3377 3394
             {
3378 3395
                 Thumb thu = (Thumb)sender;
3396
+                BringToFront(thu);
3397
+
3379 3398
                 imgRightDown = new System.Drawing.PointF((float)(imgCanvas.Margin.Left + imgCanvas.ActualWidth), (float)(imgCanvas.Margin.Top + imgCanvas.ActualHeight));
3380 3399
                 HideAngleBorder();
3381 3400
                 switch (thu.Name)
@@ -3411,36 +3430,152 @@ namespace XHWK.WKTool
3411 3430
                 double plut = Canvas.GetTop(RectLeftUp);
3412 3431
                 double prdl = Canvas.GetLeft(RectRightDown);
3413 3432
                 double prdt = Canvas.GetTop(RectRightDown);
3414
-                if (prdl - plul > 50)
3415
-                {
3416
-                }
3417
-                if (prdt - plut > 50)
3418
-                {
3419
-                }
3420 3433
                 #endregion
3421
-                
3422
-                    Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
3423
-                    Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
3434
+
3435
+                //Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
3436
+                //Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
3437
+                double imgW = 0;
3438
+                double imgH = 0;
3439
+                double imgX = 0;
3440
+                double imgY = 0;
3424 3441
                 switch (thu.Name)
3425 3442
                 {
3426 3443
                     case "RectLeftUp":
3427
-                        imgCanvas.Width = imgRightDown.X - (Mouse.GetPosition(gridM).X);
3428
-                        imgCanvas.Height = imgRightDown.Y - (Mouse.GetPosition(gridM).Y);
3429
-                        imgCanvas.Margin = new Thickness(Mouse.GetPosition(gridM).X, Mouse.GetPosition(gridM).Y, 0, 0);
3444
+                        #region 左上
3445
+                        imgW = imgRightDown.X - (Mouse.GetPosition(gridM).X);
3446
+                        imgH = imgRightDown.Y - (Mouse.GetPosition(gridM).Y);
3447
+                        imgX = 0;
3448
+                        imgY = 0;
3449
+                        if (imgW < 50)
3450
+                        {
3451
+                            imgCanvas.Width = 50;
3452
+                            imgX = imgCanvas.Margin.Left;
3453
+                            Canvas.SetLeft(thu, Canvas.GetLeft(RectRightDown) - 50);
3454
+                        }
3455
+                        else
3456
+                        {
3457
+                            imgCanvas.Width = imgW;
3458
+                            imgX = Mouse.GetPosition(gridM).X;
3459
+                            Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
3460
+                        }
3461
+                        if (imgH < 50)
3462
+                        {
3463
+                            imgCanvas.Height = 50;
3464
+                            imgY = imgCanvas.Margin.Top;
3465
+                            Canvas.SetTop(thu, Canvas.GetTop(RectRightDown) - 50);
3466
+                        }
3467
+                        else
3468
+                        {
3469
+                            imgCanvas.Height = imgH;
3470
+                            imgY = Mouse.GetPosition(gridM).Y;
3471
+                            Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
3472
+                        }
3473
+                        imgCanvas.Margin = new Thickness(imgX, imgY, 0, 0);
3474
+                        #endregion
3475
+                        //imgCanvas.Width = imgRightDown.X - (Mouse.GetPosition(gridM).X);
3476
+                        //imgCanvas.Height = imgRightDown.Y - (Mouse.GetPosition(gridM).Y);
3477
+                        //imgCanvas.Margin = new Thickness(Mouse.GetPosition(gridM).X, Mouse.GetPosition(gridM).Y, 0, 0);
3430 3478
                         break;
3431 3479
                     case "RectRightUp":
3432
-                        imgCanvas.Width = Mouse.GetPosition(gridM).X - imgCanvas.Margin.Left;
3433
-                        imgCanvas.Height = imgRightDown.Y - (Mouse.GetPosition(gridM).Y);
3434
-                        imgCanvas.Margin = new Thickness(imgCanvas.Margin.Left, Mouse.GetPosition(gridM).Y, 0, 0);
3480
+                        #region 右上
3481
+                        imgW = Mouse.GetPosition(gridM).X - imgCanvas.Margin.Left;
3482
+                        imgH = imgRightDown.Y - (Mouse.GetPosition(gridM).Y);
3483
+                        imgX = 0;
3484
+                        imgY = 0;
3485
+                        if (imgW < 50)
3486
+                        {
3487
+                            imgCanvas.Width = 50;
3488
+                            imgX = imgCanvas.Margin.Left;
3489
+                            Canvas.SetLeft(thu, Canvas.GetLeft(RectLeftUp) + 50);
3490
+                        }
3491
+                        else
3492
+                        {
3493
+                            imgCanvas.Width = imgW;
3494
+                            imgX = imgCanvas.Margin.Left;
3495
+                            Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
3496
+                        }
3497
+                        if (imgH < 50)
3498
+                        {
3499
+                            imgCanvas.Height = 50;
3500
+                            imgY = imgCanvas.Margin.Top;
3501
+                            Canvas.SetTop(thu, Canvas.GetTop(RectRightDown) - 50);
3502
+                        }
3503
+                        else
3504
+                        {
3505
+                            imgCanvas.Height = imgH;
3506
+                            imgY = Mouse.GetPosition(gridM).Y;
3507
+                            Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
3508
+                        }
3509
+                        imgCanvas.Margin = new Thickness(imgX, imgY, 0, 0);
3510
+                        //imgCanvas.Width = Mouse.GetPosition(gridM).X - imgCanvas.Margin.Left;
3511
+                        //imgCanvas.Height = imgRightDown.Y - (Mouse.GetPosition(gridM).Y);
3512
+                        //imgCanvas.Margin = new Thickness(imgCanvas.Margin.Left, Mouse.GetPosition(gridM).Y, 0, 0);
3513
+                        #endregion
3435 3514
                         break;
3436 3515
                     case "RectLeftDown":
3437
-                        imgCanvas.Width = imgRightDown.X - (Mouse.GetPosition(gridM).X);
3438
-                        imgCanvas.Height = Mouse.GetPosition(gridM).Y - imgCanvas.Margin.Top;
3439
-                        imgCanvas.Margin = new Thickness(Mouse.GetPosition(gridM).X, imgCanvas.Margin.Top, 0, 0);
3516
+                        #region 左下
3517
+                        imgW = imgRightDown.X - (Mouse.GetPosition(gridM).X);
3518
+                        imgH = Mouse.GetPosition(gridM).Y - imgCanvas.Margin.Top;
3519
+                        imgX = 0;
3520
+                        imgY = 0;
3521
+                        if (imgW < 50)
3522
+                        {
3523
+                            imgCanvas.Width = 50;
3524
+                            imgX = imgCanvas.Margin.Left;
3525
+                            Canvas.SetLeft(thu, Canvas.GetLeft(RectRightDown) - 50);
3526
+                        }
3527
+                        else
3528
+                        {
3529
+                            imgCanvas.Width = imgW;
3530
+                            imgX = Mouse.GetPosition(gridM).X;
3531
+                            Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
3532
+                        }
3533
+                        if (imgH < 50)
3534
+                        {
3535
+                            imgCanvas.Height = 50;
3536
+                            imgY = imgCanvas.Margin.Top;
3537
+                            Canvas.SetTop(thu, Canvas.GetTop(RectLeftUp) + 50);
3538
+                        }
3539
+                        else
3540
+                        {
3541
+                            imgCanvas.Height = imgH;
3542
+                            imgY = imgCanvas.Margin.Top;
3543
+                            Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
3544
+                        }
3545
+                        imgCanvas.Margin = new Thickness(imgX, imgY, 0, 0);
3546
+                        //imgCanvas.Width = imgRightDown.X - (Mouse.GetPosition(gridM).X);
3547
+                        //imgCanvas.Height = Mouse.GetPosition(gridM).Y - imgCanvas.Margin.Top;
3548
+                        //imgCanvas.Margin = new Thickness(Mouse.GetPosition(gridM).X, imgCanvas.Margin.Top, 0, 0);
3549
+                        #endregion
3440 3550
                         break;
3441 3551
                     case "RectRightDown":
3442
-                        imgCanvas.Width += e.HorizontalChange;
3443
-                        imgCanvas.Height += e.VerticalChange;
3552
+                        #region 右下
3553
+                        imgW = Mouse.GetPosition(gridM).X - imgCanvas.Margin.Left;
3554
+                        imgH = Mouse.GetPosition(gridM).Y - imgCanvas.Margin.Top;
3555
+                        if (imgW < 50)
3556
+                        {
3557
+                            imgCanvas.Width = 50;
3558
+                            Canvas.SetLeft(thu, Canvas.GetLeft(RectLeftUp) + 50);
3559
+                        }
3560
+                        else
3561
+                        {
3562
+                            imgCanvas.Width = imgW;
3563
+                            Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
3564
+                        }
3565
+                        if (imgH < 50)
3566
+                        {
3567
+                            imgCanvas.Height = 50;
3568
+                            Canvas.SetTop(thu, Canvas.GetTop(RectLeftUp) + 50);
3569
+                        }
3570
+                        else
3571
+                        {
3572
+                            imgCanvas.Height = imgH;
3573
+                            Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
3574
+                        }
3575
+                        //imgCanvas.Margin = new Thickness(imgX, imgY, 0, 0);
3576
+                        //imgCanvas.Width += e.HorizontalChange;
3577
+                        //imgCanvas.Height += e.VerticalChange;
3578
+                        #endregion
3444 3579
                         break;
3445 3580
                     default:
3446 3581
                         break;

Loading…
취소
저장