About:
A nice tool that i have written in PowerShell to do a simple task,To remind me stuff that i usually forget
Just type and click Save or you can also press Enter.
You can edit the code below to change the path of the file.
Enjoy!
The Code:
#region
Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
#endregion
#region
Generated Form Objects
$Form
= New-Object
System.Windows.Forms.Form
$Label_Result
= New-Object
System.Windows.Forms.Label
$Button_Save
= New-Object
System.Windows.Forms.Button
$TextBox
= New-Object
System.Windows.Forms.TextBox
$InitialFormWindowState
= New-Object
System.Windows.Forms.FormWindowState
#endregion
Generated Form Objects
#Global
Function
Function
Save {
$GetTime
= Get-Date -Format "dd/MM/yyyy
HH:mm:ss"
$Label_Result.Text = $GetTime + " Saved!"
$TaskToSave
= $GetTime
+ " "
+ $TextBox.Text.ToString()
$TaskToSave
| Out-File C:\InfraTeam\TaskReminder.txt -Append
$TextBox.Text = ""
}
Function
EnterToSave {
If($_.KeyCode -eq "Enter")
{
Save
}
}
Function
CheckLogFile {
$LogFileExist
= Test-Path
C:\InfraTeam\TaskReminder.txt
if ($LogFileExist)
{
$Label_Result.Text = "Task Reminder Log Found -
C:\InfraTeam\TaskReminder.txt"
}
else
{
New-Item
-Path C:\InfraTeam
-Name TaskReminder.txt
-ItemType File
-Force
$Label_Result.Text = "Task Reminder Log Have Been Created -
C:\InfraTeam\TaskReminder.txt"
}
}
#----------------------------------------------
#Generated
Event Script Blocks
#----------------------------------------------
$Button_Save_OnClick=
{
Save
}
$EnterToSave=
{
EnterToSave
}
$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the
.Net maximized form issue
$Form.WindowState =
$InitialFormWindowState
CheckLogFile
}
#----------------------------------------------
#region
Generated Form Code
$Form.BackColor =
[System.Drawing.Color]::FromArgb(255,176,224,230)
$System_Drawing_Size
= New-Object
System.Drawing.Size
$System_Drawing_Size.Height =
165
$System_Drawing_Size.Width =
737
$Form.ClientSize =
$System_Drawing_Size
$Form.DataBindings.DefaultDataSourceUpdateMode
= 0
$Form.Font =
New-Object System.Drawing.Font("Arial Narrow",15.75,0,3,0)
$Form.Name =
"Form"
$Form.Text =
"Task Reminder - By OJ"
$Form.TopMost =
$True
$Label_Result.DataBindings.DefaultDataSourceUpdateMode
= 0
$Label_Result.Font =
New-Object System.Drawing.Font("Arial Narrow",14.25,0,3,0)
$System_Drawing_Point
= New-Object
System.Drawing.Point
$System_Drawing_Point.X = 13
$System_Drawing_Point.Y = 48
$Label_Result.Location =
$System_Drawing_Point
$Label_Result.Name =
"Label_Result"
$System_Drawing_Size
= New-Object
System.Drawing.Size
$System_Drawing_Size.Height =
38
$System_Drawing_Size.Width =
712
$Label_Result.Size =
$System_Drawing_Size
$Label_Result.TabIndex =
2
$Label_Result.TextAlign =
16
$Form.Controls.Add($Label_Result)
$Button_Save.Anchor =
14
$Button_Save.DataBindings.DefaultDataSourceUpdateMode
= 0
$System_Drawing_Point
= New-Object
System.Drawing.Point
$System_Drawing_Point.X = 13
$System_Drawing_Point.Y = 89
$Button_Save.Location =
$System_Drawing_Point
$Button_Save.Name =
"Button_Save"
$System_Drawing_Size
= New-Object
System.Drawing.Size
$System_Drawing_Size.Height =
64
$System_Drawing_Size.Width =
712
$Button_Save.Size =
$System_Drawing_Size
$Button_Save.TabIndex =
1
$Button_Save.Text =
"Save"
$Button_Save.UseVisualStyleBackColor = $True
$Button_Save.add_Click($Button_Save_OnClick)
$Form.Controls.Add($Button_Save)
$TextBox.Anchor =
15
$TextBox.DataBindings.DefaultDataSourceUpdateMode
= 0
$System_Drawing_Point
= New-Object
System.Drawing.Point
$System_Drawing_Point.X = 13
$System_Drawing_Point.Y = 13
$TextBox.Location =
$System_Drawing_Point
$TextBox.Name =
"TextBox"
$System_Drawing_Size
= New-Object
System.Drawing.Size
$System_Drawing_Size.Height =
32
$System_Drawing_Size.Width =
712
$TextBox.Size =
$System_Drawing_Size
$TextBox.TabIndex =
0
$TextBox.add_KeyDown($EnterToSave)
$Form.Controls.Add($TextBox)
#endregion
Generated Form Code
#Save
the initial state of the form
$InitialFormWindowState
= $Form.WindowState
#Init
the OnLoad event to correct the initial state of the form
$Form.add_Load($OnLoadForm_StateCorrection)
#Show
the Form
$Form.ShowDialog()|
Out-Null
No comments:
Post a Comment