투명은 마우스 이벤트가 아닌 그림에만 영향을줍니다. 확인란은 마우스 이벤트를 가져오고 있습니다. 즉, 확인란을 마우스로 가리키면 컨트롤이 MouseLeave 이벤트를받습니다. 자식 컨트롤 (모든 레벨에서)이 MouseEnter 이벤트를 가져 오는 경우에도 배경색이 변경되도록하려면 관심 컨트롤 또는 모든 자식, 그랜드 자식 등이 마우스 오버를 추적해야합니다. 그것. 이렇게하려면 모든 자손 컨트롤을 통해 반복하고 해당 이벤트를 차단하십시오. 이렇게하려면 아래 클래스와 비슷한 것을 시도하십시오.
public partial class MyControl : UserControl
{
public MyControl()
{
InitializeComponent();
AttachMouseEnterToChildControls(this);
}
void AttachMouseEnterToChildControls(Control con)
{
foreach (Control c in con.Controls)
{
c.MouseEnter += new EventHandler(control_MouseEnter);
c.MouseLeave += new EventHandler(control_MouseLeave);
AttachMouseEnterToChildControls(c);
}
}
private void control_MouseEnter(object sender, EventArgs e)
{
this.BackColor = Color.AliceBlue;
}
private void control_MouseLeave(object sender, EventArgs e)
{
this.BackColor = SystemColors.Control;
}
}