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

onLoad でコントロールを移動する方法は次のとおりです。

'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