473,545 Members | 2,627 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

About using event

Hello!

What is the differens if I use event handler onSizeChanged compare to using
the other event handler MeltPracForm_Si zeChanged.
I see both as event handler is that right?
I catch the event in both cases. So is it more or less the same thing which
of these two event handler I use.

protected override void OnSizeChanged(E ventArgs e)
{
....
}
private void MeltPracForm_Si zeChanged(objec t sender, System.EventArg s e)
{
....
}

//Tony
May 15 '06 #1
7 1694
The convention I believe is that the OnXXX methods are not event
handlers but are the methods that you use to raise the events of your
classes. The other methods are what the third party actually wires up
to handle the events of your classes.

May 15 '06 #2
"tony" <jo************ *****@telia.com > wrote:
What is the differens if I use event handler onSizeChanged compare to using
the other event handler MeltPracForm_Si zeChanged.
I see both as event handler is that right?
No. One is a protected method, the other is a .NET event. The general
pattern for .NET components is for the base class implementation of the
protected method (OnSizeChanged in this case) to invoke the event
handler (SizeChanged in this case).
protected override void OnSizeChanged(E ventArgs e)
{
...
}
This is suitable if you are creating a new control for reuse elsewhere.
For example, if you want to save this form in a class library (.DLL) and
reuse it in other applications, it may work better for you. You can even
choose not to trigger the underlying event by not calling the base class
implementation.
private void MeltPracForm_Si zeChanged(objec t sender, System.EventArg s e)
{
...
}


This method gets inserted (via a delegate) into the SizeChanged event in
the InitializeCompo nent method by the VS designer. Search the
InitializeCompo nent method body and you'll see something like:

this.SizeChange d += new EventHandler(Me ltPracForm_Size Changed);

This creates a subscription to this event so that the given method gets
called when the event is triggered. The event is triggered by the base
class implementation of OnSizeChanged.

-- Barry
May 15 '06 #3
Hi,
"tony" <jo************ *****@telia.com > wrote in message
news:O$******** ******@TK2MSFTN GP04.phx.gbl...
Hello!

What is the differens if I use event handler onSizeChanged compare to
using
the other event handler MeltPracForm_Si zeChanged.
I see both as event handler is that right? I catch the event in both cases. So is it more or less the same thing
which
of these two event handler I use.


You do not catch the event in both cases, with the OnXXX you handle let call
it "the window event" , the WM_XXXX event that the control receives from
windows. There is a method WndProc that receives all the events from
windows, then call predefined methods, these are the OnXXX methods you see.
In the OnXXX method you format the info received and then call the events
like SizeChanged.


--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
May 15 '06 #4
Would it be true to say that usually the main functional difference with the
protected override method vs calling a delegate is the ability to override
the default behavor by returning true. This doesn't appear to be the case in
this example as there is a void return value, but often protected override
methods return a bool which allow you to do this, and you just can't do that
with the delegate.

"tony" <jo************ *****@telia.com > wrote in message
news:O$******** ******@TK2MSFTN GP04.phx.gbl...
Hello!

What is the differens if I use event handler onSizeChanged compare to
using
the other event handler MeltPracForm_Si zeChanged.
I see both as event handler is that right?
I catch the event in both cases. So is it more or less the same thing
which
of these two event handler I use.

protected override void OnSizeChanged(E ventArgs e)
{
...
}
private void MeltPracForm_Si zeChanged(objec t sender, System.EventArg s e)
{
...
}

//Tony

May 15 '06 #5
"Robert Halford" <ro************ @tiscali.com> wrote:
Would it be true to say that usually the main functional difference with the
protected override method vs calling a delegate is the ability to override
the default behavor by returning true. This doesn't appear to be the case in
this example as there is a void return value,
No. By convention, .NET events don't use return values. Instead, they
usually use a property on the event-args parameter, usually descended
from EventArgs.

Protected virtual methods can have any valid signature. However, the On*
virtual methods are designed to call the corresponding events, so to
match the event signatures, they only accept the corresponding
event-args parameter. They don't accept the 'object sender' parameter
since they supply that when invoking the event.
but often protected override
methods return a bool which allow you to do this, and you just can't do that
with the delegate.


You can return any value you like from a delegate (but multiple
subscriptions cause only one return value to be used):

---8<---
using System;

class App
{
delegate int ValueGetter();

static event ValueGetter GetValue;

static int MyGetValue()
{
return 42;
}

static void Main()
{
GetValue += MyGetValue;

Console.WriteLi ne(GetValue());
}
}
--->8---

-- Barry
May 15 '06 #6
Hello!!

I just wonder which of these two methods is most suitable to use in this
circumstances
when the main application window form is minimized I will minimize
all window forms that the main window form has made visible.
To make this possible I can use whichever of these two methods.

