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

Call to Base-Class Does Not Succeed

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 the base class for an
event like this?
//class Form
class Form:System.Windows.Forms.Form
{

//constructor
Form()
{
MouseEnter+=OnMouseEnter;
}
//OnMouseEnter
void OnMouseEnter(System.Object a,System.EventArgs b)
{
base.OnMouseEnter(b);
}
//Main
[System.STAThread]
static void Main()
{
System.Windows.Forms.Application.Run(new Form());
}
}


Nov 21 '06 #1
1 1456
Martijn Mulder wrote:
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 the base class for an
event like this?
//class Form
class Form:System.Windows.Forms.Form
{

//constructor
Form()
{
MouseEnter+=OnMouseEnter;
}
//OnMouseEnter
void OnMouseEnter(System.Object a,System.EventArgs b)
{
base.OnMouseEnter(b);
}
//Main
[System.STAThread]
static void Main()
{
System.Windows.Forms.Application.Run(new Form());
}
}
If you are handling this throug events as you are, then there is no need to
call the base class as that has already happened by the time you get to your
event handler. If instead of using event handlers you had overriden the
OnMouseEnter method of the base class, then in your override you would want
to make sure you called the base. That would like similar to as follows:

//class Form
class Form:System.Windows.Forms.Form
{

//constructor
Form()
{
}

//OnMouseEnter
protected override void OnMouseEnter(System.EventArgs b)
{
base.OnMouseEnter(b);
}

//Main
[System.STAThread]
static void Main()
{
System.Windows.Forms.Application.Run(new Form());
}
}

--
Tom Porterfield

Nov 21 '06 #2

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

Similar topics

26
by: Paul | last post by:
public class A { public A () { // here I would like to call the second version of _ctor, how to accomplish this ? } public A (int a, int b, int c) {
3
by: John A. Prejean | last post by:
This one has me stumped. I have a base form I am trying to wrap up, but I have one problem. In two functions I am opening a "record detail" form. I would like to keep the code in the base form...
6
by: Radith Silva | last post by:
Private Sub cmdCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCalculate.Click If txtName.Text <> "" Then If txtUnits.Text <> "" Then If optOne.Checked Or...
4
by: AI Man | last post by:
Greetings, I have been searching the web and Access relentlessly trying to find a way to call an Access macro from a different Access data base. Example - The form button gets clicked and the...
3
by: xtrigger303 | last post by:
Hi to all, a newbie question. Is it possible to avoid the virtual mechanism with pointers to members syntax the same way it's done with an explicit call ( obj.Base::Func() )? It would be...
6
by: active | last post by:
In Protected Overrides Sub OnDrawItem should I call MyBase.OnDrawItem(e) at the top or bottom of the sub? What might happen if I don't call it?
11
by: Fabio | last post by:
Hi all There is a way to exec a function asynchronously? I need to exec a function that is too slow but for me can be executed in the background... there is no way??? Thanks
0
by: noel.whelan | last post by:
I've been working through the zend gdata client lib example for google base: http://code.google.com/apis/base/samples/php/php-sample-zend.html. I've installed the zend framework version 1.0.2...
2
by: Mosfet | last post by:
Hi, I am currently writing a graphical control(a list control) that can display a picture followed by some text and to do so I first calculate an item height and then I really draw. I was...
4
by: smrah1 | last post by:
Hi we have like below code: namespace ConsoleApplication1 { class Program { static void Main(string args) {
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.