• 【Windows 10 应用开发】如何防止应用程序被截屏


    今天老周只想跟大伙们分享一个小技巧,是的,小小的技巧,很简单,保证你能学会的,要是学不会,可以考虑跳泰山。

    有些时候,我们可能会想到不要让应用程序界面上显示的内容被截屏,要阻止应用界面呈现在截图上,可以在 ApplicationView 类上找答案,因为这个行为是跟应用程序视图有直接关系的。

    我们只需要设置一个属性就成了——IsScreenCaptureEnabled,如果允许程序被捕捉到,就设置为 true,要禁止被捕捉,设置为 false 就好了。简单吧。

    看一个例子,先看XAML布局。

            <Grid Margin="15">
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto"/>
                    <RowDefinition/>
                    <RowDefinition Height="auto"/>
                </Grid.RowDefinitions>
                <TextBlock Text="中国高富帅的形象代表" FontSize="25" HorizontalAlignment="Center" Margin="0,6"/>
                <Image Grid.Row="1" Margin="3" Source="Assets1.png" />
                <CheckBox Grid.Row="2" Margin="0,8" Content="禁止被截屏" FontSize="18" HorizontalAlignment="Center" Checked="OnChecked" Unchecked="OnUnChecked"/>
            </Grid>

    重点是 CheckBox 控件,我处理了它的 Checked 和 UnChecked 事件,如果它被选中,就禁止应用界面被捕捉;如果没选中,就允许捕捉。

    下面是实现代码。

            ApplicationView appView = ApplicationView.GetForCurrentView();
            private void OnChecked(object sender, RoutedEventArgs e)
            {
                appView.IsScreenCaptureEnabled = false;
            }
    
            private void OnUnChecked(object sender, RoutedEventArgs e)
            {
                appView.IsScreenCaptureEnabled = true;
            }

    来,看看效果。首先,CheckBox 是没选中的,即允许截屏,这时候截取到的超清无水印图片如下。

    然后,我们选上 CheckBox 控件,再截屏,得到的是一片黑乎乎的东西。

    这个示例很简单,我就不提供源代码了,大家完全可以自己动手的。

  • 相关阅读:
    js string format All In One
    CSS water wave effect All In One
    Github PR 时合并多次提交的 git commits All In One
    js auto selector dom by providing id All In One
    JSS All In One
    python 中将fastq文件保存为字典
    python 中统计fasta文件中每条序列的长度
    c语言中利用do while循环语句限制用户的输入范围
    python中记录程序运行时间
    c语言中的do while循环语句
  • 原文地址:https://www.cnblogs.com/tcjiaan/p/6950026.html
Copyright © 2020-2023  润新知