JDeats said:
I need to be able to detect when the user clicks on the browser
control area. The control offers no Mouse events whatsoever. I have
tried to resort to override WndProc on the control, I have a break
point set where indicated in the code below which never gets called.
Any alternative methods or suggestions on why this isn't working?
protected override void WndProc(ref System.Windows.Forms.Message
m)
{
const int WM_LBUTTONUP = 0x0202;
if (m.Msg == WM_LBUTTONUP)
{
int test = 0; // I have a break point here
}
base.WndProc(ref m);
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace wb
{
public partial class Form1 : Form
{
private System.Windows.Forms.WebBrowser webBrowser1;
private HtmlDocument m_document = null;
public Form1()
{
this.webBrowser1 = new System.Windows.Forms.WebBrowser();
this.SuspendLayout();
//
// webBrowser1
//
this.webBrowser1.Dock = System.Windows.Forms.DockStyle.Fill;
this.webBrowser1.Location = new System.Drawing.Point( 0, 0 );
this.webBrowser1.MinimumSize = new System.Drawing.Size( 20,
20 );
this.webBrowser1.Name = "webBrowser1";
this.webBrowser1.Size = new System.Drawing.Size( 665, 491 );
this.webBrowser1.TabIndex = 0;
this.webBrowser1.Navigated += new
System.Windows.Forms.WebBrowserNavigatedEventHandler(
this.webBrowser1_Navigated );
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF( 6F, 13F );
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size( 665, 491 );
this.Controls.Add( this.webBrowser1 );
this.Name = "Form1";
this.Text = "Form1";
this.FormClosing += new
System.Windows.Forms.FormClosingEventHandler( this.Form1_FormClosing );
this.Load += new System.EventHandler( this.Form1_Load );
this.ResumeLayout( false );
}
void m_document_Click( object sender, HtmlElementEventArgs e )
{
MessageBox.Show( "Clicked at: " + e.MousePosition.X + ", " +
e.MousePosition.Y );
}
private void Form1_Load( object sender, EventArgs e )
{
webBrowser1.Navigate( "
http://www.google.com" );
}
private void Form1_FormClosing( object sender, FormClosingEventArgs
e )
{
webBrowser1.Dispose();
}
private void webBrowser1_Navigated( object sender,
WebBrowserNavigatedEventArgs e )
{
m_document = webBrowser1.Document;
m_document.Click += new HtmlElementEventHandler(
m_document_Click );
}
}
}