我正在处理反馈表。打开时-用户可以检查该标志以截取屏幕截图。问题是,屏幕截图是通过反馈表获取的,我需要在没有屏幕截图的情况下捕获屏幕。
我找到了一些截图代码。有用。为了解决这个问题,我尝试在截屏时使该表单不可见或关闭。另外,我将不透明度设置为0,高度设置为0。我认为进行屏幕截图操作太快了,因此从视觉上看,表单不能在这样的时间内被隐藏。
public void TakeScreenshot()
{
double screenLeft = SystemParameters.VirtualScreenLeft;
double screenTop = SystemParameters.VirtualScreenTop;
double screenWidth = SystemParameters.VirtualScreenWidth;
double screenHeight = SystemParameters.VirtualScreenHeight;
using (Bitmap bmp = new Bitmap((int)screenWidth, (int)screenHeight))
{
using (Graphics g = Graphics.FromImage(bmp))
{
g.CopyFromScreen((int)screenLeft, (int)screenTop, 0, 0, bmp.Size);
bmp.Save(@"D:\printscreen.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
}
}
}
public void SendMessage()
{
MagicOpacity = 0;
MailAddress from = new MailAddress(Mail, CurrentUser.Name);
MailAddress to = new MailAddress("a@mail.com");
MailMessage message = new MailMessage(from, to);
if (SendWithScreenshot)
{
TakeScreenshot();
message.Attachments.Add(new Attachment("D:\\printscreen.jpg"));
}
MagicOpacity = 1;
}
编辑:表格以“边框的不透明度”展开,用作切换,该表格是Border的内容(不透明度== 0(1)->高度= 0(500))
public void ExpandFeedBackForm()
{
MagicOpacity = MagicOpacity == 0 ? 1 : 0;
}
<Canvas>
<Button Name="FeedBackButton" Command="{Binding ExpandFeedBackFormCommand}" FontWeight="Bold" FontSize="10" Height="18.5" Margin="-3,-8,0,0"/>
<Border BorderBrush="Gray" BorderThickness="2" Opacity="{Binding MagicOpacity}" Name="border" Margin="-350,0,-178,-9" Background="White"
Canvas.Bottom="{Binding ElementName=FeedBackButton, Path=ActualHeight}">
<Border.Style>
<Style TargetType="Border">
<Style.Triggers>
<Trigger Property="Opacity" Value="1">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Height" From="0" To="500" Duration="0:0:0.4"/>
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
</Trigger>
</Style.Triggers>
</Style>
</Border.Style>
<v:FeedBackView/>
</Border>
</Canvas>
此处的MagicOpacity用于通过命令触发动画(这是因为不能绑定Height属性)。但这有效,所以没关系。
即使在截图后我没有将MagicOpacity设置为1,表单-也在图片中。
所以问题是,可以截取没有最顶部窗口的窗口的屏幕截图吗?