如何通过 Citrix 客户端自动下拉 Vb.net 中的 DateTimePicker

How to automatically drop down DateTimePicker in Vb.net through a Citrix client

由于各种原因,我不得不在更令人沮丧的 Citrix 客户端中为应用程序使用令人难以置信的令人沮丧的 vb.net DateTimePicker 控件。这实际上不是我的主要问题,问题是,我必须让 datetimepicker 在用户按下任何按钮(除了 tab、escape 等)时自动下拉。

我真的需要让它工作,用户不会真的拒绝。我宁愿不获得新的自定义控件,但如果存在一个易于实现的控件(并且不允许用户输入日期),那么我会接受它。

这是我到目前为止所做的,它在 Citrix 之外运行得非常好,但是当它在 Citrix 中触发时,当用户在它周围导航时 DateTimePicker 不会刷新。这意味着正方形超过了当前日期,用户可以按箭头键找到他们想要的内容,但它永远不会向用户显示。 (即使用户使用鼠标将其放下。)

同样在 Citrix 之外,这工作正常。

'Used to manually dropdown datetimepickers
Private dateTimePickerControl As DateTimePicker
Private Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr


Public Sub DropDownCalendar()
    Const WM_LBUTTONDOWN As Int32 = &H201
    Const WM_LBUTTONUP As Int32 = &H202

    Dim x As Integer = Me.dateTimePickerControl.Width - 10
    Dim y As Integer = CInt(Me.dateTimePickerControl.Height / 2)
    Dim lParam As Integer = x + y * &H10000

    'click down, and show the calendar
    SendMessage(Me.dateTimePickerControl.Handle, WM_LBUTTONDOWN, CType(1, IntPtr), CType(lParam, IntPtr))

    'Click-up, and activate the calendar (without this the calendar is shown, but is not active, and doesn't work as expected)
    SendMessage(Me.dateTimePickerControl.Handle, WM_LBUTTONUP, CType(1, IntPtr), CType(lParam, IntPtr))
End Sub


Private Sub dteDate_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles dteDate.KeyDown
    Try
        If e.KeyCode = Keys.Delete Then
            sender.customFormat = " "
            e.Handled = True
        ElseIf e.KeyCode <> Keys.Tab And e.KeyCode <> Keys.ShiftKey Then
            sender.focus()
            dateTimePickerControl = sender
            DropDownCalendar()
        End If
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
End Sub

我完全不知所措。这样的事情在 Citrix 中甚至可能吗?在之前的尝试中,我使用了 SendKeys("{F4}"),它在 Citrix 之外运行良好,但在 Citrix 中只会掉落冻结的白色背景。

有没有人有任何想法可以帮助我解决这个问题?

有时我们在 Citrix 上托管的 VB 应用程序中发送此类消息时必须添加 DoEvents。看看这是否适合你:

Private Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr

Private Sub DropDownCalendar(ctl As DateTimePicker)
    Const WM_LBUTTONDOWN = &H201
    Const WM_LBUTTONUP = &H202

    If ctl Is Nothing Then
        Exit Sub
    End If

    ctl.Select()

    Dim lParam = (ctl.Width - 10) + (CInt(ctl.Height / 2) * &H10000)

    'click down, and show the calendar
    SendMessage(ctl.Handle, WM_LBUTTONDOWN, CType(1, IntPtr), CType(lParam, IntPtr))

    Application.DoEvents()

    'Click-up, and activate the calendar (without this the calendar is shown, but is not active, and doesn't work as expected)
    SendMessage(ctl.Handle, WM_LBUTTONUP, CType(1, IntPtr), CType(lParam, IntPtr))
End Sub

Private Sub dteDate_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles dteDate.KeyDown
    Try
        If e.KeyCode = Keys.Delete Then
            CType(sender, DateTimePicker).CustomFormat = " "
            e.Handled = True
        ElseIf e.KeyCode <> Keys.Tab And e.KeyCode <> Keys.ShiftKey Then
            DropDownCalendar(CType(sender, DateTimePicker))
        End If
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
End Sub