控制级别上的哪个事件相当于 Form.Load 事件?

Which event on a Control level is equivalent to Form.Load event?

我正在尝试在我的应用程序中创建多个自定义控件,例如:

Public Class CbsDataGridView
    Inherits DataGridView

    '...

    Private Sub CbsDataGridView_Enter(sender As Object, e As EventArgs) Handles MyBase.Enter
        'Code here omitted, not related to the question.
        LoadGrid()
    End Sub

    Private Sub LoadGrid()
        'Code here omitted, not related to the question.
    End Sub

    '...

End Class

Public Class CbsDateTimePicker
    Inherits DateTimePicker

    Private Sub CbsDateTimePicker_Enter(sender As Object, e As EventArgs) Handles MyBase.Enter
        'Code here omitted, not related to the question.
    End Sub

End Class

将这些控件添加到新的空窗体时。这是我遇到的两种情况:

场景 1:

- Drag And Drop CbsDateTimePicker into the form
- Drag And Drop CbsDataGridView into the form
- Run Application - Load The New Form
- CbsDateTimePicker_Enter event fires.
- CbsDataGridView_Enter event doesn't fire.

场景 2:

- Drag And Drop CbsDataGridView into the form
- Drag And Drop CbsDateTimePicker into the form
- Run Application - Load The New Form
- CbsDataGridView_Enter event fires.
- CbsDateTimePicker_Enter event doesn't fire.

我想我误解了控件的 Enter 事件。

我正在寻找的是一个类似于 Form.Load 事件的事件,该事件将在包含控件的表单加载时触发。

有没有直接的方法来实现这个功能?还是我应该寻找其他方式?

Enter 事件将在控件通过鼠标或键盘激活时触发。此外,只要您通过代码设置表单的活动控件,该事件就会触发。

控件没有类似于 FormLoad 事件的 Load 事件,但它们有一个虚拟的 OnCreateControl,当控件被调用时首次创建。您可以覆盖它并向该方法添加自定义逻辑,甚至可以为您的控件引发自定义 Load 事件。