Creating GUI for DateTime Picker output to CSV file



  • Hi, I am creating a GUI for end user to input date & time which will be output to CSV.
    I am currently coding this on PowerShell since I am using $env:username so to identify who's requesting for audit purpose.

    While PowerShell has DateTimePicker, it looks old. This is what I found on a quick search
    0_1519754149618_484d2cd5-6a97-445e-83f5-19a2e75b825d-image.png

    However, I want something more cleaner like this Time Picker
    0_1519754214927_fcf78714-8d51-4001-84fa-7d43fd84c5ef-image.png

    Any idea how can I use this XAML(not sure what this mean.. still researching more on it) in PowerShell?



  • You can easily change the colors of this time picker from the script. Try the below.

    ###########################################################
    # TimeFramePicker.ps1
    #
    # MeneerB 29/07/2015
    ###########################################################
    Add-Type -AssemblyName System.Windows.Forms
    
    # Main Form
    $mainForm = New-Object System.Windows.Forms.Form
    $font = New-Object System.Drawing.Font(“Consolas”, 13)
    $mainForm.Text = ” Pick Time Frame”
    $mainForm.Font = $font
    $mainForm.ForeColor = “Black”
    $mainForm.BackColor = “White”
    $mainForm.Width = 300
    $mainForm.Height = 200
    
    # DatePicker Label
    $datePickerLabel = New-Object System.Windows.Forms.Label
    $datePickerLabel.Text = “date”
    $datePickerLabel.Location = “15, 10”
    $datePickerLabel.Height = 22
    $datePickerLabel.Width = 90
    $mainForm.Controls.Add($datePickerLabel)
    
    # MinTimePicker Label
    $minTimePickerLabel = New-Object System.Windows.Forms.Label
    $minTimePickerLabel.Text = “min-time”
    $minTimePickerLabel.Location = “15, 45”
    $minTimePickerLabel.Height = 22
    $minTimePickerLabel.Width = 90
    $mainForm.Controls.Add($minTimePickerLabel)
    
    # MaxTimePicker Label
    $maxTimePickerLabel = New-Object System.Windows.Forms.Label
    $maxTimePickerLabel.Text = “max-time”
    $maxTimePickerLabel.Location = “15, 80”
    $maxTimePickerLabel.Height = 22
    $maxTimePickerLabel.Width = 90
    $mainForm.Controls.Add($maxTimePickerLabel)
    
    # DatePicker
    $datePicker = New-Object System.Windows.Forms.DateTimePicker
    $datePicker.Location = “110, 7”
    $datePicker.Width = “150”
    $datePicker.Format = [windows.forms.datetimepickerFormat]::custom
    $datePicker.CustomFormat = “dd/MM/yyyy”
    $mainForm.Controls.Add($datePicker)
    
    # MinTimePicker
    $minTimePicker = New-Object System.Windows.Forms.DateTimePicker
    $minTimePicker.Location = “110, 42”
    $minTimePicker.Width = “150”
    $minTimePicker.Format = [windows.forms.datetimepickerFormat]::custom
    $minTimePicker.CustomFormat = “HH:mm:ss”
    $minTimePicker.ShowUpDown = $TRUE
    $mainForm.Controls.Add($minTimePicker)
    
    # MaxTimePicker
    $maxTimePicker = New-Object System.Windows.Forms.DateTimePicker
    $maxTimePicker.Location = “110, 77”
    $maxTimePicker.Width = “150”
    $maxTimePicker.Format = [windows.forms.datetimepickerFormat]::custom
    $maxTimePicker.CustomFormat = “HH:mm:ss”
    $maxTimePicker.ShowUpDown = $TRUE
    $mainForm.Controls.Add($maxTimePicker)
    
    # OD Button
    $okButton = New-Object System.Windows.Forms.Button
    $okButton.Location = “15, 130”
    $okButton.ForeColor = “Black”
    $okButton.BackColor = “White”
    $okButton.Text = “OK”
    $okButton.add_Click({$mainForm.close()})
    $mainForm.Controls.Add($okButton)
    
    [void] $mainForm.ShowDialog()


  • @dustinb3403 said in Creating GUI for DateTime Picker output to CSV file:

    You can easily change the colors of this time picker from the script. Try the below.

    ###########################################################

    TimeFramePicker.ps1

    MeneerB 29/07/2015

    ###########################################################
    Add-Type -AssemblyName System.Windows.Forms

    Main Form

    $mainForm = New-Object System.Windows.Forms.Form
    $font = New-Object System.Drawing.Font(“Consolas”, 13)
    $mainForm.Text = ” Pick Time Frame”
    $mainForm.Font = $font
    $mainForm.ForeColor = “Black”
    $mainForm.BackColor = “White”
    $mainForm.Width = 300
    $mainForm.Height = 200

    DatePicker Label

    $datePickerLabel = New-Object System.Windows.Forms.Label
    $datePickerLabel.Text = “date”
    $datePickerLabel.Location = “15, 10”
    $datePickerLabel.Height = 22
    $datePickerLabel.Width = 90
    $mainForm.Controls.Add($datePickerLabel)

    MinTimePicker Label

    $minTimePickerLabel = New-Object System.Windows.Forms.Label
    $minTimePickerLabel.Text = “min-time”
    $minTimePickerLabel.Location = “15, 45”
    $minTimePickerLabel.Height = 22
    $minTimePickerLabel.Width = 90
    $mainForm.Controls.Add($minTimePickerLabel)

    MaxTimePicker Label

    $maxTimePickerLabel = New-Object System.Windows.Forms.Label
    $maxTimePickerLabel.Text = “max-time”
    $maxTimePickerLabel.Location = “15, 80”
    $maxTimePickerLabel.Height = 22
    $maxTimePickerLabel.Width = 90
    $mainForm.Controls.Add($maxTimePickerLabel)

    DatePicker

    $datePicker = New-Object System.Windows.Forms.DateTimePicker
    $datePicker.Location = “110, 7”
    $datePicker.Width = “150”
    $datePicker.Format = [windows.forms.datetimepickerFormat]::custom
    $datePicker.CustomFormat = “dd/MM/yyyy”
    $mainForm.Controls.Add($datePicker)

    MinTimePicker

    $minTimePicker = New-Object System.Windows.Forms.DateTimePicker
    $minTimePicker.Location = “110, 42”
    $minTimePicker.Width = “150”
    $minTimePicker.Format = [windows.forms.datetimepickerFormat]::custom
    $minTimePicker.CustomFormat = “HH🇲🇲ss”
    $minTimePicker.ShowUpDown = $TRUE
    $mainForm.Controls.Add($minTimePicker)

    MaxTimePicker

    $maxTimePicker = New-Object System.Windows.Forms.DateTimePicker
    $maxTimePicker.Location = “110, 77”
    $maxTimePicker.Width = “150”
    $maxTimePicker.Format = [windows.forms.datetimepickerFormat]::custom
    $maxTimePicker.CustomFormat = “HH🇲🇲ss”
    $maxTimePicker.ShowUpDown = $TRUE
    $mainForm.Controls.Add($maxTimePicker)

    OD Button

    $okButton = New-Object System.Windows.Forms.Button
    $okButton.Location = “15, 130”
    $okButton.ForeColor = “Black”
    $okButton.BackColor = “White”
    $okButton.Text = “OK”
    $okButton.add_Click({$mainForm.close()})
    $mainForm.Controls.Add($okButton)

    [void] $mainForm.ShowDialog()

    Not the color, the the whole scrolling thing. instead of clicking up and down or type in, I like it to be all mouse like in the second picture.



  • I doubt that powershell will be pretty like that. It's process driven not gui driven.



  • 😢 Old school style it is then.
    Thanks!



  • Added a PowerShell tag.



  • @stess https://blogs.technet.microsoft.com/platformspfe/2014/01/20/integrating-xaml-into-powershell/ look at this. It gives the basics of integrating XAML into a PowerShell script and might be right what you are looking for.


Log in to reply