1

I have a custom WinForms control that displays some graphics. I need to overlay an InkCanvas on top of this control. The InkCanvas should be "see through" (transparent background, visible ink). This InkCanvas allows the user to sketch on the graphics being displayed.

I know about the airspace issue in WPF/WinForms interop (the fact that WinForms elements hosted in a WPF window will always stay on top of all other components). So obviously I cannot achieve the desired effects in WPF. I decided to go about the problem the other way around (host an InkCanvas in a WinForms form and overlay the InkCanvas on my custom control).

The problem is that the WinForms ElementHost cannot be made "see through" (no transparency can be set). I tried deriving ElementHost with the following override

protected override CreateParams CreateParams
{
    get
    {
        const int WS_EX_TRANSPARENT = 0x20;
        CreateParams cp = base.CreateParams;
        cp.ExStyle = cp.ExStyle | WS_EX_TRANSPARENT;
        return cp;
    }
}

But this will make the whole thing completely transparent (the sketches are not visible any more).

How can I have the "see through" InkCanvas with visible ink overlayed on the WinForms control?

Maghoumi
  • 3,295
  • 3
  • 33
  • 49
  • 1
    I don't think you can do this due to the "airspace" problem. Here's a resource on the subject, not sure if it applies completely to your problem... http://blogs.msdn.com/b/dwayneneed/archive/2013/02/26/mitigating-airspace-issues-in-wpf-applications.aspx –  May 28 '15 at 18:08
  • 1
    ElementHost *creates* an "airspace", it cannot remove one. Only way ahead is to layer another transparent borderless window on top of the one you have. – Hans Passant May 28 '15 at 19:09
  • Thank you both. I see... If that's the case, then I will consider creating my own InkCanvas in the graphics viewer user control... – Maghoumi May 29 '15 at 00:00

1 Answers1

0

Based on the comments and lack of answers, we can safely assume that what I want to do is impossible unless we do the "window layering" hack that @Hans Passant mentioned.

Maghoumi
  • 3,295
  • 3
  • 33
  • 49