From 4113f9d81489a09c1d4a79d240db5afbbca757e0 Mon Sep 17 00:00:00 2001
From: NaBian <836904362@qq.com>
Date: Sat, 7 Mar 2020 21:58:46 +0800
Subject: [PATCH] add Screenshot Demo
---
.../HandyControlDemo_Core_GE30.csproj | 3 +
.../HandyControlDemo_Net_40.csproj | 3 +
.../HandyControlDemo_Net_GE45.csproj | 3 +
.../HandyControlDemo_Code.csproj | 7 +++
.../Data/DemoInfo.json | 3 +-
.../HandyControlDemo_Shared.projitems | 7 +++
.../Properties/Langs/Lang.Designer.cs | 27 ++++++---
.../Properties/Langs/Lang.en.resx | 6 ++
.../Properties/Langs/Lang.fa.resx | 6 ++
.../Properties/Langs/Lang.fr.resx | 6 ++
.../Properties/Langs/Lang.ko-KR.resx | 6 ++
.../Properties/Langs/Lang.resx | 6 ++
.../LeftMainContent/WindowScreenshot_16x.png | Bin 0 -> 207 bytes
.../Controls/ScreenshotDemoCtl.xaml | 10 ++++
.../Controls/ScreenshotDemoCtl.xaml.cs | 33 +++++++++++
.../UserControl/Main/MainContent.xaml | 2 +-
.../Controls/Screenshot/Screenshot.cs | 7 +--
.../Controls/Screenshot/ScreenshotWindow.cs | 56 ++++++++++--------
.../HandyControl_Shared.projitems | 1 +
.../Interactivity/Commands/ControlCommands.cs | 5 ++
.../Commands/ScreenshotCommand.cs | 15 +++++
.../Commands/StartScreenshotCommand.cs | 15 +++++
.../Tools/Helper/WindowHelper.cs | 1 +
23 files changed, 187 insertions(+), 41 deletions(-)
create mode 100644 src/Shared/HandyControlDemo_Shared/Resources/Img/LeftMainContent/WindowScreenshot_16x.png
create mode 100644 src/Shared/HandyControlDemo_Shared/UserControl/Controls/ScreenshotDemoCtl.xaml
create mode 100644 src/Shared/HandyControlDemo_Shared/UserControl/Controls/ScreenshotDemoCtl.xaml.cs
create mode 100644 src/Shared/HandyControl_Shared/Interactivity/Commands/ScreenshotCommand.cs
create mode 100644 src/Shared/HandyControl_Shared/Interactivity/Commands/StartScreenshotCommand.cs
diff --git a/src/Core_GE30/HandyControlDemo_Core_GE30/HandyControlDemo_Core_GE30.csproj b/src/Core_GE30/HandyControlDemo_Core_GE30/HandyControlDemo_Core_GE30.csproj
index 75007053..a599d3eb 100644
--- a/src/Core_GE30/HandyControlDemo_Core_GE30/HandyControlDemo_Core_GE30.csproj
+++ b/src/Core_GE30/HandyControlDemo_Core_GE30/HandyControlDemo_Core_GE30.csproj
@@ -480,6 +480,9 @@
Resources\Img\cloud.png
+
+ Resources\Img\LeftMainContent\WindowScreenshot_16x.png
+
diff --git a/src/Net_40/HandyControlDemo_Net_40/HandyControlDemo_Net_40.csproj b/src/Net_40/HandyControlDemo_Net_40/HandyControlDemo_Net_40.csproj
index 50bbc0a2..0efba4ca 100644
--- a/src/Net_40/HandyControlDemo_Net_40/HandyControlDemo_Net_40.csproj
+++ b/src/Net_40/HandyControlDemo_Net_40/HandyControlDemo_Net_40.csproj
@@ -547,6 +547,9 @@
Resources\Img\cloud.png
+
+ Resources\Img\LeftMainContent\WindowScreenshot_16x.png
+
diff --git a/src/Net_GE45/HandyControlDemo_Net_GE45/HandyControlDemo_Net_GE45.csproj b/src/Net_GE45/HandyControlDemo_Net_GE45/HandyControlDemo_Net_GE45.csproj
index abe74897..0dae1c8d 100644
--- a/src/Net_GE45/HandyControlDemo_Net_GE45/HandyControlDemo_Net_GE45.csproj
+++ b/src/Net_GE45/HandyControlDemo_Net_GE45/HandyControlDemo_Net_GE45.csproj
@@ -610,6 +610,9 @@
Resources\Img\cloud.png
+
+ Resources\Img\LeftMainContent\WindowScreenshot_16x.png
+
diff --git a/src/Shared/HandyControlDemo_Code/HandyControlDemo_Code.csproj b/src/Shared/HandyControlDemo_Code/HandyControlDemo_Code.csproj
index db149ee9..d307144e 100644
--- a/src/Shared/HandyControlDemo_Code/HandyControlDemo_Code.csproj
+++ b/src/Shared/HandyControlDemo_Code/HandyControlDemo_Code.csproj
@@ -317,6 +317,9 @@
UserControl\Controls\RunningBlockDemoCtl.xaml
+
+ UserControl\Controls\ScreenshotDemoCtl.xaml
+
UserControl\Controls\ScrollViewerDemoCtl.xaml
@@ -713,6 +716,10 @@
UserControl\Controls\RunningBlockDemoCtl.xaml.cs
RunningBlockDemoCtl.xaml
+
+ UserControl\Controls\ScreenshotDemoCtl.xaml.cs
+ ScreenshotDemoCtl.xaml
+
UserControl\Controls\ScrollViewerDemoCtl.xaml.cs
ScrollViewerDemoCtl.xaml
diff --git a/src/Shared/HandyControlDemo_Shared/Data/DemoInfo.json b/src/Shared/HandyControlDemo_Shared/Data/DemoInfo.json
index c849557e..69a6b1da 100644
--- a/src/Shared/HandyControlDemo_Shared/Data/DemoInfo.json
+++ b/src/Shared/HandyControlDemo_Shared/Data/DemoInfo.json
@@ -98,6 +98,7 @@
[ "Sprite", "SpriteDemoCtl", "HandyControl", "" ],
[ "Notification", "NotificationDemoCtl", "Procedure_16x", "" ],
[ "Dialog", "DialogDemoCtl", "Dialog_16x", "" ],
+ [ "Screenshot", "ScreenshotDemoCtl", "WindowScreenshot_16x", "1" ],
[ "Window", "WindowDemoCtl", "WindowsForm_16x", "1" ]
]
},
@@ -106,7 +107,7 @@
"demoItemList": [
[ "HatchBrushGenerator", "HatchBrushGeneratorDemoCtl", "DataGenerator_16x", "" ],
[ "Morphing Animation", "GeometryAnimationDemoCtl", "Animation_16x", "" ],
- [ "Effects", "EffectsDemoCtl", "Effects_16x", "1" ]
+ [ "Effects", "EffectsDemoCtl", "Effects_16x", "" ]
]
}
]
\ No newline at end of file
diff --git a/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems b/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems
index ef1f20e3..9bb9f927 100644
--- a/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems
+++ b/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems
@@ -190,6 +190,9 @@
RunningBlockDemoCtl.xaml
+
+ ScreenshotDemoCtl.xaml
+
ScrollViewerDemoCtl.xaml
@@ -684,6 +687,10 @@
Designer
MSBuild:Compile
+
+ Designer
+ MSBuild:Compile
+
Designer
MSBuild:Compile
diff --git a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.Designer.cs b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.Designer.cs
index bd30d1fd..e3078682 100644
--- a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.Designer.cs
+++ b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.Designer.cs
@@ -1176,15 +1176,6 @@ namespace HandyControlDemo.Properties.Langs {
}
}
- ///
- /// 查找类似 概览 的本地化字符串。
- ///
- public static string Overview {
- get {
- return ResourceManager.GetString("Overview", resourceCulture);
- }
- }
-
///
/// 查找类似 页码条 的本地化字符串。
///
@@ -1491,6 +1482,15 @@ namespace HandyControlDemo.Properties.Langs {
}
}
+ ///
+ /// 查找类似 截图 的本地化字符串。
+ ///
+ public static string Screenshot {
+ get {
+ return ResourceManager.GetString("Screenshot", resourceCulture);
+ }
+ }
+
///
/// 查找类似 滚动视图 的本地化字符串。
///
@@ -1608,6 +1608,15 @@ namespace HandyControlDemo.Properties.Langs {
}
}
+ ///
+ /// 查找类似 开始截图 的本地化字符串。
+ ///
+ public static string StartScreenshot {
+ get {
+ return ResourceManager.GetString("StartScreenshot", resourceCulture);
+ }
+ }
+
///
/// 查找类似 保持打开 的本地化字符串。
///
diff --git a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.en.resx b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.en.resx
index 24edac67..97bad55c 100644
--- a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.en.resx
+++ b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.en.resx
@@ -738,4 +738,10 @@
Practical demos
+
+ Start screenshot
+
+
+ Screenshot
+
\ No newline at end of file
diff --git a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.fa.resx b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.fa.resx
index 73fd70c6..b1d3c4fe 100644
--- a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.fa.resx
+++ b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.fa.resx
@@ -738,4 +738,10 @@
Practical demos
+
+ Start screenshot
+
+
+ Screenshot
+
\ No newline at end of file
diff --git a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.fr.resx b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.fr.resx
index c8051c46..3c22a942 100644
--- a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.fr.resx
+++ b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.fr.resx
@@ -738,4 +738,10 @@
Practical demos
+
+ Start screenshot
+
+
+ Screenshot
+
\ No newline at end of file
diff --git a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.ko-KR.resx b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.ko-KR.resx
index 9715066f..88562ce8 100644
--- a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.ko-KR.resx
+++ b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.ko-KR.resx
@@ -738,4 +738,10 @@
Practical demos
+
+ Start screenshot
+
+
+ Screenshot
+
\ No newline at end of file
diff --git a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.resx b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.resx
index a64229fb..f4e63998 100644
--- a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.resx
+++ b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.resx
@@ -738,4 +738,10 @@
实用例子
+
+ 开始截图
+
+
+ 截图
+
\ No newline at end of file
diff --git a/src/Shared/HandyControlDemo_Shared/Resources/Img/LeftMainContent/WindowScreenshot_16x.png b/src/Shared/HandyControlDemo_Shared/Resources/Img/LeftMainContent/WindowScreenshot_16x.png
new file mode 100644
index 0000000000000000000000000000000000000000..45e78d9f63fd79f1c7e9350a758b47cd7c64cb29
GIT binary patch
literal 207
zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`oCO|{#S9F5he4R}c>anMpkSk?
zi(^Pd+}Vi-IS(iZumlHXZI~a?W~-7LF@w|c+w6jV(RYPKC%qFNw%imfeaQ6TPp9CL
zDf?2w4&GenktTX2>i72(x`vG%YZzwbd1=-t%+-|Q-g0J*n`gEYW=YHNGZfPOqo@?+l=07(8A5T-G@yGywoC
C^h`eh
literal 0
HcmV?d00001
diff --git a/src/Shared/HandyControlDemo_Shared/UserControl/Controls/ScreenshotDemoCtl.xaml b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/ScreenshotDemoCtl.xaml
new file mode 100644
index 00000000..85767c53
--- /dev/null
+++ b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/ScreenshotDemoCtl.xaml
@@ -0,0 +1,10 @@
+
+
+
+
+
diff --git a/src/Shared/HandyControlDemo_Shared/UserControl/Controls/ScreenshotDemoCtl.xaml.cs b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/ScreenshotDemoCtl.xaml.cs
new file mode 100644
index 00000000..7f237020
--- /dev/null
+++ b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/ScreenshotDemoCtl.xaml.cs
@@ -0,0 +1,33 @@
+using System;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Media;
+using HandyControl.Controls;
+using HandyControl.Data;
+
+namespace HandyControlDemo.UserControl
+{
+ public partial class ScreenshotDemoCtl : IDisposable
+ {
+ public ScreenshotDemoCtl()
+ {
+ InitializeComponent();
+ Screenshot.Snapped += Screenshot_Snapped;
+ }
+
+ private void Screenshot_Snapped(object sender, FunctionEventArgs e)
+ {
+ new HandyControl.Controls.Window
+ {
+ Content = new Image
+ {
+ Source = e.Info,
+ Stretch = Stretch.None
+ },
+ WindowStartupLocation = WindowStartupLocation.CenterScreen
+ }.ShowDialog();
+ }
+
+ public void Dispose() => Screenshot.Snapped -= Screenshot_Snapped;
+ }
+}
diff --git a/src/Shared/HandyControlDemo_Shared/UserControl/Main/MainContent.xaml b/src/Shared/HandyControlDemo_Shared/UserControl/Main/MainContent.xaml
index e016d2fe..e4bacd27 100644
--- a/src/Shared/HandyControlDemo_Shared/UserControl/Main/MainContent.xaml
+++ b/src/Shared/HandyControlDemo_Shared/UserControl/Main/MainContent.xaml
@@ -3,7 +3,7 @@
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:avalonedit="http://icsharpcode.net/sharpdevelop/avalonedit"
x:Class="HandyControlDemo.UserControl.MainContent">
-
+
diff --git a/src/Shared/HandyControl_Shared/Controls/Screenshot/Screenshot.cs b/src/Shared/HandyControl_Shared/Controls/Screenshot/Screenshot.cs
index ba219ac4..887db21f 100644
--- a/src/Shared/HandyControl_Shared/Controls/Screenshot/Screenshot.cs
+++ b/src/Shared/HandyControl_Shared/Controls/Screenshot/Screenshot.cs
@@ -1,16 +1,15 @@
using System;
using System.Windows.Media;
+using HandyControl.Data;
namespace HandyControl.Controls
{
public class Screenshot
{
- public event EventHandler Snapped;
-
- public ImageSource Source { get; set; }
+ public static event EventHandler> Snapped;
public void Start() => new ScreenshotWindow(this).Show();
- internal void OnSnapped() => Snapped?.Invoke(this, EventArgs.Empty);
+ internal void OnSnapped(ImageSource source) => Snapped?.Invoke(this, new FunctionEventArgs(source));
}
}
diff --git a/src/Shared/HandyControl_Shared/Controls/Screenshot/ScreenshotWindow.cs b/src/Shared/HandyControl_Shared/Controls/Screenshot/ScreenshotWindow.cs
index 27d665c5..9af41e93 100644
--- a/src/Shared/HandyControl_Shared/Controls/Screenshot/ScreenshotWindow.cs
+++ b/src/Shared/HandyControl_Shared/Controls/Screenshot/ScreenshotWindow.cs
@@ -26,8 +26,6 @@ namespace HandyControl.Controls
#region const
- private const int RectMinLength = 14;
-
private const int IntervalLength = 1;
private const int IntervalBigLength = 10;
@@ -60,6 +58,8 @@ namespace HandyControl.Controls
private Point _mousePointOld;
+ private bool _saveScreenshot;
+
#endregion
#endregion
@@ -177,7 +177,8 @@ namespace HandyControl.Controls
}
break;
case Key.Enter:
- SaveScreenshot();
+ _saveScreenshot = true;
+ Close();
break;
}
}
@@ -185,7 +186,11 @@ namespace HandyControl.Controls
protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e) => _mousePointOld = e.GetPosition(this);
- protected override void OnPreviewMouseDoubleClick(MouseButtonEventArgs e) => SaveScreenshot();
+ protected override void OnPreviewMouseDoubleClick(MouseButtonEventArgs e)
+ {
+ _saveScreenshot = true;
+ Close();
+ }
protected override void OnPreviewMouseMove(MouseEventArgs e)
{
@@ -282,6 +287,11 @@ namespace HandyControl.Controls
private void ScreenshotWindow_Closed(object sender, EventArgs e)
{
+ if (_saveScreenshot)
+ {
+ SaveScreenshot();
+ }
+
StopHooks();
IsDrawing = false;
@@ -442,10 +452,9 @@ namespace HandyControl.Controls
if (Canvas.Background is ImageBrush imageBrush && imageBrush.ImageSource is BitmapSource bitmapSource)
{
var cb = new CroppedBitmap(bitmapSource, new Int32Rect(_targetWindowRect.Left, _targetWindowRect.Top, _targetWindowRect.Width, _targetWindowRect.Height));
- _screenshot.Source = cb;
+ _screenshot.OnSnapped(cb);
}
- _screenshot.OnSnapped();
Close();
}
@@ -488,7 +497,21 @@ namespace HandyControl.Controls
}
}
- private void RegularRect(ref InteropValues.RECT rect)
+ private static InteropValues.RECT MoveRect(InteropValues.RECT rect, int leftFlag = 0, int topFlag = 0, int rightFlag = 0, int bottomFlag = 0)
+ {
+ var moveLength = Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)
+ ? IntervalBigLength
+ : IntervalLength;
+
+ rect.Left += leftFlag * moveLength;
+ rect.Top += topFlag * moveLength;
+ rect.Right += rightFlag * moveLength;
+ rect.Bottom += bottomFlag * moveLength;
+
+ return rect;
+ }
+
+ private void MoveTargetArea(InteropValues.RECT rect)
{
if (rect.Left < 0)
{
@@ -516,25 +539,6 @@ namespace HandyControl.Controls
rect.Left = Math.Max(0, rect.Left);
rect.Top = Math.Max(0, rect.Top);
- }
-
- private static InteropValues.RECT MoveRect(InteropValues.RECT rect, int leftFlag = 0, int topFlag = 0, int rightFlag = 0, int bottomFlag = 0)
- {
- var moveLength = Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)
- ? IntervalBigLength
- : IntervalLength;
-
- rect.Left += leftFlag * moveLength;
- rect.Top += topFlag * moveLength;
- rect.Right += rightFlag * moveLength;
- rect.Bottom += bottomFlag * moveLength;
-
- return rect;
- }
-
- private void MoveTargetArea(InteropValues.RECT rect)
- {
- RegularRect(ref rect);
var width = rect.Width;
var height = rect.Height;
diff --git a/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems b/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems
index 726a31f5..a78fba08 100644
--- a/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems
+++ b/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems
@@ -61,6 +61,7 @@
+
diff --git a/src/Shared/HandyControl_Shared/Interactivity/Commands/ControlCommands.cs b/src/Shared/HandyControl_Shared/Interactivity/Commands/ControlCommands.cs
index 07c58353..770de7f2 100644
--- a/src/Shared/HandyControl_Shared/Interactivity/Commands/ControlCommands.cs
+++ b/src/Shared/HandyControl_Shared/Interactivity/Commands/ControlCommands.cs
@@ -161,5 +161,10 @@ namespace HandyControl.Interactivity
/// 关闭窗口
///
public static CloseWindowCommand CloseWindow { get; } = new CloseWindowCommand();
+
+ ///
+ /// 开始截图
+ ///
+ public static StartScreenshotCommand StartScreenshot { get; } = new StartScreenshotCommand();
}
}
\ No newline at end of file
diff --git a/src/Shared/HandyControl_Shared/Interactivity/Commands/ScreenshotCommand.cs b/src/Shared/HandyControl_Shared/Interactivity/Commands/ScreenshotCommand.cs
new file mode 100644
index 00000000..cefef4f4
--- /dev/null
+++ b/src/Shared/HandyControl_Shared/Interactivity/Commands/ScreenshotCommand.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Windows.Input;
+using HandyControl.Controls;
+
+namespace HandyControl.Interactivity
+{
+ public class StartScreenshotCommand : ICommand
+ {
+ public bool CanExecute(object parameter) => true;
+
+ public void Execute(object parameter) => new Screenshot().Start();
+
+ public event EventHandler CanExecuteChanged;
+ }
+}
diff --git a/src/Shared/HandyControl_Shared/Interactivity/Commands/StartScreenshotCommand.cs b/src/Shared/HandyControl_Shared/Interactivity/Commands/StartScreenshotCommand.cs
new file mode 100644
index 00000000..cefef4f4
--- /dev/null
+++ b/src/Shared/HandyControl_Shared/Interactivity/Commands/StartScreenshotCommand.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Windows.Input;
+using HandyControl.Controls;
+
+namespace HandyControl.Interactivity
+{
+ public class StartScreenshotCommand : ICommand
+ {
+ public bool CanExecute(object parameter) => true;
+
+ public void Execute(object parameter) => new Screenshot().Start();
+
+ public event EventHandler CanExecuteChanged;
+ }
+}
diff --git a/src/Shared/HandyControl_Shared/Tools/Helper/WindowHelper.cs b/src/Shared/HandyControl_Shared/Tools/Helper/WindowHelper.cs
index b9682b70..23f73766 100644
--- a/src/Shared/HandyControl_Shared/Tools/Helper/WindowHelper.cs
+++ b/src/Shared/HandyControl_Shared/Tools/Helper/WindowHelper.cs
@@ -6,6 +6,7 @@ using System.Runtime.InteropServices;
using System.Security;
using System.Windows;
using System.Windows.Interop;
+using HandyControl.Tools.Extension;
using HandyControl.Tools.Interop;
namespace HandyControl.Tools