0

I have a user control with a label set as Dock Fill. I have created the Click event of the User control as well as of the label:

 private void Cell_Click(object sender, EventArgs e)
        {
            if (this.ClickCount == 0)
            {
                this.ClickCount = 1;
                this.SetSeat_Male();
            }
            else if (this.ClickCount == 1)
            {
                this.ClickCount = 2;
                this.SetSeat_Female();
            }
            else if (this.ClickCount == 2)
            {
                this.ClickCount = 0;
                this.SetSeat_Empty();
            }
        }
        private void lblSeatNo_Click(object sender, EventArgs e)
        {
            Cell_Click(sender, e);
        }

I am using this user control on another form, but the click event of this user control on form is not calling the click event of the cell in this user control. How can i call this click event on my form?

Usman Farooq
  • 109
  • 3
  • 11
  • you should change Cell_Click to be a normal subroutine, instead of a event handler, so change to, private void Cell_Click() {..} – Joseph Wu Apr 28 '18 at 10:27
  • @JoeWu can you please explain? – Usman Farooq Apr 28 '18 at 10:39
  • the click event is handled by 'lblSeatNo_Click' already, it is not necessary to call what seems to be another handler ( actually delete Cell_click method, and place its content directly inside 'lblSeatNo_Click' – Joseph Wu Apr 28 '18 at 10:43
  • but then i need to make this label public (so that i can access its event in the form where i use this control)??? – Usman Farooq Apr 28 '18 at 11:01
  • i see your point, make sure to set parent form's 'keypreview' property to 'true'. please check this https://stackoverflow.com/questions/22782753/how-to-get-all-keypress-events-as-a-usercontrol-in-c – Joseph Wu Apr 28 '18 at 11:13
  • i am not handling key press event.. i am trying to handle Mouse-Click and Click Event to supprot Touch-Screen as well. – Usman Farooq Apr 28 '18 at 11:16

0 Answers0