Click here to Skip to main content
16,011,702 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to handle a User Control Event ? Pin
Pankaj Nikam18-Mar-09 21:21
professionalPankaj Nikam18-Mar-09 21:21 
AnswerRe: How to handle a User Control Event ? Pin
dan!sh 18-Mar-09 21:45
professional dan!sh 18-Mar-09 21:45 
GeneralRe: How to handle a User Control Event ? Pin
Pankaj Nikam19-Mar-09 7:21
professionalPankaj Nikam19-Mar-09 7:21 
AnswerRe: How to handle a User Control Event ? Pin
DaveyM6919-Mar-09 0:04
professionalDaveyM6919-Mar-09 0:04 
GeneralRe: How to handle a User Control Event ? Pin
dan!sh 19-Mar-09 2:27
professional dan!sh 19-Mar-09 2:27 
GeneralRe: How to handle a User Control Event ? Pin
DaveyM6919-Mar-09 2:53
professionalDaveyM6919-Mar-09 2:53 
GeneralRe: How to handle a User Control Event ? Pin
Pankaj Nikam19-Mar-09 7:19
professionalPankaj Nikam19-Mar-09 7:19 
GeneralRe: How to handle a User Control Event ? Pin
DaveyM6919-Mar-09 7:33
professionalDaveyM6919-Mar-09 7:33 
There's a few ways this can be done. The easiest is just to subscribe in the user control and raise a new event each time.
using System;
using System.ComponentModel;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class UserControl1 : UserControl
    {
        public event EventHandler Button1Clicked;
        public event EventHandler Button2Clicked;

        public UserControl1()
        {
            InitializeComponent();
            button1.Click += new EventHandler(button1_Click);
            button2.Click += new EventHandler(button2_Click);
        }

        protected virtual void button1_Click(object sender, EventArgs e)
        {
            EventHandler eh = Button1Clicked;
            if (eh != null)
                eh(this, e);
        }

        protected virtual void button2_Click(object sender, EventArgs e)
        {
            EventHandler eh = Button2Clicked;
            if (eh != null)
                eh(this, e);
        }

        [Browsable(false),
        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public IButtonControl AcceptButton
        {    
            get { return button1; }
        }

        [Browsable(false),
        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public IButtonControl CancelButton
        {    get { return button2; }
        }
    }
}
You now have userControl11.Button1Clicked and userControl11.Button2Clicked events available in your host form like any other control's events.

Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)

GeneralRe: How to handle a User Control Event ? Pin
Pankaj Nikam19-Mar-09 7:38
professionalPankaj Nikam19-Mar-09 7:38 
QuestionIs there a method summary snippet? Pin
12Code18-Mar-09 18:32
12Code18-Mar-09 18:32 
AnswerRe: Is there a method summary snippet? Pin
Abhijit Jana18-Mar-09 18:39
professionalAbhijit Jana18-Mar-09 18:39 
QuestionShortcut keys and macros Pin
12Code18-Mar-09 17:35
12Code18-Mar-09 17:35 
AnswerRe: Shortcut keys and macros Pin
Abhijit Jana18-Mar-09 18:21
professionalAbhijit Jana18-Mar-09 18:21 
GeneralRe: Shortcut keys and macros [modified] Pin
12Code18-Mar-09 19:01
12Code18-Mar-09 19:01 
AnswerRe: Shortcut keys and macros Pin
Pankaj Nikam18-Mar-09 18:35
professionalPankaj Nikam18-Mar-09 18:35 
GeneralRe: Shortcut keys and macros Pin
12Code18-Mar-09 19:17
12Code18-Mar-09 19:17 
GeneralRe: Shortcut keys and macros Pin
Pankaj Nikam18-Mar-09 19:36
professionalPankaj Nikam18-Mar-09 19:36 
Questionhow to join 2 tables in a data set Pin
Nine_18-Mar-09 17:31
Nine_18-Mar-09 17:31 
AnswerRe: how to join 2 tables in a data set Pin
tech60318-Mar-09 19:06
tech60318-Mar-09 19:06 
GeneralRe: how to join 2 tables in a data set Pin
Nine_19-Mar-09 1:29
Nine_19-Mar-09 1:29 
GeneralRe: how to join 2 tables in a data set Pin
tech60319-Mar-09 3:06
tech60319-Mar-09 3:06 
QuestionWindows Media Player control - suppress full screen Pin
Christian Graus18-Mar-09 16:51
protectorChristian Graus18-Mar-09 16:51 
AnswerRe: Windows Media Player control - suppress full screen Pin
ABitSmart18-Mar-09 18:05
ABitSmart18-Mar-09 18:05 
QuestionDeploy N-Tier Application... Pin
Illegal Operation18-Mar-09 12:26
Illegal Operation18-Mar-09 12:26 
QuestionMessage Removed Pin
18-Mar-09 10:59
professionalN_tro_P18-Mar-09 10:59 

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.