When the window form for the application is minimized this method
OnSizeChanged is called.
Protected override void OnSizeChanged(E ventArgs e)
{
...
}

I have used the form designer to be able to create this event handler.
This method MeltPracForm_Si zeChanged is also called when the window form
for application is minimized.
private void MeltPracForm_Si zeChanged(objec t sender, System.EventArg s e)
{
...
}

So what method do you suggest is most suitable to use for me?

//Tony
"Robert Halford" <ro************ @tiscali.com> skrev i meddelandet
news:eY******** ******@TK2MSFTN GP02.phx.gbl...
Would it be true to say that usually the main functional difference with the protected override method vs calling a delegate is the ability to override the default behavor by returning true. This doesn't appear to be the case in this example as there is a void return value, but often protected override methods return a bool which allow you to do this, and you just can't do that with the delegate.

"tony" <jo************ *****@telia.com > wrote in message
news:O$******** ******@TK2MSFTN GP04.phx.gbl...
Hello!

What is the differens if I use event handler onSizeChanged compare to
using
the other event handler MeltPracForm_Si zeChanged.
I see both as event handler is that right?
I catch the event in both cases. So is it more or less the same thing
which
of these two event handler I use.

protected override void OnSizeChanged(E ventArgs e)
{
...
}
private void MeltPracForm_Si zeChanged(objec t sender, System.EventArg s e) {
...
}

//Tony




May 15 '06 #7
"Tony Johansson" <jo************ *****@telia.com > wrote:
I just wonder which of these two methods is most suitable to use in this
circumstances
when the main application window form is minimized I will minimize
all window forms that the main window form has made visible.
If you're just trying to implement an event in the user interface, I
recommend that you go with the event handler. The designer surface knows
more about it:
private void MeltPracForm_Si zeChanged(objec t sender, System.EventArg s e)


-- Barry
May 15 '06 #8

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

Similar topics

1
3033
by: Steve | last post by:
I've run in to a problem with a query I'm trying to write. I have attached a sample SQL script at the end of this post to show an overview of what I'm working with. I want to be able to use LIMIT to control how many rows from one table are returned, independent of how many rows there are in a second table that is joined to the first. ...
2
5755
by: James Nicholas | last post by:
I have the below code in a form to re-form the characters entered into it into a dollar amount and also only accept numeric characters. However, when I enter the numbers "113" (which appears after the reformatting process as 1.13), it no longer accepts any other characters. I also am not able to deleted from the text box that I entered it...
20
3298
by: Olav.NET | last post by:
I am a .NET/C++ developer who is supposed to do some work with Access. I do not know much about it except for the DB part. Questions: *1* I am looking for INTENSIVE books to get quickly up to speed. I like books with practical exercises, and also with test questions (like cert books) *2*
6
1340
by: Flare | last post by:
Hi i have a qusstion about events and delegates. Especially the precis role of the Event. Eg. We have a class wich want to fire events so we declare: public delegate void TestEventHandler(object sender, EventArgs arg); public event TestEventHandler Test; And fire the event with
9
1818
by: Peter Krikelis | last post by:
Hi, Finally figured events and delegates whew! Thanks to the people in this community that helped me out. So now I have a class that raises an event. Now if I instantiate an object array of that class, and the event fires, is there any way of getting the array index of the object that raised that event?
3
2601
by: Minh Khoa | last post by:
Please give me more information about delegate and its usage? Why do i use it and when?
2
3896
by: Kool-Aide | last post by:
Alright, here goes...When I put a menu strip on the windows form I can double click the exit button to go to the source page and it takes me to the on click exit blah blah blah and you would put Application.Exit(); Alright well what would I put for the print preview and the print and Save and saveas and open and new? I can't find anything for...
3
1363
by: Tony | last post by:
Hello! Is it the normal procedure in C# and .NET framework to always use the actual event object which is passed as the second parameters to the event handler. All of them are derived from the base class which is EventArgs so because of this the second parameters could in all cases be EventArgs which had be be cased in the most cases to...
3
1991
by: Tony | last post by:
Hello! One more thing assume I create an event and an object derived from the eventArgs containing some info about the event. Then create another event also with an object derived from the eventArgs containing some info about the event. When creating the event handler I have two choices either use EventArgs as the second parametr and...
8
4256
by: Tony Johansson | last post by:
Hello! I wonder can somebody explain when is it suitable to use these methods OnKeyUp, OnKeyDown and OnKeyPress because these raise an event. These are located in class UserControl. If these raise an event how do I create an handler to catch these raised events. //Tony
0
7496
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, 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...
0
7941
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7452
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...
0
6014
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5354
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5071
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...
0
3485
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...
0
3467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1916
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 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.