Click here to Skip to main content
15,887,477 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: How do I execute a class from a class? Pin
Charlie Williams31-Jan-05 11:38
Charlie Williams31-Jan-05 11:38 
GeneralRe: How do I execute a class from a class? Pin
DSLR31-Jan-05 11:47
DSLR31-Jan-05 11:47 
GeneralRe: How do I execute a class from a class? Pin
Charlie Williams31-Jan-05 12:00
Charlie Williams31-Jan-05 12:00 
GeneralRe: How do I execute a class from a class? Pin
DSLR31-Jan-05 12:09
DSLR31-Jan-05 12:09 
GeneralRe: How do I execute a class from a class? Pin
Charlie Williams31-Jan-05 12:48
Charlie Williams31-Jan-05 12:48 
AnswerRe: How do I execute a class from a class? Pin
Charlie Williams31-Jan-05 13:53
Charlie Williams31-Jan-05 13:53 
GeneralRe: How do I execute a class from a class? Pin
DSLR31-Jan-05 23:58
DSLR31-Jan-05 23:58 
GeneralRe: How do I execute a class from a class? Pin
Charlie Williams1-Feb-05 4:47
Charlie Williams1-Feb-05 4:47 
DSLR wrote:
In the OnOff_ClickHandler event there the row MyArray2.Off(5)

The point I was trying to make was that the way you have it set up now Array1 has to have knowledge of Array2 (that it has an Off method or that it even exists) when it shouldn't need to. The events you mentioned are events of the individual controls in Array1. What I'm talking about defining a custom event in Array1 that could be handled in Array2.

Think about the System.Windows.Forms.Button class. It doesn't know or care about the Panel class or a custom user control you might put it in. It doesn't require a reference to the control that contains it or need to know the name of any methods the containing control defines. You can execute a block of code every time the Button is clicked by subscribing to the Click event, just as you've done.

Well, in Array2, you want to execute a block of code every time any Button is clicked on Array1. You should define an event, just like Button does, that notifies anyone that's interested when a Button is clicked. This doesn't require Array1 to have intimate knowledge of Array2. Note also that you shouldn't subscribe to the Click event of each Button in Array1 from Array2. That would require Array2 to have an inappropriate knowledge of Array1.

The changes I'm proposing may seem complicated at first, but they will simplify your code if they are implemented. You'll be free to change code, class names, method names, etc. without worry. The only thing you'll be concerned with is having Array1 shout to the world, "Hey, somebody clicked one of my buttons!" (firing an event) and having Array2 listen for that shout (subscribing to the event).

DSLR wrote:
.NET isn’t my thing. ...I give up

That's your choice, of course. Delegates and events aren't always the easiest thing to grasp at first glance. If you power through it, you'll be a better developer. It will take effort, but it's well worth it, IMO.

Here is a popular CodeProject article on events and delegates[^]. It may help the pieces fall into place and make what I'm saying start to make some sense.

Charlie

if(!curlies){ return; }
GeneralRe: How do I execute a class from a class? Pin
DSLR1-Feb-05 8:27
DSLR1-Feb-05 8:27 
QuestionInstall or at least read an HxS ? Pin
Denevers30-Jan-05 3:39
Denevers30-Jan-05 3:39 
GeneralCrystal Reports and .Net Remoting Pin
a_dipendra28-Jan-05 4:40
a_dipendra28-Jan-05 4:40 
GeneralInstalling a publisher policy into the GAC Pin
Pain_Elemental28-Jan-05 4:29
Pain_Elemental28-Jan-05 4:29 
GeneralHash Storage Problem Pin
SusmithaC28-Jan-05 1:04
SusmithaC28-Jan-05 1:04 
GeneralRe: Hash Storage Problem Pin
Philip Fitzsimons28-Jan-05 4:40
Philip Fitzsimons28-Jan-05 4:40 
General.wav files Pin
ziggy8227-Jan-05 5:11
ziggy8227-Jan-05 5:11 
GeneralRe: .wav files Pin
Corinna John31-Jan-05 21:04
Corinna John31-Jan-05 21:04 
GeneralTesting Tool for .Net Pin
Vishwanathkk27-Jan-05 2:34
Vishwanathkk27-Jan-05 2:34 
Generalstring to long Pin
zagzagzag27-Jan-05 0:46
zagzagzag27-Jan-05 0:46 
GeneralRe: string to long Pin
wyoung7631-Jan-05 23:18
wyoung7631-Jan-05 23:18 
GeneralRemoving an assembly from the GAC Pin
shayw26-Jan-05 8:24
shayw26-Jan-05 8:24 
GeneralRe: Removing an assembly from the GAC Pin
Mike Dimmick27-Jan-05 4:25
Mike Dimmick27-Jan-05 4:25 
GeneralRe: Removing an assembly from the GAC Pin
shayw27-Jan-05 19:25
shayw27-Jan-05 19:25 
GeneralRe: Removing an assembly from the GAC Pin
GuruPandian29-Jan-05 3:34
GuruPandian29-Jan-05 3:34 
GeneralAccessing "Native" DLL from a .NET App Pin
bneacetp26-Jan-05 4:04
bneacetp26-Jan-05 4:04 
GeneralRe: Accessing "Native" DLL from a .NET App Pin
zagzagzag27-Jan-05 0:41
zagzagzag27-Jan-05 0:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.