Tag Archives: WebBrowser

WebBrowser Control – Flash DropDown Fix (Framework 2.0)

For a customer of ours we had to create a standalone browser that could load assessments for candidates. It couldn’t be loaded in a browser because the user would have access to the computer. Anyway, the .NET WebBrowser component loads a html page with the swf that starts the assessment.
The problem now was that Flex/Flash dropdowns didn’t seem to work. A candidate could click on the dropdown, the items were shown but when an item was clicked, the dropdown closed and the item was not selected. On my laptop I couldn’t reproduce the bug.

After searching someone pointed me in the right direction on StackOverflow and with the help of this question on a vbdotnetforum, I finally managed to find the problem and two solutions.

Problem

It seems that when clicking the dropdown, a Flash layer is displayed on top of the dropdown with the items. At that moment, the WebBrowser seems to take over the focus. When clicking on an item, you are actually clicking on the whole Flash Application, giving back focus to the swf, but not selecting an item. Because Flash gets back the focus, the dropdown closes automatically.

Solution 1

The problem only occurs when the client pc has .NET Framework 2.0 installed and nothing higher. When installing .NET Framework 2.0 SP1 or 3.5, the problem is resolved.

Solution 2

By extending the WebBrowser component and overriding one function, you can resolve the problem without upgrading .NET Framework. Use this Class as your WebBrowser and everything should work fine (the VB implementation can be found at the link above):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System.Windows.Forms;
 
namespace SaltoExplorer
{
///
 
<summary> /// When clients have .NET Framework 2.0 installed and
/// nothing higher, then there's a problem that not item
/// can be selected in Flex DropDowns.
/// It's a problem with focus. From the moment
/// .NET Framework 2.0 SP1 or higher (like 3.5) is installed,
/// the problem is resolved.
/// Extending the WebBrowser component can fix this problem,
/// but it should only be done if the problem occurs
/// (with .NET Framework 2.0)
/// See
/// http://www.vbdotnetforums.com/vb-net-general-discussion/18563-webbrowser-control-2-0-framework-flash-fix.html
/// http://stackoverflow.com/questions/2205924/problems-flashflex-in-net-webbrowser-component
/// </summary>
 
&nbsp;
 
public class Edumatic3WebBrowser : WebBrowser
{
private const int WmLbuttondown = 0x201;
private const int WmRbuttondown = 0x204;
private const int WmMbuttondown = 0x207;
private const int WmMouseactivate = 0x21;
 
private ContainerControl FindContainerControl()
{
ContainerControl cc = null;
Control ctl = this;
while(ctl != null)
{
var tempCc = ctl as ContainerControl;
if(tempCc != null)
{
cc = tempCc;
break;
}
ctl = ctl.Parent;
}
return cc;
}
 
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WmLbuttondown:
case WmRbuttondown:
case WmMbuttondown:
case WmMouseactivate:
if(!DesignMode)
{
var cc = FindContainerControl();
if(cc != null &amp;&amp; cc.ActiveControl != this)
{
//Probably giving focus to the Swf
cc.Focus();
}
}
base.DefWndProc(ref m);
break;
default:
base.DefWndProc(ref m);
break;
}
}
}
}