0

I have a custom created user control with a label and a picture box, which I will be using as a button in a form. The problem is that when I add an action to the UC_Click event and run the application I doesn't recognize when I click it. Is there a fix for this?

private void OpenChildForm(Form childForm, Panel panelTab)
{
    if (currentChildForm != null)
    { currentChildForm.Close(); }
    currentChildForm = childForm;
    childForm.TopLevel = false;
    childForm.FormBorderStyle = FormBorderStyle.None;
    childForm.Dock = DockStyle.Fill;
    panelTab.Controls.Add(childForm);
    panelTab.Tag = childForm;
    childForm.BringToFront();
    childForm.Show();
}

private void UCDepartment_Click_1(object sender, EventArgs e)
{
    OpenChildForm(new AdministratorChildForms.DepartmentManagment(), panelTab);
}
Ramil Aliyev 007
  • 4,437
  • 2
  • 31
  • 47
  • 1
    Please show exactly what you did. Is [this](https://stackoverflow.com/q/9677062/1997232) the same problem? – Sinatr Apr 01 '21 at 07:28
  • If you click on a child control on the user control, I believe the child control's click event will be triggered, rather than the control's click event. – ProgrammingLlama Apr 01 '21 at 07:31
  • Is there a way around that? Because my goal is to have multiple of them and for each one to open a different form – jokrastanov Apr 01 '21 at 07:34

1 Answers1

0

I saw the tag winforms so i wrote this hope it helps;

public class Customized :UserControl
{
    public PictureBox pic { get; set; }
    public Label label { get; set; }
    public Customized()
    {
        pic.Click += Pic_Click;

    }

    private void Pic_Click(object sender, EventArgs e)
    {
        // SomeEvent.
    }
}
EL Khayar
  • 11
  • 4