I am working on feedback form. When it's opened - user can check the flag to take screenshot of the screen. The problem is, that screenshot is taken with feedback form, and I need to capture screen without it.
I've found some code to take screenshot. It works. To solve this, I've tried to make this form invisible or closed during taking screenshot. Also, I've set it's opacity to 0 and height to 0. I think taking screenshot operation is too fast, so visually, the form cannot be hidden in such period of time.
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;
}
EDIT: The form expands by Opacity of Border, used as toggle, the form is content of Border(opacity == 0(1) -> height = 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 here is used for triggering animation using command(that's because Height property cannot be binded). But that is working, so it doesn't matter.
Even if I do not set the MagicOpacity to 1 after taking screenshot, the form - is in the picture.
So the question is that is it possible to take screenshot of window without top-most window?