Created
January 24, 2016 22:58
-
-
Save PrateekKumarSingh/cbcac3a41450811044f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function Auto-Complete() | |
{ | |
Return (Invoke-RestMethod -Uri "http://api.bing.com/qsml.aspx?query=$($TextBox1.text)").searchsuggestion.section.item.text | |
} | |
Function Create-WinForm() | |
{ | |
#Calling the Assemblies | |
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | |
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") | |
#Create the Conatainer Form to place the Labels and Textboxes | |
$Form = New-Object “System.Windows.Forms.Form”; | |
$Form.Width = 340; | |
$Form.Height = 310; | |
$Form.Text = 'Enter your Search Query' | |
$Form.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen; | |
$Form.TopMost = $true | |
$Form.KeyPreview = $true | |
$Form.FormBorderStyle = 'Fixed3d' | |
# Define the font to be used in the Form | |
$Font = New-Object System.Drawing.Font("lucida sans",12,[System.Drawing.FontStyle]::bold) | |
#Define Label1 | |
$Label1 = New-Object “System.Windows.Forms.Label”; | |
$Label1.Left = 10; | |
$Label1.Top = 15; | |
$Label1.Height = 25 | |
$Label1.Width = 120 | |
$Label1.Text = 'Search Query'; | |
$Label1.Font =$Font | |
#Define Label2 | |
$Label2 = New-Object “System.Windows.Forms.Label”; | |
$Label2.Left = 10; | |
$Label2.Top = 50; | |
$Label2.Height = 220 | |
$Label2.Width = 310 | |
$Label2.Text = ''; | |
$Label2.BorderStyle = "FixedSingle" | |
$Label2.Font= $Font | |
#$Label2.AutoScrollOffset | |
#Define TextBox1 for input | |
$TextBox1 = New-Object “System.Windows.Forms.RichTextBox”; | |
$TextBox1.Left = 140; | |
$TextBox1.Top = 10; | |
$TextBox1.Height = 30 | |
$TextBox1.width = 180; | |
$TextBox1.Font = $Font | |
#Defining the Form Key Listener | |
$form.add_keyup({ | |
$Data = Auto-Complete | |
$Data | %{$StrWithLineBreaks+=$_+';'} | |
$Label2.text=$StrWithLineBreaks -replace ";","`n" | |
}) | |
#Adding Controls to the Form | |
$Form.Controls.Add($Label1); | |
$Form.Controls.Add($TextBox1); | |
$Form.Controls.Add($Label2); | |
$Form.ShowDialog()|Out-Null | |
} | |
Create-WinForm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks Prasoon :)