0

winForm 有一个带有 3 个 tabPages 的 TabControl。在设计器中的 tabControl 和 tabPages 之外还有 3 个不重叠的面板。

3 个 tabPages 中的每一个都包含各种控件,包括 DateTimePicker。

在运行时:

  1. 面板的大小调整为相同的范围/位置
  2. 所有控件都从 tabPage 移动到相应的面板
  3. tabControl.dispose()
  4. 用户控制面板按钮显示/隐藏 3 个面板
  5. 一切正常,datagridview 和按钮事件按预期触发。

但是, dateTimePicker.valueChangd 或 dateTimePicker.closeUp 不会触发。

下面的 button.click 应该会触发,但 datetimepicker 不会触发,它们都是在设计器中以完全相同的方式创建的。

有任何想法吗?

Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
    msgbox("val changed")
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    refreshTable()
End Sub

以下是控件在加载时的移动方式:

'change size and location of hidden panels (modules) on load
    userPanel.Size = TabControl1.Size
    userPanel.Location = TabControl1.Location

    ongoingPanel.Size = TabControl1.Size
    ongoingPanel.Location = TabControl1.Location

    archivePanel.Size = TabControl1.Size
    archivePanel.Location = TabControl1.Location

    'key=>value that will hold control=>panel string
    Dim ctrlArr As New Dictionary(Of Object, String)

    'loop over tabPages and add child controls to array as key with panel they belong to as value
    For Each tp As TabPage In TabControl1.TabPages
        For Each ctrl As Control In tp.Controls
            If tp.Name = "TabPage1" Then
                ctrlArr.Add(ctrl, "archivePanel")
            ElseIf tp.Name = "TabPage2" Then
                ctrlArr.Add(ctrl, "ongoingPanel")
            ElseIf tp.Name = "TabPage3" Then
                ctrlArr.Add(ctrl, "userPanel")
            End If
        Next
    Next

    For Each ct As Control In ctrlArr.Keys
        Dim panel As Panel = CType(Me.Controls(ctrlArr.Item(ct)), Panel)
        'move the control to paired panel
        ct.Parent = panel
    Next

    'destroy tabs, they are only for design
    TabControl1.Dispose()
4

0 回答 0