0

Possible Duplicate:
Create event handler for OnScroll for web browser control

I would like to create an event handler for a web browser control scrolling.

webCompareSQL.Document.Window.Scroll

Can some one show me how to create an event handler?

Community
  • 1
  • 1
Pomster
  • 14,567
  • 55
  • 128
  • 204

1 Answers1

5

In the class you add a delegate and an event, and usually a simple internal method that checks for null and calls the event:

public delegate void ScrollHandler();
public event ScrollHandler Scrolled;
internal void OnScrolled()
{
    if (this.Scrolled != null)
        this.Scrolled();
}

Then in the actual code you would register a method for the event using:

MyClass.Scrolled += new ScrollHandler(MyMethod);

void MyMethod()
{
    Console.WriteLine("It was scrolled.");
}
Matt
  • 7,100
  • 3
  • 28
  • 58
  • Thanks i'm still figuring out how it works :) – Pomster Jun 20 '12 at 08:58
  • Thanks this looks good for creating an event handler. This webCompareSQL.Document.Window.Scroll this code is and even or i think it is because when i typed it in there was lightning next to the scroll, is there any way i can write an even handler for this? – Pomster Jun 20 '12 at 09:02