none
Passing argument from user control's event to the parent Form RRS feed

  • Question

  • I want pass argument from user control's event from the parent form.

    Here is the code snippet of the user control.

    public class ConfigDeviceControlEventArgs : EventArgs
    {
        private int m_selectedtabindex;
        public int SelectedTabIndex 
        {
            get { return m_selectedtabindex; }
            set { m_selectedtabindex = value; }
        }
    }

    public partial class ChildConfigDeviceControl : UserControl { public event EventHandler <ConfigDeviceControlEventArgs> TabControlDeviceSelectedIndexChanged; protected virtual void OnTabControlDeviceSelectedIndexChanged(ConfigDeviceControlEventArgs e) { EventHandler<ConfigDeviceControlEventArgs> handler = TabControlDeviceSelectedIndexChanged; if (handler != null) handler(this, e); } protected virtual void tabControlDevice_SelectedIndexChanged(object sender, ConfigDeviceControlEventArgs e) { e.SelectedTabIndex = tabControlDevice.SelectedIndex; OnTabControlDeviceSelectedIndexChanged(e); } . . .

    And here is the parent form's code.

    <Degigner>
    this.tabControlDevice.SelectedIndexChanged += new System.EventHandler<ConfigDeviceControlEventArgs>(this.tabControlDevice_SelectedIndexChanged);
    
    <Form>
    private void MyConfigDeviceControl1_TabControlDeviceSelectedIndexChanged(object sender, ConfigDeviceControlEventArgs e)
    {
        int tabpage;
        tabpage = e.SelectedTabIndex;
    }

    However, an error occurs at Designer code's "this.tabControlDevice_SelectedIndexChanged" like following.

    Cannot implicitly convert type 'System.EventHandler<ConfigDeviceControlEventArgs>' to 'System.EventHandler'.....	
    Can anybody help me to fix this error?



    • Edited by Jeff0803 Monday, November 19, 2018 8:24 PM
    Monday, November 19, 2018 8:23 PM

Answers