2015-04-14 82 views
0

自動向下的DateTimePicker在Vb.net通過各種我不得不用非常令人沮喪vb.net DateTimePicker控件,在更令人沮喪的Citrix客戶端,爲應用程序的原因。這實際上不是我的主要問題,問題是,當用戶按下任何按鈕時(除tab,escape等外),我必須使datetimepicker自動下拉。如何通過Citrix客戶端

我真的需要得到這個工作,用戶不會真的拿不出一個答案。我寧願不要獲得新的自定義控件,但是如果存在易於實現的控件(並且不允許用戶輸入日期),那麼我會對它開放。

這是我做了什麼,到目前爲止,它工作得很好之外思傑的,但是當它在思傑觸發,當用戶導航周圍的的DateTimePicker不會刷新。意思是方塊在當前日期之後,並且用戶可以按箭頭鍵來查看他們心中的內容,但它從不向用戶顯示。 (即使用戶使用鼠標砸下來。)

再次思傑之外能正常工作。

'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只會下降凍結的白色背景。

有沒有人有任何想法可以幫助我在這裏?

回答

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 
+0

我能夠通過將DropDownCalendar調用切換到KeyPress事件而不是KeyDown事件來修復它。你的答案看起來不錯,但我不會嘗試它,因爲我剛剛把我的代碼推到了服務器上,而且我似乎只是越過了我的手指,因爲它似乎工作。 – Loogawa