【问题标题】:How to automatically drop down DateTimePicker in Vb.net through a Citrix client如何通过 Citrix 客户端在 Vb.net 中自动下拉 DateTimePicker
【发布时间】:2015-04-14 14:19:38
【问题描述】:

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

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

这是我迄今为止所做的,它在 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 中只会下拉冻结的白色背景。

有没有人有任何可以帮助我的想法?

【问题讨论】:

    标签: vb.net datetimepicker sendmessage citrix


    【解决方案1】:

    有时我们必须在 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
    

    【讨论】:

    • 我能够通过将 DropDownCalendar 调用切换到 KeyPress 事件而不是 KeyDown 事件来修复它。您的答案看起来不错,但我不打算尝试,因为我刚刚将代码推送到服务器,而且我只是在祈祷,因为它似乎可以工作。
    猜你喜欢
    • 2014-04-17
    • 2010-09-18
    • 1970-01-01
    • 2017-08-23
    • 1970-01-01
    • 1970-01-01
    • 2010-09-09
    • 1970-01-01
    • 2012-12-04
    相关资源
    最近更新 更多