Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / September 2007

Tip: Looking for answers? Try searching our database.

Adding WndProc override on inherited Web Browser WinForm control.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
JDeats - 26 Sep 2007 23:20 GMT
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);
       }
Ashot Geodakov - 27 Sep 2007 01:15 GMT
>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
[quoted text clipped - 16 lines]
>            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 );
       }
   }
}

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.