)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

What is bubbling event architecture and construct it in WinForms HTMLUIControl?

Platform: WinForms |
Control: HTMLUIControl |
Published Date: April 30, 2011 |
Last Revised Date: January 3, 2020

Bubbling event

The use of a common 'Event Handler' for handling the same event for all the child elements is called Bubbling Event Architecture. This helps in reducing the number of event handler declarations required by each and every child element, thereby reducing the length and complexity of the code.

The HTML elements are collected in an array by their parent name. An event handler, for a specific event, common to all the elements in the collection is defined. The bubbling event arguments for the elements are set. The element that first triggers the event is traced. Based on the element's identity, the action for the event is executed.

C#

//The elements within the BODY tag(parent element) are got in an array
IHTMLElement[] htmlelement = this.htmluiControl1.Document.GetElementsByName("body");
//A common event handler is defined for all the elements in the collection
htmlelement[0].Click += new EventHandler(body_Click);
//The bubbling event argument for the tag elements are set
BubblingEventArgs bargs = HTMLUIControl.GetBublingEventArgs(e);
//The element that first triggers the event is obtained
BaseElement elem = bargs.RootSender as BaseElement;
//The Element is verified for its identity and the event is executed
private void body_Click(object sender, EventArgs e)
{
    if(elem.ID == "btn1")
   {
        Console.WriteLine("Button1 is clicked");
   }
   else if(elem.ID == "btn2")
   {
        Console.WriteLine("Button2 is clicked");
   }
}

 

VB

'The elements within the BODY tag(parent element) are got in an array
Private htmlelement As IHTMLElement() = Me.htmluiControl1.Document.GetElementsByName("body")
'A common event handler is defined for all the elements in the collection
Private htmlelement(0).Click += New EventHandler(body_Click)
'The bubbling event argument for the tag elements are set
Private bargs As BubblingEventArgs = HTMLUIControl.GetBublingEventArgs(e)
'The element that first triggers the event is obtained
Private elem As BaseElement = CType(IIf(TypeOf bargs.RootSender Is BaseElement, bargs.RootSender, Nothing), BaseElement)
'The Element is verified for its identity and the event is executed
Private Sub body_Click(ByVal sender As Object, ByVal e As EventArgs)
    If elem.ID = "btn1" Then
       Console.WriteLine("Button1 is clicked")
    Else If elem.ID = "btn2" Then
       Console.WriteLine("Button2 is clicked")
    End If
End Sub

 

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon