473,322 Members | 1,241 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.

EventHandler outside of class

Hi,

Is it possible to get an EventHandler to be called outside of the class
where a control is instantiated?

For example, I would like to create a button at runtime and have it call a
function in another class if it is clicked.

Any hints would be greatly appreciated

Thanks

Dunster
Nov 15 '05 #1
3 3154
have a look at remote events

"Dunster" <no****@nospam.ns> wrote in message
news:#T**************@TK2MSFTNGP11.phx.gbl...
Hi,

Is it possible to get an EventHandler to be called outside of the class
where a control is instantiated?

For example, I would like to create a button at runtime and have it call a
function in another class if it is clicked.

Any hints would be greatly appreciated

Thanks

Dunster

Nov 15 '05 #2
Lucean Morningside wrote:

Thank you for taking the time to reply and especially the sample code.

When you talk about design patterns, where can I learn more about these? Are
you talking about books that are dedicated to design patterns? I'm quite
new to C# but have coded extensively in C but of course C# is object
oriented and quite a bit different.

TIA for any info on design patterns.

Dunster
class MyEventObserver
{
public void clickEventHandler( object src, EventArgs args )
{
// your even handling code here
}
}

class MyForm
{
private MyEventObserver m_observer = new MyEventObserver();
private Button m_dynamicButton = null;

.
.
.

public void CreateAndBindButton()
{
m_dynamicButton = new Button( ... );
m_dynamicBytton.Click += new EvenHandler(
m_observer.clickEventHandler );
}
}

So, yes. It can be done. There's even a whole design parttern dedicated to
this behavior: the Observer pattern, and the closely related
Model-View-Controller (MVC) pattern.

-LM


Nov 15 '05 #3
Thank you Alvin!

Alvin Bruney wrote:
patterns are a way of lumping programming best practices into a strategy
for better software development. have a read at (watch for line wrap)
http://msdn.microsoft.com/vbasic/usi...ctopattern.asp


Nov 15 '05 #4

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

Similar topics

7
by: Rim | last post by:
Hi, It appears to me the simplest way to add a function to a class outside of the class declaration is as follows: >>> class a(object): .... pass .... >>> def f(self): .... print 'hi'
3
by: Kevin Bowser | last post by:
I am having trouble updating the text in a C# form textbox from outside the class. Calling function ChangeDisplay from inside the class ControlPanel works fine, but when I call it from the main...
5
by: Felix I. Wyss | last post by:
Good Afternoon, I recently noticed that some very simple methods of a template declared and used in a DLL library get inlined when used by the DLL itself, but not by other DLLs and EXEs. After...
8
by: reviswami78 | last post by:
Hi : I wanted to know if the following is possible in C# ( .NET Framework 1.x): I want to add an attribute to a class in a separate file i.e. in a file other than which the class itself is...
1
by: ypjofficial | last post by:
Hi all, what's difference does it make when we define the member function inside and outside a class? I am using vc7. when i define the member functions outside a class with the scope...
5
by: Ben | last post by:
Hello I have a protected variable in a class (Class A) that I need to call from another class (Class B) to modify. I thought what I had to do was create a public method in the class (Class A)...
8
by: Masterfrier | last post by:
Hello Experts! ;-) I am fairly new to C#, and have this problem.... on my form, i have some controls (imagelist, etc..) from another class, i need to access imageList1 Here is a snippet...
2
cornfed
by: cornfed | last post by:
I've got a class to make Templates for different repeaters in my page. in one of these repeaters a linkbutton is needed. This LinkButton needs an event that is in a .cs file somewhere else in the...
3
card
by: card | last post by:
Ah, the joy of generic programming. Ok. Here's my problem. I have a templated class with a internally defined structure type. Within the class, I have some member functions whose return value is...
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...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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.