我用面板和兩個標籤的組合進行了用戶控制。我在用戶控件上添加了mouseenter和mouseleave事件。我將用戶控件放在窗體上。我想在點擊控件時打開一個新窗體。但默認點擊或鼠標點擊事件不起作用。我該如何解決這個問題?如何讓用戶控件打開新窗體?
下面是用戶控件代碼:
public partial class group_control : UserControl
{
public group_control()
{
InitializeComponent();
}
public void setname(string s)
{
namelbl.Text = s;
}
public void setno(int n)
{
no_acc.Text = n.ToString();
}
private void logo_MouseEnter(object sender, EventArgs e)
{
logo.BackColor = System.Drawing.Color.Yellow;
no_acc.Visible = true;
label1.Visible = true;
namelbl.Visible = false;
}
private void logo_MouseLeave(object sender, EventArgs e)
{
logo.BackColor = System.Drawing.Color.Gray;
no_acc.Visible = false;
label1.Visible = false;
namelbl.Visible = true;
}
private void logo_Click(object sender, EventArgs e)
{
Program.cur_grp = namelbl.Text;
}
private void no_acc_Click(object sender, EventArgs e)
{
logo_Click(sender, e);
}
private void label1_Click(object sender, EventArgs e)
{
logo_Click(sender, e);
}
private void namelbl_Click(object sender, EventArgs e)
{
logo_Click(sender, e);
}
private void no_acc_MouseEnter(object sender, EventArgs e)
{
logo_MouseEnter(sender, e);
}
private void namelbl_MouseEnter(object sender, EventArgs e)
{
logo_MouseEnter(sender, e);
}
private void label1_MouseEnter(object sender, EventArgs e)
{
logo_MouseEnter(sender, e);
}
private void no_acc_MouseLeave(object sender, EventArgs e)
{
logo_MouseLeave(sender, e);
}
private void label1_MouseLeave(object sender, EventArgs e)
{
logo_MouseLeave(sender, e);
}
private void namelbl_MouseLeave(object sender, EventArgs e)
{
logo_MouseLeave(sender, e);
}
}
這裏是用戶控件Click事件代碼:
private void group_control1_Click_1(object sender, EventArgs e)
{
new view_record().Show();
}
修剪的代碼。所有那些MouseLeave事件都需要我們來看待這個問題嗎?把一個調試器停在點擊線上,看看它是否觸發。 – LarsTech
您是否點擊了在您的用戶控件中添加的面板或標籤? –
@ user12572我點擊面板。 –