Q: Unable to register click event from composite control to parent form What I am attempting to do is create a complex control that has a picture box, track slider and numeric up down controls. In the parent form, when the user clicks on an image, then this composite control appears and the background color is then sent to it and the image in the control is then set with that background color. Then if the user clicks on the image on the composite control, the parent form is then notified of the click event and then subsequently removes that specific composite control from the parent form.
Composite Control code
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace ctlClusterControlLib
{
    public partial class UserControl1 : UserControl
    {
        private Color colImageBackground;
        private int intThreadCount;
        private PictureBox pictureBoxControl; // Compiler informs me that this is never assigned to and will always have its default value null.
        private TrackBar trackBar;            // Compiler informs me that this is never assigned to and will always have its default value null.
        private NumericUpDown numericUpDown;  // Compiler informs me that this is never assigned to and will always have its default value null.
        private string strImageToolTip1;
        private string strImageToolTip2;

        private static object EventSubmitKey = new object();

        public UserControl1()
        {
            InitializeComponent();
        }

        public Color ImageBackground
        {
            get { return colImageBackground; }
            set { colImageBackground = value; Invalidate(); }
        }

        public int ThreadCount
        {
            get { return intThreadCount; }
            set { intThreadCount = value; }
        }

        [
            Category("Action"),
            Description("Raised when the user clicks on the image.")
        ]
        public event EventHandler PictureClick
        {
            add { Events.AddHandler(EventSubmitKey, value); }
            remove { Events.RemoveHandler(EventSubmitKey, value); }
        }

        public event EventHandler TrackBarScroll
        {
            add { trackBar.Scroll += value; }
            remove { trackBar.Scroll -= value; }
        }

        public event EventHandler numericUpDownChange
        {
            add { numericUpDown.ValueChanged += value; }
            remove { numericUpDown.ValueChanged -= value; }
        }

        public string ImageToolTip1
        {
            get { return strImageToolTip1; }
            set { strImageToolTip1 = value; }
        }

        public string ImageToolTip2
        {
            get { return strImageToolTip2; }
            set { strImageToolTip2 = value; }
        }

        private void trackBar1_Scroll(object sender, EventArgs e)
        {
            numericUpDown1.Value = trackBar1.Value;
        }

        private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
            trackBar1.Value = Convert.ToInt32(numericUpDown1.Value);
        }

        protected override void OnPaint(PaintEventArgs pe)
        {
            base.OnPaint(pe);
            Color c = Color.FromArgb(0xFF, colImageBackground);
            pictureBox1.BackColor = c;
        }
    }
}

Parent Form CS relevant section:
    private void newPictureBox_Click(object sender, EventArgs e)
    {
        UserControl1 _UserControl = new UserControl1();
        PictureBox _PictureBox = (PictureBox)sender;
        string _NewControlClusterName = "_New" + _PictureBox.Name;

        _UserControl.Name = _NewControlClusterName;
        _UserControl.ThreadCount = 16;
        _UserControl.ImageBackground = _PictureBox.BackColor;
        _UserControl.Dock = DockStyle.Top;

        _UserControl.PictureClick += new EventHandler(ClusterControl_Click);
        //_UserControl.TrackBarScroll += new EventHandler(GetTartanCode);

        panel3.Controls.Add(_UserControl);
        panel3.Controls.SetChildIndex(_UserControl, 0);
    }

And I am having intermittent issues with raising the click event to the parent form using this control.
I have tried everything I can find in Google and Stack Overflow with no joy. My questions are this:


*

*Am I even in the right ballpark?

*Is this something that needs to be coded in the parent form cs file?

*Is this something that needs to be reconfigured in the composite control cs file?

*Is this something that needs to be configured in both files?


A: I believe I have a solution.
What I was not doing was directly assigning the request to the control I wanted to register the event for. Instead I was assigning it to a new control and therefore nothing would happen.
public event EventHandler PictureClick
{
    add { pictureBox1.Click += value; }
    remove { pictureBox1.Click -= value; }
}

And so far, It works every time.
