diff --git a/PacticeSolution/Capture/App.xaml b/PacticeSolution/Capture/App.xaml
new file mode 100644
index 0000000..d7e1708
--- /dev/null
+++ b/PacticeSolution/Capture/App.xaml
@@ -0,0 +1,9 @@
+
+
+
+
+
diff --git a/PacticeSolution/Capture/App.xaml.cs b/PacticeSolution/Capture/App.xaml.cs
new file mode 100644
index 0000000..cdc7039
--- /dev/null
+++ b/PacticeSolution/Capture/App.xaml.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Configuration;
+using System.Data;
+using System.Linq;
+using System.Threading.Tasks;
+using System.Windows;
+
+namespace Capture
+{
+ ///
+ /// Interaction logic for App.xaml
+ ///
+ public partial class App : Application
+ {
+ }
+}
diff --git a/PacticeSolution/Capture/AssemblyInfo.cs b/PacticeSolution/Capture/AssemblyInfo.cs
new file mode 100644
index 0000000..8b5504e
--- /dev/null
+++ b/PacticeSolution/Capture/AssemblyInfo.cs
@@ -0,0 +1,10 @@
+using System.Windows;
+
+[assembly: ThemeInfo(
+ ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
+ //(used if a resource is not found in the page,
+ // or application resource dictionaries)
+ ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
+ //(used if a resource is not found in the page,
+ // app, or any theme specific resource dictionaries)
+)]
diff --git a/PacticeSolution/Capture/Capture.csproj b/PacticeSolution/Capture/Capture.csproj
new file mode 100644
index 0000000..3cedcda
--- /dev/null
+++ b/PacticeSolution/Capture/Capture.csproj
@@ -0,0 +1,14 @@
+
+
+
+ WinExe
+ net6.0-windows
+ enable
+ true
+
+
+
+
+
+
+
diff --git a/PacticeSolution/Capture/MainWindow.xaml b/PacticeSolution/Capture/MainWindow.xaml
new file mode 100644
index 0000000..69c5d0b
--- /dev/null
+++ b/PacticeSolution/Capture/MainWindow.xaml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/PacticeSolution/Capture/MainWindow.xaml.cs b/PacticeSolution/Capture/MainWindow.xaml.cs
new file mode 100644
index 0000000..369e80b
--- /dev/null
+++ b/PacticeSolution/Capture/MainWindow.xaml.cs
@@ -0,0 +1,84 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+using System.Drawing;
+using System.Drawing.Imaging;
+using System.Diagnostics;
+using System.Security.Cryptography;
+
+namespace Capture
+{
+ ///
+ /// Interaction logic for MainWindow.xaml
+ ///
+ public partial class MainWindow : Window
+ {
+ private OptionContext _options;
+
+ public MainWindow()
+ {
+ InitializeComponent();
+ InitInstance();
+ }
+
+ private void InitInstance()
+ {
+ _options = this.DataContext as OptionContext;
+ }
+
+ private void CaptureScreen()
+ {
+ int width = (int)this.Width - _options.FrameThickness * 2;
+ int height = (int)this.Height - _options.FrameThickness * 2 - _options.ButtonHeight;
+ int left = (int)this.Left + _options.FrameThickness;
+ int top = (int)this.Top + _options.FrameThickness;
+
+ string path = @"C:\Temp\test.bmp";
+ using (Bitmap bitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
+ {
+ using (Graphics gr = Graphics.FromImage(bitmap))
+ {
+ gr.CopyFromScreen(left, top, 0, 0, bitmap.Size);
+ }
+
+ bitmap.Save(path, ImageFormat.Png);
+ }
+
+ OpenFile(path);
+ }
+
+ private void OpenFile(string path)
+ {
+ Process pr = new Process();
+ pr.StartInfo = new ProcessStartInfo(path)
+ {
+ UseShellExecute = true
+ };
+ pr.Start();
+ }
+
+ private void btnCapture_Click(object sender, RoutedEventArgs e)
+ {
+ CaptureScreen();
+ }
+
+ private void Window_MouseDown(object sender, MouseButtonEventArgs e)
+ {
+ if (e.ChangedButton != MouseButton.Left)
+ return;
+
+ this.DragMove();
+ }
+ }
+}
diff --git a/PacticeSolution/Capture/OptionContext.cs b/PacticeSolution/Capture/OptionContext.cs
new file mode 100644
index 0000000..9e4d627
--- /dev/null
+++ b/PacticeSolution/Capture/OptionContext.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Media;
+
+namespace Capture
+{
+ public class OptionContext
+ {
+ public int ButtonHeight { get; set; } = 20;
+ public Brush FrameColor { get; set; } = Brushes.Red;
+ public int FrameThickness { get; set; } = 2;
+ }
+}
diff --git a/PacticeSolution/PacticeSolution.sln b/PacticeSolution/PacticeSolution.sln
index 2251b20..ecdeea3 100644
--- a/PacticeSolution/PacticeSolution.sln
+++ b/PacticeSolution/PacticeSolution.sln
@@ -139,6 +139,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChartSample", "ChartSample\
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LiveChartPractice", "LiveChartPractice\LiveChartPractice.csproj", "{4B945CF3-2E74-46AA-8EFC-21B6434A4AC2}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPFCanvas", "WPFCanvas\WPFCanvas.csproj", "{D407D4BF-1BE7-4C02-B2A8-CF15A92793CF}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Capture", "Capture\Capture.csproj", "{08694854-976A-4551-A4CA-7BA80CFCC33C}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -417,6 +421,14 @@ Global
{4B945CF3-2E74-46AA-8EFC-21B6434A4AC2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4B945CF3-2E74-46AA-8EFC-21B6434A4AC2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4B945CF3-2E74-46AA-8EFC-21B6434A4AC2}.Release|Any CPU.Build.0 = Release|Any CPU
+ {D407D4BF-1BE7-4C02-B2A8-CF15A92793CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D407D4BF-1BE7-4C02-B2A8-CF15A92793CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {D407D4BF-1BE7-4C02-B2A8-CF15A92793CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {D407D4BF-1BE7-4C02-B2A8-CF15A92793CF}.Release|Any CPU.Build.0 = Release|Any CPU
+ {08694854-976A-4551-A4CA-7BA80CFCC33C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {08694854-976A-4551-A4CA-7BA80CFCC33C}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {08694854-976A-4551-A4CA-7BA80CFCC33C}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {08694854-976A-4551-A4CA-7BA80CFCC33C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/PacticeSolution/WPFCanvas/App.xaml b/PacticeSolution/WPFCanvas/App.xaml
new file mode 100644
index 0000000..0a19ec3
--- /dev/null
+++ b/PacticeSolution/WPFCanvas/App.xaml
@@ -0,0 +1,9 @@
+
+
+
+
+
diff --git a/PacticeSolution/WPFCanvas/App.xaml.cs b/PacticeSolution/WPFCanvas/App.xaml.cs
new file mode 100644
index 0000000..c6a52c8
--- /dev/null
+++ b/PacticeSolution/WPFCanvas/App.xaml.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Configuration;
+using System.Data;
+using System.Linq;
+using System.Threading.Tasks;
+using System.Windows;
+
+namespace WPFCanvas
+{
+ ///
+ /// Interaction logic for App.xaml
+ ///
+ public partial class App : Application
+ {
+ }
+}
diff --git a/PacticeSolution/WPFCanvas/AssemblyInfo.cs b/PacticeSolution/WPFCanvas/AssemblyInfo.cs
new file mode 100644
index 0000000..8b5504e
--- /dev/null
+++ b/PacticeSolution/WPFCanvas/AssemblyInfo.cs
@@ -0,0 +1,10 @@
+using System.Windows;
+
+[assembly: ThemeInfo(
+ ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
+ //(used if a resource is not found in the page,
+ // or application resource dictionaries)
+ ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
+ //(used if a resource is not found in the page,
+ // app, or any theme specific resource dictionaries)
+)]
diff --git a/PacticeSolution/WPFCanvas/MainWindow.xaml b/PacticeSolution/WPFCanvas/MainWindow.xaml
new file mode 100644
index 0000000..8b2355f
--- /dev/null
+++ b/PacticeSolution/WPFCanvas/MainWindow.xaml
@@ -0,0 +1,64 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/PacticeSolution/WPFCanvas/MainWindow.xaml.cs b/PacticeSolution/WPFCanvas/MainWindow.xaml.cs
new file mode 100644
index 0000000..5cd07af
--- /dev/null
+++ b/PacticeSolution/WPFCanvas/MainWindow.xaml.cs
@@ -0,0 +1,161 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace WPFCanvas
+{
+ ///
+ /// Interaction logic for MainWindow.xaml
+ ///
+ public partial class MainWindow : Window
+ {
+ private enum DrawMode
+ {
+ Line,
+ Circle,
+ Square,
+ Eraser,
+ };
+
+ private bool _mouseClicked;
+ private Point _prePosition;
+
+ private Brush _myBrush;
+ private double _thickness;
+
+ private Rectangle _tmpRect;
+
+ private DrawMode MODE;
+
+ public MainWindow()
+ {
+ InitializeComponent();
+ }
+
+ private void btnLine_Click(object sender, RoutedEventArgs e)
+ {
+ MODE = DrawMode.Line;
+ }
+
+ private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
+ {
+ _mouseClicked = true;
+ _prePosition = e.GetPosition(canvas);
+ }
+
+ private void Window_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
+ {
+ _mouseClicked = false;
+ }
+
+ private void Window_MouseMove(object sender, MouseEventArgs e)
+ {
+ Point nowPosition = e.GetPosition(canvas);
+ if (!_mouseClicked)
+ return;
+
+ switch (MODE)
+ {
+ case DrawMode.Line:
+ Line line = new Line()
+ {
+ X1 = _prePosition.X,
+ Y1 = _prePosition.Y,
+ X2 = nowPosition.X,
+ Y2 = nowPosition.Y,
+ Stroke = _myBrush == null ? Brushes.Black : _myBrush,
+ StrokeThickness = _thickness <= 0 ? 1 : _thickness
+ };
+ canvas.Children.Add(line);
+
+ _prePosition = nowPosition;
+ break;
+ case DrawMode.Square:
+ if (e.MouseDevice.LeftButton != MouseButtonState.Pressed)
+ _tmpRect = null;
+ else
+ {
+ Rectangle rect = new Rectangle();
+ rect.Stroke = Brushes.Gray;
+ rect.Fill = _myBrush == null ? Brushes.Black : _myBrush;
+ rect.Opacity = 0.8;
+
+ double left = _prePosition.X;
+ double top = _prePosition.Y;
+
+ double width = nowPosition.X - _prePosition.X;
+ double height = nowPosition.Y - _prePosition.Y;
+
+ if (nowPosition.X < _prePosition.X)
+ {
+ left = nowPosition.X;
+ width *= -1;
+ }
+
+ if (nowPosition.Y < _prePosition.Y)
+ {
+ top = nowPosition.Y;
+ height *= -1;
+ }
+
+ rect.Margin = new Thickness(left, top, 0, 0);
+ rect.Width = width;
+ rect.Height = height;
+
+ canvas.Children.Remove(_tmpRect);
+ _tmpRect = rect;
+ canvas.Children.Add(rect);
+ }
+ break;
+ }
+
+
+ }
+
+ private void btnBlack_Click(object sender, RoutedEventArgs e)
+ {
+ _myBrush = Brushes.Black;
+ }
+
+ private void btnRed_Click(object sender, RoutedEventArgs e)
+ {
+ _myBrush = Brushes.Red;
+ }
+
+ private void btnBlue_Click(object sender, RoutedEventArgs e)
+ {
+ _myBrush = Brushes.Blue;
+ }
+
+ private void btnGreen_Click(object sender, RoutedEventArgs e)
+ {
+ _myBrush = Brushes.Green;
+ }
+
+ private void btnYellow_Click(object sender, RoutedEventArgs e)
+ {
+ _myBrush = Brushes.Yellow;
+ }
+
+ private void cboThickness_SelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ _thickness = double.Parse(cboThickness.SelectedValue.ToString());
+ }
+
+ private void btnSquare_Click(object sender, RoutedEventArgs e)
+ {
+ MODE = DrawMode.Square;
+ }
+ }
+}
diff --git a/PacticeSolution/WPFCanvas/WPFCanvas.csproj b/PacticeSolution/WPFCanvas/WPFCanvas.csproj
new file mode 100644
index 0000000..4106cb0
--- /dev/null
+++ b/PacticeSolution/WPFCanvas/WPFCanvas.csproj
@@ -0,0 +1,10 @@
+
+
+
+ WinExe
+ net6.0-windows
+ enable
+ true
+
+
+