0

I made a shadow window with this code

<Grid Background="Red" Margin="0">
    <Grid.Effect>
        <DropShadowEffect BlurRadius="10" ShadowDepth="1" Direction="270" Color="Red"/>
    </Grid.Effect>
    <Grid Margin="1" Background="White">

    </Grid>
</Grid>

Result is successful, but when i try to capture windows screenshot with alt+print scr there was a blank margin like this.

first http://puu.sh/9rK9b/4dbd9a3b46.png

I want to capture screen only inside grid area except shadow area like this.

second http://puu.sh/9rKcj/098796a6c7.png

  • You have to choose one of two: either nice looking and easy to make shadow *inside* window or `ALT`-`PRNSCR` (which takes snapshot from *inside* as well). I believe it's possible to draw shadow outside of window, but that would be some winapi/aero interops. See, to example, [here](http://stackoverflow.com/a/6313576/1997232). – Sinatr Jun 13 '14 at 15:14

1 Answers1

1

You need to replicate the functionality of alt+print scr by hand to get the behaviour you need.

First of all you need to hook into the message loop and intercept the press along these lines:

ComponentDispatcher.ThreadFilterMessage += new ThreadMessageEventHandler(OnThreadMessage);

static void OnThreadMessage(ref MSG msg, ref bool handled)
{
    if (!handled)
    {
        if (msg.message == WmHotKey)
        {
            // intercept alt+print screen here, do custom action
        }
    }
}

Then you need to generate the image you want from the ui element and set it to the clipboard along these lines (uiElement will be your Grid):

var bmp = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Pbgra32);
bmp.Render(uiElement);
encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bmp));
using (var stream = new MemoryStream)
{
    encoder.Save(stream);
    var img = Image.FromStream(stream);
    Clipboard.SetImage(img);
}
MrDosu
  • 3,427
  • 15
  • 18