由于各种原因,我被迫使用令人难以置信的令人沮丧的vb.net DateTimePicker控件,在更令人沮丧的Citrix客户端中,用于应用程序。这实际上不是我的主要问题,问题是,当用户按下任何按钮时(除了tab,escape等),我必须使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中甚至可以实现这样的功能吗?在之前的尝试中,我使用了在Citrix之外运行良好的SendKeys(“{F4}”),但在Citrix中只会降低冻结的白色背景。
有没有人有任何可以帮助我的想法?
答案 0 :(得分:1)
有时我们在Citrix上托管的VB应用程序中发送此类消息时必须添加DoEvent。看看这是否适合你:
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