I have a rather tricky one (at least for me), which I have spent a lot of time trying to figure out. I have a C# winform application. In the application I need to present multiple web pages on top of each other with a transparent color allowing me to stack the web pages on top of each other. I can easily do that by letting the web page have no back color specified and then placing the WebBrowser control on a seperate WinForm with a TransparentcyKey and BackgroundColor set to e.g. white. When I open multiple forms they will behave transparent and I get the required effect.
Having heaps of forms like that open is in my opinion quite messy as what I just want is something more control like. My idea is therefore to either put it into a UserControl and add the necessary logic in there or simply inherit and override functionality in the Webbrowser. The UserControl does however not expose any transparency key like the form so initially this is a dead end. Overriding the WndProc in the UserControl to handle the paint myself seems to have no effect. It is like the WebBrowser is not really accessible for anything, which I guess has something to do with the fact that it is just the wrapped ActiveX.
In case it is not possible to have a derived WeBrow开发者_开发问答ser or a UserControl with a WebBrowser in it does anyone have any suggestions on how I could handle the forms in a nie way so that they act like user controls regarding clipping when placing them on top of a "mother" form?
Best Ragards Franz Thomsen
The webbrowser control erases its background using the background color specified in Internet Options. To blend it with another window's image you need to use layers (SetLayeredWindowAttributes/ UpdateLayeredWindow).
However layers does not work with child windows (in this case the WebBrowser control). To make it to another layer you need to create an owned top-level window, positioned exactly on the same place over your place holder control on your main window. You'll have to keep moving it and possibly resizing it as the place holder control is moved /resized. Having an owner will make sure it gets automatically minimized and destroyed with the application’s main window. And you need to make it looks like a child window, that is, borderless and ShowInTaskbar=false.
See http://blogs.msdn.com/changov/archive/2009/01/19/webbrowser-control-on-transparent-wpf-window.aspx for a discussion.
If your web page contains those hardware-accelerated ActiveX/DirectX transitions and filters that write to screen directly instead of participating IE window drawing process, you may be out of luck.
精彩评论