Solved

How do I add an event to a user created partial class?

Posted on 2009-05-12
2
210 Views
Last Modified: 2013-12-17
In C #, I generated a partial class of a windows form. I placed the event handlers in the user created partial class. VS usually adds the event handler in a created partial class that contains the constructor. I would like to know how i should add the event handler to the event of the button seeing as its not possible using the properties tab.

I hope my question is clear
0
Comment
Question by:SarahAm
2 Comments
 
LVL 3

Accepted Solution

by:
demi-os earned 250 total points
ID: 24372209
to add an event from the form to another class you can do:
     
private void Form1_Load(object sender, EventArgs e)
{
            SomeClass sc = new SomeClass();
            button1.Click += new EventHandler(sc.button1_click);
 }

where SomeClass is something like this:
    class SomeClass
    {
        public void button1_click(object sender, EventArgs e)
        {
            MessageBox.Show("button1 click");
        }
    }
0
 

Author Closing Comment

by:SarahAm
ID: 31580860
Thank You
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question