473,394 Members | 1,761 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,394 software developers and data experts.

Call an event from the base class

Hey all

We are working on a project and have alot of forms with textboxes on.
Now we want to put some input validation keypress events on those
textboxes. We got a parent class where we putted some event into ex.

public void AlfaKeyPress(object sender, KeyPressEventArgs e)
{
// still have to put something into this
e.Handled = false;
}

But it seems inpossible to link to this event from a child class
without writing for all textboxes the eventhandlers. We thought, just
select all textboxes, go to the event tab en select the proper event,
but guess again it didn't work. The event was no where to be found. We
tried public, internal, internal protected and protected but zero
results.

Someone got an idee how to do this without adding it all by hand of by
adding all the event to each form.

Thanks in advanced

Mar 31 '07 #1
7 1667
Hi,
Not sure I understand your problem.
I created 3 text boxes, selected them.
Double clicked the validating event from the events lists and got a
handler stub.
Checking inside InitializeComponent confirmed the stub was hooked to
all 3 text boxes.
Bob

On 31 Mar 2007 08:22:21 -0700, "ke**********@gmail.com"
<ke**********@gmail.comwrote:
>Hey all

We are working on a project and have alot of forms with textboxes on.
Now we want to put some input validation keypress events on those
textboxes. We got a parent class where we putted some event into ex.

public void AlfaKeyPress(object sender, KeyPressEventArgs e)
{
// still have to put something into this
e.Handled = false;
}

But it seems inpossible to link to this event from a child class
without writing for all textboxes the eventhandlers. We thought, just
select all textboxes, go to the event tab en select the proper event,
but guess again it didn't work. The event was no where to be found. We
tried public, internal, internal protected and protected but zero
results.

Someone got an idee how to do this without adding it all by hand of by
adding all the event to each form.

Thanks in advanced
Apr 1 '07 #2
ke**********@gmail.com <ke**********@gmail.comwrote:
We are working on a project and have alot of forms with textboxes on.
Now we want to put some input validation keypress events on those
textboxes. We got a parent class where we putted some event into ex.

public void AlfaKeyPress(object sender, KeyPressEventArgs e)
{
// still have to put something into this
e.Handled = false;
}

But it seems inpossible to link to this event from a child class
without writing for all textboxes the eventhandlers. We thought, just
select all textboxes, go to the event tab en select the proper event,
but guess again it didn't work. The event was no where to be found. We
tried public, internal, internal protected and protected but zero
results.
You can't *call* an event from a derived class unless the base class
specifically makes that ability available to you. However, unless it's
a private event or an internal event from a different assembly, you
should be able to add a handler to it.

Effectively, an event is just a pair of methods to subscribe and
unsubcribe handlers. With "field-like" events, a delegate variable is
automatically created behind the scenes.

See http://pobox.com/~skeet/csharp/events.html for more details.

