Overwrite event of a control

0

I have created a base form which has a control, so the forms that inherit from this base form must overwrite the Click event of this control.

Event of a control of the Base Form:

public partial class CustomFormBase : Office2007Form
{
    public CustomFormBase()
    {
        InitializeComponent();
    }

    private void bubbleBar1_ButtonClick(object sender, DevComponents.DotNetBar.ClickEventArgs e)
    {
        BubbleButton button = sender as BubbleButton;

        switch (button.Name)
        {
            case "bubbleButtonNuevo":
                MessageBox.Show("Nuevo");
                break;
            case "bubbleButtonEditar":
                MessageBox.Show("Editar");
                break;
            case "bubbleButtonGuardar":
                MessageBox.Show("Guardar");
                break;
            case "bubbleButtonBuscar":
                MessageBox.Show("Buscar");
                break;
            case "bubbleButtonEliminar":
                MessageBox.Show("Eliminar");
                break;
            case "bubbleButtonSalir":
                MessageBox.Show("Salir");
                break;
        }
    }
}

Then the form that inherits from this base has to overwrite the event, in order to create New, Edit, Save, Search, Delete, Exit .

In this image I show a form that inherits from CustomFormBase .

I need to overwrite the event that is in the form that inherits from CustomFormBase , which I show above.

public partial class Form1 : CustomFormBase
{
    public Form1()
    {
        InitializeComponent();
    }

    //Deso sobreescribir evento de control bubbleBar1_ButtonClick
}
    
asked by Pedro Ávila 28.11.2016 в 06:09
source

1 answer

1

To be able to overwrite the method, you need to define a virtual method that is not private , so that the child classes that inherit from your base class have access.

In this case, maybe the easiest thing is to create a new method with those characteristics in your base class, and that the existing bubbleBar1_ButtonClick method delegate the job to you:

public partial class CustomFormBase : Office2007Form
{
    public CustomFormBase()
    {
        InitializeComponent();
    }

    private void bubbleBar1_ButtonClick(object sender, DevComponents.DotNetBar.ClickEventArgs e)
    {
        this.ManejaButtonClick(sender as BubbleButton);
    }

    protected virtual void ManejaButtonClick(BubbleButton button)
    {
        switch (button.Name)
        {
            case "bubbleButtonNuevo":
                MessageBox.Show("Nuevo");
                break;
            case "bubbleButtonEditar":
                MessageBox.Show("Editar");
                break;
            case "bubbleButtonGuardar":
                MessageBox.Show("Guardar");
                break;
            case "bubbleButtonBuscar":
                MessageBox.Show("Buscar");
                break;
            case "bubbleButtonEliminar":
                MessageBox.Show("Eliminar");
                break;
            case "bubbleButtonSalir":
                MessageBox.Show("Salir");
                break;
        }
    }
}

Now you can write about the new ManejaButtonClick method in the child classes:

public partial class Form1 : CustomFormBase
{
    public Form1()
    {
        InitializeComponent();
    }

    protected override void ManejaButtonClick(BubbleButton button)
    {
        // ... lo que tu quieras.
    }
}
    
answered by 28.11.2016 / 17:32
source