WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

System_Window_Forms

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

DateTimePicker

 Keywords: dotNet .Net Form DateTimePicker Date Time Picker Control

;***************************************************************************
;**   Use a Windows .Net Form with a DateTimePicker Control
;**
;** Purpose: Accept DateTimePicker Input
;** Inputs:
;** Outputs: Results written to screen
;** Reference:
;**       REQUIRES WinBatch 2013A or newer
;**
;** Developer: Deana Falk 2014.03.06
;***************************************************************************
If Version( )< '2013A'
   Pause('Notice', 'Need 2013A or Newer Version of WinBatch')
   Exit
EndIf

 _True = ObjectType( 'BOOL', -1 )
 _False = ObjectType( 'BOOL', 0 )

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; ObjectClrOption - Load assembly into the WinBatch process
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ObjectClrOption( 'use', 'System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' )
ObjectClrOption( 'use', 'System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' )

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; ObjectClrNew - Create a class implemented by a managed assembly.
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Form1 = ObjectClrNew('System.Windows.Forms.Form')
Button1 =  ObjectClrNew('System.Windows.Forms.Button')
DateTimePicker1 =  ObjectClrNew('System.Windows.Forms.DateTimePicker')
; Enumerations
enumStartPos = ObjectClrNew('System.Windows.Forms.FormStartPosition')
enumDialogResult = ObjectClrNew( 'System.Windows.Forms.DialogResult')


;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Define Form1
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Set the caption bar text of the form.
Form1.Text = 'DateTimePicker1'
; Set the start position of the form to the center of the screen.
Form1.StartPosition = ObjectClrType( 'System.Windows.Forms.FormStartPosition', enumStartPos.CenterScreen ) ;CenterScreen
; Set the accept button of the form to button1.
Form1.AcceptButton = button1
; Obtain the Width of the form for later use with controls
formwidth = Form1.Width-15


;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Define DateTimePicker1
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Position  DateTimePicker1
DateTimePicker1.Location = ObjectClrNew('System.Drawing.Point',0,10)
; Define width to width of the form
DateTimePicker1.Width = formwidth
; Specify tabindex
DateTimePicker1.TabIndex  = 0
;Customize format
enumDateTimePickerFormat = ObjectClrNew( 'System.Windows.Forms.DateTimePickerFormat' )
DateTimePicker1.Format = ObjectClrType('System.Windows.Forms.DateTimePickerFormat',enumDateTimePickerFormat.Custom )
DateTimePicker1.CustomFormat = "yyyy:MM:dd:HH:mm:ss"
;DateTimePicker1.CustomFormat = "MMMM dd, yyyy - dddd"


;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Define Button1
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Set the position of the button on the form.
button1.Location = ObjectClrNew('System.Drawing.Point',100,110)
; Set the text of button1 to 'OK'.
button1.Text = 'OK'
; Specify tabindex
button1.TabIndex  = 1
; IMPORTANT: The dialog box can be assigned one of the values of the DialogResult enumeration by assigning it to the DialogResult property of a Button on the form.
button1.DialogResult = ObjectClrType( 'System.Windows.Forms.DialogResult', enumDialogResult.OK )

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Add Controls
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Form1.Controls.Add(Button1)
Form1.Controls.Add(DateTimePicker1)

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Display the form as a modal dialog box.
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ret = Form1.ShowDialog()

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Get Results
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Pause( 'Text of DateTimePicker1', DateTimePicker1.Text )


;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Clean up
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Button1.Dispose()
DateTimePicker1.Dispose()
Form1.Dispose()

Exit

Article ID:   W17847
Filename:   DateTimePicker.txt
File Created: 2014:05:09:13:13:02
Last Updated: 2014:05:09:13:13:02