473,404 Members | 2,187 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,404 software developers and data experts.

Override event but do not use call back for controls in inherited class

Hi,

I have a class in C# which receives data from the socket and inherits from Form. Whenever it receives data, it fires an event.

ReceivedDone += new ReceivedDoneEventHandler(MyClass.DataReceiveDone);

then I have following functions:

Expand|Select|Wrap|Line Numbers
  1.  
  2.         public void DataReceiveDone(object sender, ReceivedDoneNotifyEventArgs e){
  3.  
  4.             byte[] buffer;
  5.             buffer = new byte[e.Data.Length]; 
  6.             e.Data.CopyTo(buffer, 0);
  7.             DataReceived(buffer);
  8.         }
  9.  
  10.  
  11.  
  12.        public virtual void DataReceived(byte[] bData)
  13.         {
  14.             MessageBox.Show("I am here");
  15.         }
  16.  
  17.  
I expect the user of this class to override DataReceived() and use the data in inherited class. The problem is, if user creates new control and wants to assign bData, he must use Control.invoke in inherited class, for example:

lblReading.Invoke(new OnDataReceiveCallback(this.OnDataReceive), bData);

I want user of the class to do this in easy way like,
lblReading.Test = BitConverter.ToInt16(bData, 0);

Any help?

Thanks in advance,

Haroon.
Feb 27 '07 #1
1 1043
Hi,

Sorry I dont know how to edit above question. So I am rewriting it with editing.
I have a class in C# which receives data from the socket and inherits from Form. Whenever it receives data, it fires an event.

ReceivedDone += new ReceivedDoneEventHandler(MyClass.DataReceiveDone);

then I have following functions:

public void DataReceiveDone(object sender, ReceivedDoneNotifyEventArgs e){

byte[] buffer;
buffer = new byte[e.Data.Length];
e.Data.CopyTo(buffer, 0);
DataReceived(buffer);
}



public virtual void DataReceived(byte[] bData)
{
MessageBox.Show("I am here");
}


I expect the user of this class to override DataReceived() and use the data in derived class. The problem is, if user creates new control and wants to assign bData, he must use Control.invoke in derived class, for example:

lblReading.Invoke(new OnDataReceiveCallback(this.OnDataReceive), bData);

I want user of the class to do this in easy way like,
lblReading.Test = BitConverter.ToInt16(bData, 0);

So only change is the word "derived" instead of inherited.
Any help?

Thanks in advance,

Haroon.
Feb 28 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

14
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...
8
by: JPRoot | last post by:
Hi M. Jeffrey Tan, Just hopping you didn't forget me? :) Thanks JPRoot ----- \"Jeffrey Tan\" wrote: -----
5
by: Darius | last post by:
I'm writing here in hopes that someone can explain the difference between the new and virtual/override keywords in C#. Specifically, what is the difference between this: public class Window {...
18
by: bhavin | last post by:
Hi, Can someone point me to some good best practices kind of documentation on use of events compared to method overriding. Ex. In Windows Forms when should i have an event handler for Paint, and...
8
by: Keith Smith | last post by:
Could some one help me a little? I am trying to understand when/where you would ever want to use "protected override..." code such as this. How is this any different from creating a...
3
by: methodios | last post by:
Hi Can someone help me straighten out my train of thought... I want to know what actually goes on behind the scene..step by step. Here is the code: ----------------- using System; ...
5
by: Marcel Hug | last post by:
Hi NG ! I'm new in C# and I'm reading a book about the fundamentals and concepts. In the chapter Methods it's written to use virtual, if i would like to override the method in a subclass. This...
9
by: jeff | last post by:
New VB user...developer... Situation...simplified... - I want to wrap a pre and post event around a system generated where the pre-event will always execute before the system event and the...
2
by: slolife | last post by:
See any problem with this code: Here's my Base page class: Public Class BasePage Inherits System.Web.UI.Page Protected m_NeedAlerts As Boolean Private Sub Page_Init(ByVal sender As...
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: 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
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...
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
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.