在.NET平台上,使用Windows Presentation Foundation(WPF)可以方便地实现屏幕截图功能。本文将介绍如何使用WPF和C#编程语言来实现屏幕截图,并提供相应的源代码。
首先,我们需要创建一个WPF应用程序,并在主窗口中添加一个按钮,用于触发屏幕截图操作。以下是XAML代码示例:
<Window x:Class="ScreenCaptureApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="屏幕截图示例" Height="350" Width="525">
<Grid>
<Button Content="截图" HorizontalAlignment="Center" VerticalAlignment="Center" Click="CaptureScreen_Click"/>
</Grid>
</Window>