:: Home

  login:         
  passwords:  

Winforms Interview Questions

Windows Forms Deployment
Windows Forms Controls
Windows Forms Data Binding
Windows Forms Datagrid
Windows Forms Docking
Windows Forms Keyboard Handling
Windows Forms Layout
Windows Forms Licensing
Windows Forms Menus
Windows Forms Mouse Handling
Windows Forms from MFC
Windows Forms from VB6
Windows Forms Patterns
Windows Forms Printing
Windows Forms Resources
Windows Form Scrolling
Windows Forms Tips
Windows Forms Common Dialogs
Windows Forms Listbox
Windows Forms ComboBox
Windows Forms Rich TextBox
Windows Forms ListView
Windows Forms TreeView
Windows Forms Button
Windows Forms TabControl
Windows Forms TextBox
Windows Forms MDI
Windows Forms Cursors
Windows Forms WebBrowser
Windows Forms PictureBox
Windows Forms Form
Windows Forms MDI
Windows Forms In IE
GDI+Bitmaps&Images
GDI+Font
GDI+Color
GDI+Brushes
GDI Drawing Tips
GDI+ from GDI
GDI Paths Regions
GDI+Pens
Interioerability WIn32
Tools Metadata Viewers
Design Time Serialization
Design Time Custom Designers
Design Time Tips
Design Time Type Editors
Vs.Net Tips
Vs.Net Debugging
Vs.Net Macros
Framework Tips General
Framework Tips Events
Framework Tips General IO
Framework Tips Strings
Framework Tips Threading
Tool Resource Editor
Design Time UI
Framework Tips CGI
Framework Tips XML

WPF Interview Qs

SilverLight Interview Qs

SAP Interview Questions

Oracle Interview Questions

PHP Interview Questions

Ajax Interview Questions

IIS 7.0

OOP Interview Questions

Ruby Interview Questions

Sql Server Interview Questions

SharePoint 2007 Questions

Microsoft Crm Questions

Framework Tips Events

The General Winforms Interview Questions consists the most frequently asked questions in Winforms. This list of 100+ questions guage your familiarity with the Winforms platform. The q&a have been collected over a period of time from various blogs, forums and other similar Winforms sites

51. Framework Tips Events

    51.1 How do I intercept event subscription of a event in my base class?
    51.2 How do I control the order in which events are fired to multiple subscribers?
    51.3 How do I figure out if a particular client object has subscribed to one of my events?

51.1 How do I intercept event subscription of a event in my base class?

In C# you could intercept what gets subscribed as follows: // In a Control derived class, for example: // Use override if the base class property was marked as virtual public new event EventHandler Click { add { // Do not let derived classes subscribe to this event, they should instead override OnClick. if(value.Target != this) base.Click += value; } remove { base.Click -= value; } }


51.2 How do I control the order in which events are fired to multiple subscribers?


// Use a custom Delegate to hold your subscribers
private EventHandler myHandlers;
// Control Click event firing, for example.
public new event EventHandler Click
{
add
{
this.myHandlers += value;
}
remove
{
this.myHandlers -= value;
}
}
protected override void OnClick(EventArgs e)
{
// First let my derived classes receive the Click event.
foreach(Delegate d in this.myHandler.GetInvocationList())
{
if(d.Target == this)
{
d.DynamicInvoke(new object[]{this, e});
break;
}
}
// Then let other subscribers receive the Click event.
foreach(Delegate d in this.myHandler.GetInvocationList())
{
if(d.Target != this)
d.DynamicInvoke(new object[]{this, e});
}
}

51.3 How do I figure out if a particular client object has subscribed to one of my events?

In C#, you can do as follows:

// In a Control derived class, for example, first store the handlers in a custom list.
private EventHandler myHandlers;
public new event EventHandler Click
{

add
{
this.myHandlers += value;
}
remove
{
this.myHandlers -= value;
}
}
// This method will specify whether a particular delegate is subscribed.
public bool IsSubscribed(Delegate del)
{
System.Delegate[] delegates = this.myHandlers.GetInvocationList();
foreach(Delegate d in delegates)
{
if(d == del)
return true;
}
return false;
}
// Fire the Click event by parsing through your delegate list.
protected override void OnClick(EventArgs e)
{

// First let my derived classes receive the Click event.
foreach(Delegate d in this.myHandlers.GetInvocationList())
{
d.DynamicInvoke(new object[]{this, e});
}
}

Copyright 2007, Megasolutions Ltd