Hi All,
There is a scenario, in which there is a counter in my base class.
There is some initial value of this counter (check below code). Now
there is a function "DecreaseCount" , which will decrease count. Now I
want some functionality like when this counter become zero(0) a
delegate will be fired of derived class. This is working fine.
Now, on my UI side this instance of Tester and Developer are a
node of a TreeView. There are lots of other instance of same classes in
that TreeView. If any company having more than one(0) Employee, the
color of TreeNode should be Green. And when it becomes to Zero(0) then
color of TreeNode should become Red.
This useless to pass every time a TreeNode to Employee class. Now
I want to write a code to change the color in my UI part. And want to
call this Method/Event from by Super (base) class when the counter
becomes Zero....
The following is my effort.....
Give your feedback....
/////////// Code Start /////////////
using System;
using System.Windows. Forms;
namespace DelegateInherta nceTest
{
public delegate void NotifierCall();
public abstract class Employee
{
//public delegate void ChangeNotifier( );
NotifierCall notifierCall;
int counter = 5;
//Constructor
public Employee()
{
notifierCall = new NotifierCall(th is.NotifyCall);
}
public Employee(int counter)
{
this.counter = counter;
notifierCall = new NotifierCall(th is.NotifyCall);
}
public abstract void NotifyCall();
public virtual void NotifyCall()
{
MessageBox.Show ("Call of Delegate In Base");
}
public void DecreaseCount()
{
this.counter--;
if (this.counter == 0)
{
this.notifierCa ll();
}
}
}
public class Tester : Employee
{
//Default Constructor
public Tester()
{
}
public override void NotifyCall()
{
MessageBox.Show ("NotifyCall of Delegate In Derived of Tester");
}
}
public class Developer : Employee
{
//Default Constructor
public Developer()
{
}
public override void NotifyCall()
{
MessageBox.Show ("NotifyCall of Delegate In Derived of Developer");
}
}
public class EmployeeDemo
{
static void Main()
{
Employee testers = new Tester();
Employee developers = new Developer();
while(true)
{
testers.Decreas eCount();
}
}
public void NotifyCall()
{
MessageBox.Show ("Call of induvidual instance");
}
}
}
////// Code End //////
Thanks In Advance.....
Waiting for your feedback....
Thanks & Regards,
Rushikesh
Integreon 3 1476
One more thing.
Should I resolve this using creting an Public Event....
If yes, then How???
Please reply back to me
Thanks & Regards,
Rushikesh
Integreon
Hi Roshik
as far as i understood ur question heres my answer . Basically u need
to create ur own eventsArgs Class which will have a colour as parameter
and that will be set in the base class. When the ColourChangeEve nt will
be fired, whatever the color is set in the parent class will be passed
to eventhandler for Inheriting class which will then set its colour
namespace DelegateInherta nceTest
{
public delegate void ChangeColour(Co lourEventArgs e);
public event ChangeColour OnColourChangeE vent;
public abstract class Employee
{
private int intCount;
public int EmployeeCount
{
get { return this.intCount;}
set { this.intCount = value;}
}
public void DecreaseCount()
{
this.counter--;
if (this.Count == 0)
{
e = new ColourArgs("gre en");
this.OnColourCh angeEvent(e);
}
}
public abstract OnColourChangeE vent(ColourEven tArgs e);
}
public class Tester : Employee
{
private string nodeColour;
//Default Constructor
public Tester()
{
}
public override void OnColourChangeE vent(ColourArgs e)
{
nodeColour = e.GetColour;
}
public override void NotifyCall()
{
MessageBox.Show ("NotifyCall of Delegate In
Derived of Tester");
}
}
public class ColourEventArgs : EventArgs
{
ColourEventArgs (string clr)
{
this.Colour = clr;
}
private string strColour;
public string Colour
{
get {return strColour;}
set {this.strColour = value;}
}
}
}
public class EmployeeDemo
{
static void Main()
{
Employee testers = new Tester();
if ( testers.Employe eCount > 0)
{
}
while(true)
{
testers.Decreas eCount();
}
}
}
hope it helps
Vivek
Thanks Vivek,
You understand correctly, but only problems is how do my UI(Say Main
function) get notify about this. Because the color change will fier
automatically when count becomes Zero....
But how do I hange the Color of particular TreeNode.
LoveDotNet wrote: Hi Roshik as far as i understood ur question heres my answer . Basically u need to create ur own eventsArgs Class which will have a colour as parameter and that will be set in the base class. When the ColourChangeEve nt will be fired, whatever the color is set in the parent class will be passed to eventhandler for Inheriting class which will then set its colour
namespace DelegateInherta nceTest { public delegate void ChangeColour(Co lourEventArgs e); public event ChangeColour OnColourChangeE vent;
public abstract class Employee { private int intCount; public int EmployeeCount { get { return this.intCount;} set { this.intCount = value;} }
public void DecreaseCount() { this.counter--; if (this.Count == 0) { e = new ColourArgs("gre en"); this.OnColourCh angeEvent(e); } }
public abstract OnColourChangeE vent(ColourEven tArgs e); }
public class Tester : Employee { private string nodeColour; //Default Constructor public Tester() { }
public override void OnColourChangeE vent(ColourArgs e) { nodeColour = e.GetColour; }
public override void NotifyCall() { MessageBox.Show ("NotifyCall of Delegate In Derived of Tester"); } }
public class ColourEventArgs : EventArgs { ColourEventArgs (string clr) { this.Colour = clr; } private string strColour; public string Colour { get {return strColour;} set {this.strColour = value;} } } }
public class EmployeeDemo { static void Main() { Employee testers = new Tester(); if ( testers.Employe eCount > 0) { } while(true) { testers.Decreas eCount(); } }
}
hope it helps Vivek This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: JPRoot |
last post by:
Hi
I use the following syntax to have events inherited from base to child classes which works nicely (virtual and override keyword on events). But I am wondering if it is a "supported" way of using events since I never saw it used anywhere in MSDN documentation/samples?! Or it will just break when I upgrade to .NET Framework 2.x in the coming years
namespace MyNamespac
public delegate void MyDel()
public class MyBase
public virtual...
|
by: StevenVibert |
last post by:
I'm rewriting a C++ TAPI app I wrote a while ago in C#. Everything
works fine for the first call. Unfortunately, all subsequent calls are
completely ignored by TAPI until I restart the app again.
I remember running into this same problem with my original C++ code and
it was being caused by my failure to release all call related tapi
resources. As a point of reference the C++ app has been running quite
well for over a year.
Anyway, I...
|
by: Minh Khoa |
last post by:
Please give me more information about delegate and its usage?
Why do i use it and when?
|
by: Nicky Smith |
last post by:
Hello,
I'm reading Mike Gunderloy's Mcad Vb.net book, and I've also read the
MS press Mcad book for the same topic ".. Windows based applications
with VB.net" for exam 70-306.
In the sections in both books that try to teach the use of delagates
and events, I'm really lost, and to make matters worse, I've written a
user-control that fires events for the host form, and this works
without delegates!
|
by: Tim |
last post by:
There are a set of clients who need to be notified of certain events. I have
used events and delegates (publisher-Subscriber model) for the
notification mechanism. All the clients register with the event publisher
and subscribe for the events that they are interested in. When a certain
event happens, the subscribers are notified about it.
I want the clients to return a value after their callback method is called.
If any of the client...
| |
by: Ant |
last post by:
Hello,
Very simple question but one I need clarified.
Which part of the statement below is considered the 'delegate'?
Is it the 'new System.EventHandler'
or the
btnAccept_Click?
or is it the piece of code which doesn't appear here, but abstracts the
btnAccept_Click method?
|
by: Mark |
last post by:
why doesn't .NET support multiple inheritance?
I think it's so silly!
Cheers,
Mark
|
by: David Veeneman |
last post by:
I have several events that pass a value in their event args. One event
passes an int, another a string, another a DateTime, and so on. Rather than
creating a separate set of event args for each type, I have created a
generic event args class that looks like this:
public class ItemChangingEventArgs<T>
{
...
}
|
by: groups |
last post by:
C# is an impressive language...but it seems to have one big limitation
that, from a C++ background, seems unacceptable.
Here's the problem:
I have a third-party Document class. (This means I can't change the
Document class.) I want to extend this (inherit from Document) as
MyDocument, adding new events and application-specific methods and
properties.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |