Solution to compatibility between irregular forms and WebBrowser controls in WPF

Source: Internet
Author: User

Introduction

In the past few days, I was commissioned to develop an online TV project, requiring that you first use embedded web pages to play videos and menus, and then consider integrating all functions of the web pages into the desktop program.

Generally, players have a cool look, so I designed an irregular shape with a transparent border, such:

However, this design was integrated into WPF, but encountered a headache BUG:

As long as the form is set to AllowsTransparency = "True" WindowStyle = "None", the embedded WebBrowser cannot be displayed, but it is not really gone, the video loaded in the video will play normally, sound, and even point the webpage content with the mouse to interact normally, that is, nothing can be seen.

 

Solution

So how can I solve it?

After a series of searches, I found this Code:

Front-end XAML file: http://www.google.cn/codesearch/p? Hl = zh-CN # ihfHhUg5N2k/trunk/vs2010/meta/Glu/Helper/WebBrowserOverlay. xaml & q = WebBrowserOnTransparentWindow & d = 5

Background CS file: http://www.google.cn/codesearch/p? Hl = zh-CN # ihfHhUg5N2k/trunk/Glu/Helper/WebBrowserOverlay. xaml. cs & q = WebBrowserOnTransparentWindow & d = 3

To use these two files, copy them to the project:

Then place a named Border element in the place where you want to load WebBrowser:

Then set it in the background Code as follows:

In this way, your original Border location will be loaded into a WebBrowser.

Its principle seems to be to use a new form without irregular shapes and transparency to carry WebBrowser, which avoids the flexibility problem we encountered before, and then adjust the display through some Win32 APIs, it seems that we have nothing to do with integration. The final effect is as follows:

 

 

 

 

 

Slightly improved

The preceding WebBrowser always refers to the System. windows. controls. webBrowser, although it can be directly embedded by WPF, is a waste of resources. It is inferior to the WebBrowser function in WinForm, so I changed the code, make the WebBrowserOverlay class no longer carry WebBrowser, but host WindowsFormsHost. Then we can add our usual System to it. windows. forms. the WebBrowser control is changed to the following:

Defects

However, you need to know that this method is not a perfect solution, and there seems to be no perfect solution to this problem. The problems currently known in this method are as follows:

  1. A white square is displayed at the beginning of the program before the interface can be displayed normally. (Solution T_T)
  2. When Windows 7 is used, dragging the program to the left, right, and top of the screen will automatically dock and change the form size. At this time, the embedded part cannot follow the changes in the form size. (The solution is to set the maximum, minimum width, and height. There may be a way to update, but I didn't perform a detailed test, and my program does not support drag and drop to change the size, so I didn't do this test)
  3. When the main window is hidden, the embedded part is not hidden. (The solution is to hide the WebBrowserOverlay object when hiding the main form. My program is minimized directly to the system tray, so I didn't test whether the conventional minimization will produce the same problem)

This is what we have found. Except for the first article, it is quite painful ~

 

Related Materials

Http://kimiya25.spaces.live.com/blog/cns! 27A083D4FD9435E9! 1693. entry? Wa = wsignin1.0 & sa= 675748223

Http: // 203.208.39.132/search? Q = cache: J1BEG4zMNm0J: bytes

Http://www.google.cn/codesearch? Q = WebBrowserOnTransparentWindow & hl = zh-CN & btnG = % E6 % 90% 9C % E7 % B4 % A2 % E4 % BB % A3 % E7 % A0 % 81

From http://skyd.cnblogs.com/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.