简体   繁体   English

如何在用户控件上激活 Click 事件?

[英]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.我有一个自定义创建的用户控件,其中包含 label 和一个图片框,我将在表单中将其用作按钮。 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.问题是,当我向UC_Click事件添加操作并运行应用程序时,我单击它时无法识别。 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;我看到了标签 winforms 所以我写了这个希望它有帮助;

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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