如何覆盖子类中的基类事件 [英] how to overide the base class event in the child class

查看:71
本文介绍了如何覆盖子类中的基类事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我们在子窗体中放置任何文本框,我有一个文本框deleclared不允许任何特殊字符。但有一种情况我不会检查基类事件。我可以覆盖子类中的基类事件,以便表单不应该为指定的文本框获取基类事件



以下是示例代码

基本形式我有



public static void SetCustomDisabled {

textbox.ParseEditValue + = new ConvertEditValueEventHandler(ParseEditValue)

}



私有空memo_ParseEditValue(对象发件人,

.ConvertEditValueEventArgs e)

{

e.Value = false;





}



先谢谢

Hi i have an event deleclared for text box not to allow any special characters,if we place any textbox in the child forms.but there is one case where I have not to check for the base class event .how can i overide the base class event in the child class so that the form should not take the base class event for the specified text box

following is the sample code
in base form i have

public static void SetCustomDisabled{
textbox.ParseEditValue += new ConvertEditValueEventHandler(ParseEditValue)
}

Private void memo_ParseEditValue(object sender,
.ConvertEditValueEventArgs e)
{
e.Value = false;


}

Thanks in advance

推荐答案

试试这个

try this
Private void memo_ParseEditValue(object sender, 
.ConvertEditValueEventArgs e)
{
if (sender.ToString().Contains("textbox1"))//your control name which you dont want to handle
            {

            }
            else
            {
                e.Value = false;            
            }
 

}


只需附上你想做的工作,我很困惑通过覆盖注释,因为您没有覆盖任何内容,您正在附加一个事件。只需附加一个不同的方法来处理特殊文本框的事件。



创建一个额外的方法,连同您的原始文件,以处理特殊文本框的事件,就像这样......

Just attach the event you want to do the work, I am confused by the override comment as you are not overriding anything, you are attaching an event. Just attach a different method to handle the event for the 'special' text box.

Create an additional method, along with your original, to handle the special text box's event, like so...
Private void memo_ParseEditValue(object sender,ConvertEditValueEventArgs e)
{
    // do something to original text box
    e.Value = false;
}

Private void memo_SpecialParseEditValue(object sender,ConvertEditValueEventArgs e)
{
    // do something different for the special text box
}





然后附上新方法来处理特殊文本框,就像这样...



Then attach the new method to handle the special text box, like so...

public static void SetCustomDisabled
{
    // attach to original text box
    textbox.ParseEditValue += new ConvertEditValueEventHandler(memo_ParseEditValue)

    // attach different method to the special text box
    textboxSpecial.ParseEditValue += new SpecialConvertEditValueEventHandler(memo_SpecialParseEditValue)
}


这篇关于如何覆盖子类中的基类事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