Now, if you were genuinely trying to *subscribe* to an event and
couldn't, please give more details, preferably with a short but
complete program demonstrating the problem.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 1 '07 #3
On Apr 1, 8:37 pm, Jon Skeet [C# MVP] <s...@pobox.comwrote:
kenny.den...@gmail.com <kenny.den...@gmail.comwrote:
We are working on a project and have alot of forms with textboxes on.
Now we want to put some input validation keypress events on those
textboxes. We got a parent class where we putted some event into ex.
public void AlfaKeyPress(object sender, KeyPressEventArgs e)
{
// still have to put something into this
e.Handled = false;
}
But it seems inpossible to link to this event from a child class
without writing for all textboxes the eventhandlers. We thought, just
select all textboxes, go to the event tab en select the proper event,
but guess again it didn't work. The event was no where to be found. We
tried public, internal, internal protected and protected but zero
results.

You can't *call* an event from a derived class unless the base class
specifically makes that ability available to you. However, unless it's
a private event or an internal event from a different assembly, you
should be able to add a handler to it.

Effectively, an event is just a pair of methods to subscribe and
unsubcribe handlers. With "field-like" events, a delegate variable is
automatically created behind the scenes.

Seehttp://pobox.com/~skeet/csharp/events.htmlfor more details.

Now, if you were genuinely trying to *subscribe* to an event and
couldn't, please give more details, preferably with a short but
complete program demonstrating the problem.

--
Jon Skeet - <s...@pobox.com>http://www.pobox.com/~skeet Blog:http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
The problem is not, I can't add the event with an eventhandler in the
code itself but we where wondering why we can't choose the events we
from the base-class in a derived class. Cause we thought cause its a
derived class all the events are avaible in this class to, and they
are when we use the eventhandlers and += operator and stuff to add
them to every textbox.

However the event don't show up in the list where you can choose those
autogenerated event textbox1_KeyPress, textbox1_TextChanged, ...
Those you find under the yellow lightningstrike when you select a
controle.

Only the event I write in this class are show up but not events from
the base class.

It's not a big problem but rather something that could speed-up the
development. Is it impossible to get those events into those listboxes
cause those are made with some sort of script that only checks for
events in the class itself and not for the derived class.

Thanks in advanced

Apr 2 '07 #4
ke**********@gmail.com <ke**********@gmail.comwrote:

<snip>
The problem is not, I can't add the event with an eventhandler in the
code itself but we where wondering why we can't choose the events we
from the base-class in a derived class. Cause we thought cause its a
derived class all the events are avaible in this class to, and they
are when we use the eventhandlers and += operator and stuff to add
them to every textbox.

However the event don't show up in the list where you can choose those
autogenerated event textbox1_KeyPress, textbox1_TextChanged, ...
Those you find under the yellow lightningstrike when you select a
controle.
So in other words, you're only talking about an IDE designer issue, not
a language issue? If so, I'm not really the one to help - I don't tend
to use the designer.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 2 '07 #5
On Apr 2, 11:17 pm, Jon Skeet [C# MVP] <s...@pobox.comwrote:
kenny.den...@gmail.com <kenny.den...@gmail.comwrote:

<snip>
The problem is not, I can't add the event with an eventhandler in the
code itself but we where wondering why we can't choose the events we
from the base-class in a derived class. Cause we thought cause its a
derived class all the events are avaible in this class to, and they
are when we use the eventhandlers and += operator and stuff to add
them to every textbox.
However the event don't show up in the list where you can choose those
autogenerated event textbox1_KeyPress, textbox1_TextChanged, ...
Those you find under the yellow lightningstrike when you select a
controle.

So in other words, you're only talking about an IDE designer issue, not
a language issue? If so, I'm not really the one to help - I don't tend
to use the designer.
--
Jon Skeet - <s...@pobox.com>http://www.pobox.com/~skeet Blog:http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Yea, but like i said. Its not realy "a problem" more something you
would think would work but doesn't. I has to be something with the way
VS 2005 only sees the events in the class "form" you're working and
not in a base class. So I guess, we want to do something thats not
possible because of this. if some1 got an methode how to make it work
its still welcome.

Thanks

Apr 2 '07 #6
ke**********@gmail.com <ke**********@gmail.comwrote:

<snip>
Yea, but like i said. Its not realy "a problem" more something you
would think would work but doesn't. I has to be something with the way
VS 2005 only sees the events in the class "form" you're working and
not in a base class. So I guess, we want to do something thats not
possible because of this. if some1 got an methode how to make it work
its still welcome.
No, what you're trying to do is perfectly possible (if I've understood
you correctly) it's just not working in the form designer. Does
Intellisense show you the event in the code view?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 2 '07 #7
On Apr 3, 12:21 am, Jon Skeet [C# MVP] <s...@pobox.comwrote:
kenny.den...@gmail.com <kenny.den...@gmail.comwrote:

<snip>
Yea, but like i said. Its not realy "a problem" more something you
would think would work but doesn't. I has to be something with the way
VS 2005 only sees the events in the class "form" you're working and
not in a base class. So I guess, we want to do something thats not
possible because of this. if some1 got an methode how to make it work
its still welcome.

No, what you're trying to do is perfectly possible (if I've understood
you correctly) it's just not working in the form designer. Does
Intellisense show you the event in the code view?

--
Jon Skeet - <s...@pobox.com>http://www.pobox.com/~skeet Blog:http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Yea, the intel shows the events in the code view.
But like i said already its not a "problem" rather something to speed-
up the process, however now we already got it all written down with
the eventhandlers. Thanks anyway.

Apr 3 '07 #8

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

Similar topics

12
by: ectoplasm | last post by:
Abstract base class A. Derived from A are class B and C, both concrete. I hold a pointer to an object of class A, an instance which is either B or C. I have trouble with making the following...
4
by: Amy Matlock | last post by:
Hi all: How does the hardware work if you invoke a BASE::METHOD() on a DERIVED class member? Do you still hit the v-table dynamically at run time? Suppose you have a derived class method, but...
1
by: Bill Menees | last post by:
I've got a RichTextBoxEx inherited from RichTextBox, and I want to overload the TextLength property to use TextBoxBase's implementation of TextLength. But since TextBoxBase isn't my immediate base...
1
by: Bob Rock | last post by:
Hello, I have read that the base keyword can be used not only to control a base class instantiation (thus calling one of the base class constructors) but also to access any other public or...
10
by: Peter Oliphant | last post by:
Is there a way of defining a method in a base class such that derived classes will call their own version, EVEN if the derived instance is referred to by a pointer to the base class? Note that the...
5
by: Andy | last post by:
Hi all, I have a site with the following architecture: Common.Web.dll - Contains a CommonPageBase class which inherits System.Web.UI.Page myadd.dll - Contains PageBase which inherits...
1
by: Martijn Mulder | last post by:
Documentation suggests that I should make a call to the base-class method for some methods. When I try to do so for the class below, I get wrong results. What is the correct way to make a call to...
6
by: bryanbabula | last post by:
I have a question about overriding i was wondering if anyone could help me with, or even suggesting a better/different way. I have no idea if this can even be done or not. I was wondering if there...
5
by: macap.usenet | last post by:
Hello, I´ve a problem which maybe sounds a bit easy, but it is hard do ask google for the problem. I have a CheckBoxList and a class derived from this checkboxlist Let´s say: ...
2
by: RAVISEKHAR | last post by:
what happens if i call a base class virtual function in a derived class constructor?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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...

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.