473,398 Members | 2,525 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Trap Event of Class and tie to Method

I have a assembly from a third party that exposes an Event
I want to Trap the event and tie to a Method in a Class where I am consuming
their assembly. The class is actually a UserControl

How can I tie OnSettingsModified from the assembly to Method
Configuration_OnValid in my class ????

Thanks
Third Party App
============
public interface ISettings
{

event EventHandler OnSettingsModified;
}
public Class Settings: ISettings
{
private void textEdit_EditValueChanged(object sender, EventArgs e)
{
if (OnSettingsModified != null)
{
OnSettingsModified.Invoke(sender, e);
}

}

}

My App
======

Settings mySettings - new Settings();

private void Configuration_OnValid(object sender, System.EventArgs e)
{
UpdateEnableSave();
}
Nov 4 '08 #1
1 1794
Good morning sippyuconn.

The method of tying OnSettingsModified from the assembly to
Configuration_OnValid depends on how Settings implements the ISettings
interface: either explicitly or implicitly. I will go through each
possibility with you and provide the solution respectively.

=====================================
Possibility 1: 'Settings' IMPLICITLY implements 'ISettings'

public interface ISettings
{
event EventHandler OnSettingsModified;
}

public class Settings : ISettings
{
private void textEdit_EditValueChanged(object sender, EventArgs e)
{
if (OnSettingsModified != null)
{
OnSettingsModified.Invoke(sender, e);
}
}

#region ISettings Members

public event EventHandler OnSettingsModified;

#endregion
}

The code "public event EventHandler OnSettingsModified;" tells that
'Settings' is implicitly implementing 'ISettings', and the event is a part
of the class, so we can add the event handler by writing this code:

Settings mySettings = new Settings();
mySettings.OnSettingsModified += new EventHandler(Configuration_OnValid);

=====================================
Possibility 2: 'Settings' EXPLICITLY implements 'ISettings'

public class Settings : ISettings
{
public void textEdit_EditValueChanged(object sender, EventArgs e)
{
if (OnSettingsModified != null)
{
OnSettingsModified.Invoke(sender, e);
}
}

event EventHandler OnSettingsModified;

#region ISettings Members

event EventHandler ISettings.OnSettingsModified
{
add
{
lock (OnSettingsModified)
{
OnSettingsModified += value;
}
}
remove
{
lock (OnSettingsModified)
{
OnSettingsModified -= value;
}
}
}

#endregion
}

In this implementation, the event OnSettingsModified is not exposed as a
public event from the class 'Settings', thus, we cannot tie the event
handler in the same way as "possibility 1". The event is a part of the
interface, so the right way to add the event handler is:

Settings mySettings = new Settings();
ISettings iSettings = (ISettings)mySettings;
iSettings.OnSettingsModified += new EventHandler(Configuration_OnValid);

For more information about explicitly implementing an interface event,
please refer to the MSDN article:
http://msdn.microsoft.com/en-us/libr...46(VS.80).aspx
http://msdn.microsoft.com/en-us/libr...57(VS.80).aspx

sippyuconn, is the above information helpful to you? If it cannot help you
with the question, I appreciate it if you could share more implementation
of the class 'Settings' or send a small reproducible project to my mailbox:
ji****@microsoft.com

Have a very nice day!

Best Regards,
Jialiang Ge (ji****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

MSDN Managed Newsgroup support offering is for non-urgent issues where an
initial response from the community or a Microsoft Support Engineer within
2 business day is acceptable. Please note that each follow up response may
take approximately 2 business days as the support professional working with
you may need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations that require urgent,
real-time or phone-based interactions. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 5 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: RAJ | last post by:
hi plz tell me how to know "how window is going to close"... i have to right code for X button of forms... plz telll me thanks bye
18
by: Elder Hyde | last post by:
Hey all, A class of mine needs to tell the outside world when its buffer is not empty. The problem is that C# seems to force you to put the event-raising code in the base class. To illustrate,...
1
by: Sean Nolan | last post by:
We have implemented unhandled error trapping at the application level and log these errors to our database. One error, however, the does not get trapped is when the connection pool has exceeded the...
3
by: Denon | last post by:
How to trap browser close event in SERVER side? I read a lot of forum message, it talk about onclose(), onunload() and even onbeforeunload() event. However, all of theses are based on javascript...
0
by: Jack Wright | last post by:
Dear All, I have a web Application "http://localhost/Web/WebForm1.aspx" that calls a WebService from "http://localhost/webserviceapp/service1.asmx"...I have set the executionTimeout to 10 secs in...
7
by: Charles Law | last post by:
I may have asked this before, but what is the purpose of both these functions? Is there a time when one should be called over the other? Does one supersede the other, or do they both have their...
13
by: Charles Law | last post by:
Mr "yEaH rIgHt" posted the following link about a week ago in answer to my question about removing event handlers. > http://www.vbinfozine.com/t_bindevt.shtml Following on from that post, the...
3
by: Gavin | last post by:
Hi All I have a project that has 2 forms, the main form displays various sql data items and the second form is for editing / updating 1 particular table. I would like to refresh a dataset on...
2
by: Linda Liu[MSFT] | last post by:
Hi George, Keyboard input introduces the idea of focus. In Windows, a particular element is designated as having the focus, meaning that it acts as the target for keyboard input. The user sets...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.