简体   繁体   English

面板中的C#用户控件未收到事件

[英]C# user controls in a panel not receiving events

I'm working on a project that is requiring me to add multiple user controls to a panel. 我正在一个项目中,该项目要求我向面板添加多个用户控件。 What I would like to do with these custom controls is highlight the currently selected control and low-light the others. 我要对这些自定义控件进行的操作是突出显示当前选择的控件,而其他控件则保持低亮度。 My problem is that my custom controls aren't receiving the GotFocus/LostFocus messages. 我的问题是自定义控件没有收到GotFocus / LostFocus消息。 Am I missing something here? 我在这里想念什么吗?

This is how I'm loading my control into the panel. 这就是我将控件加载到面板中的方式。

int count = 0;
foreach(DataRow dr in ds.Tables[0].Rows)
{
    PricingModel.GUI.Controls.PriceView pv = new PricingModel.GUI.Controls.PriceView(_session, dr["product"].ToString().Trim());
    pv.Visible = true;
    pv.Top = pv.Height * count;

    _priceViewPanel.Controls.Add(pv);
    count++;
}

I'm using .Net(1.1) any help would be greatly appreciated. 我正在使用.Net(1.1),任何帮助将不胜感激。

You need to add code to actually handle those events, like this: 您需要添加代码以实际处理这些事件,如下所示:

pv.GotFocus += new EventHandler(pv_GotFocus);
pv.LostFocus += new EventHandler(pv_LostFocus);

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

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