简体   繁体   中英

How to activate the Click event on a User Control?

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);
}

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.
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM