简体   繁体   English

从类本身引发自定义控件的事件

[英]Raise event of customized control from class itself

I have a custom TabPage class: 我有一个自定义的TabPage类:

class CustomTabPage : TabPage
{
    TextBox tbCode = new TextBox();

    public CustomTabPage()
    {

    }

    public CustomTabPage(string title)
    {
        tbCode.Multiline = true;
        tbCode.Size = this.Size;  
    }        

    //Something like this...
    private void OnThisControlSizeChanged()
    {
        tbCode.Size = this.Size;
    }
}

What I need for this class is to raise the OnSizeChanged event of the TabPage control when I resize it from where I create the control. 我需要的此类是在从创建控件的位置调整它的大小时引发TabPage控件的OnSizeChanged事件。 The reason for this is when I resize the TabPage control, I want to adapt the TextBox size accordingly so that they stay the same. 原因是当我调整TabPage控件的大小时,我想相应地调整TextBox大小,以便它们保持不变。

class CustomTabPage : TabPage
{
    TextBox tbCode = new TextBox();
    public CustomTabPage()
    {
        SizeChanged += CustomTabPage_SizeChanged;
    }

    void CustomTabPage_SizeChanged(object sender, EventArgs e)
    {
        OnThisControlSizeChanged();
    }

    public CustomTabPage(string title)
    {
        tbCode.Multiline = true;
        tbCode.Size = this.Size;
    }

    private void OnThisControlSizeChanged()
    {
        tbCode.Size = this.Size;
    }
}
this.OnSizeChanged(new EventArgs());

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

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