Leefri

Hi there

A repost as I didn't get a clear answer.

I would like to know is this the right way of calling a class from an event like clicking on a form button. Is this the OO way or is there a better way

I'm creating this basic task list application which shows just a listbox and an add button on a form.

I have under the TaskList Namespace

  • public partial class Form1 : Form

  • static class Program

  • class TaskList

I want an event that when I click on the button it will kick off an event in the TaskList class. When I click on the button to create the event (in Visual C# Express) it creates the event within the form and not my TaskList class.

How can I make the event appear in my class (I assume I redirect / change the name to a method in my class).

Thanks

F.C.



Re: Windows Forms General Button Event and calling a class

Matthew Watson

In the code for the button handler in your form, just call the appropriate method in your TaskList class.

You don't need another event in yout TaskList class, just a method you can call.






Re: Windows Forms General Button Event and calling a class

Friendlycoder

Hi

So when my application loads, I will need to create an instant of my class TaskList, then call the method from it to display the list. Correct

Apologies, I'm working on my first proper C# application using OO methodology so it very different from procedural.

- Sorry for the dup thread.





Re: Windows Forms General Button Event and calling a class

Matthew Watson

That is correct.





Re: Windows Forms General Button Event and calling a class

Friendlycoder

Thanks.

I'm realising that reading and programming OO are two different things.