Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - System.Windows.Forms.Form

Reply
 
Old 06-19-2008   #1 (permalink)
William Holmes


 
 

System.Windows.Forms.Form

Hello,

I am using a windows form from within powershell. I have a textbox which I
have added to the form that I would like to be able to clear but I am
missing something on how to accomplish this. I want to enter some text in
the textbox then when I click the go button I want the text to be cleared.
What is the syntax for accessing an objects properties?

Thanks


Here is my script:

$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "MyForm"
$objForm.Size = New-Object System.Drawing.Size(600,400)
$objForm.StartPosition = "CenterScreen"

$objTextBox = New-Object System.Windows.Forms.TextBox
$objTextBox.Location = New-Object System.Drawing.Size(10,40)
$objTextBox.Size = New-Object System.Drawing.Size(260,20)
$objForm.Controls.Add($objTextBox)

$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(70,120)
$OKButton.Size = New-Object System.Drawing.Size(100,23)
$OKButton.Text = "GO"
$OKButton.Add_Click({<HERE IS WHERE I WANT TO CLEAR $objTextBox>})
$objForm.Controls.Add($OKButton)

$objForm.Topmost = $True

$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()


My System SpecsSystem Spec
Old 06-19-2008   #2 (permalink)
Jon


 
 

Re: System.Windows.Forms.Form

You can set its 'text' property to an empty string ....

$OKButton.Add_Click({$objTextBox.Text=""})

--
Jon


"William Holmes" <wtholmes@xxxxxx> wrote in message
news:%23nOxoph0IHA.548@xxxxxx
Quote:

> Hello,
>
> I am using a windows form from within powershell. I have a textbox which I
> have added to the form that I would like to be able to clear but I am
> missing something on how to accomplish this. I want to enter some text in
> the textbox then when I click the go button I want the text to be cleared.
> What is the syntax for accessing an objects properties?
>
> Thanks
>
>
> Here is my script:
>
> $objForm = New-Object System.Windows.Forms.Form
> $objForm.Text = "MyForm"
> $objForm.Size = New-Object System.Drawing.Size(600,400)
> $objForm.StartPosition = "CenterScreen"
>
> $objTextBox = New-Object System.Windows.Forms.TextBox
> $objTextBox.Location = New-Object System.Drawing.Size(10,40)
> $objTextBox.Size = New-Object System.Drawing.Size(260,20)
> $objForm.Controls.Add($objTextBox)
>
> $OKButton = New-Object System.Windows.Forms.Button
> $OKButton.Location = New-Object System.Drawing.Size(70,120)
> $OKButton.Size = New-Object System.Drawing.Size(100,23)
> $OKButton.Text = "GO"
> $OKButton.Add_Click({<HERE IS WHERE I WANT TO CLEAR $objTextBox>})
> $objForm.Controls.Add($OKButton)
>
> $objForm.Topmost = $True
>
> $objForm.Add_Shown({$objForm.Activate()})
> [void] $objForm.ShowDialog()
My System SpecsSystem Spec
Old 06-19-2008   #3 (permalink)
Marco Shaw [MVP]


 
 

Re: System.Windows.Forms.Form

William Holmes wrote:
Quote:

> Hello,
>
> I am using a windows form from within powershell. I have a textbox which
> I have added to the form that I would like to be able to clear but I am
> missing something on how to accomplish this. I want to enter some text
> in the textbox then when I click the go button I want the text to be
> cleared. What is the syntax for accessing an objects properties?
That should be an object's members, which includes properties, methods
and events. I'm not sure what you mean exactly, but maybe this helps:

[reflection.assembly]::LoadWithPartialName("System.Windows.Forms")
$objTextBox = New-Object System.Windows.Forms.TextBox
$objTextBox|get-member

You want to do an "action", so you're likely looking for a method. I
looked for a "clear" and there was one and it worked.
Quote:

> $OKButton.Add_Click({<HERE IS WHERE I WANT TO CLEAR $objTextBox>})
This should work for you:
$OKButton.Add_Click({$objTextBox.clear()})

Marco

--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
My System SpecsSystem Spec
Old 06-19-2008   #4 (permalink)
Oisin (x0n) Grehan [MVP]


 
 

Re: System.Windows.Forms.Form

On Jun 19, 10:40*am, "William Holmes" <wthol...@xxxxxx> wrote:
Quote:

> Hello,
>
> I am using a windows form from within powershell. I have a textbox which I
> have added to the form that I would like to be able to clear but I am
> missing something on how to accomplish this. *I want to enter some textin
> the textbox then when I click the go button I want the text to be cleared..
> What is the syntax for accessing an objects properties?
>
> Thanks
>
> Here is my script:
>
> $objForm = New-Object System.Windows.Forms.Form
> $objForm.Text = "MyForm"
> $objForm.Size = New-Object System.Drawing.Size(600,400)
> $objForm.StartPosition = "CenterScreen"
>
> $objTextBox = New-Object System.Windows.Forms.TextBox
> $objTextBox.Location = New-Object System.Drawing.Size(10,40)
> $objTextBox.Size = New-Object System.Drawing.Size(260,20)
> $objForm.Controls.Add($objTextBox)
>
> $OKButton = New-Object System.Windows.Forms.Button
> $OKButton.Location = New-Object System.Drawing.Size(70,120)
> $OKButton.Size = New-Object System.Drawing.Size(100,23)
> $OKButton.Text = "GO"
> $OKButton.Add_Click({<HERE IS WHERE I WANT TO CLEAR $objTextBox>})
> $objForm.Controls.Add($OKButton)
>
> $objForm.Topmost = $True
>
> $objForm.Add_Shown({$objForm.Activate()})
> [void] $objForm.ShowDialog()
Hi,

It's as simple as:

$OKButton.Add_Click( { $objTextBox.Text = "" } )

Hope this helps,

- Oisin
My System SpecsSystem Spec
Old 06-19-2008   #5 (permalink)
William Holmes


 
 

Re: System.Windows.Forms.Form

Thanks everyone,

I am new to powershell scripting and I was simply not referencing the object
correctly. I was using objectTextbox rather that $objectTextbox. Duh....

Bill

"Marco Shaw [MVP]" <marco.shaw@_NO_SPAM_gmail.com> wrote in message
news:#t2blxh0IHA.4416@xxxxxx
Quote:

> William Holmes wrote:
Quote:

>> Hello,
>>
>> I am using a windows form from within powershell. I have a textbox which
>> I have added to the form that I would like to be able to clear but I am
>> missing something on how to accomplish this. I want to enter some text
>> in the textbox then when I click the go button I want the text to be
>> cleared. What is the syntax for accessing an objects properties?
>
> That should be an object's members, which includes properties, methods and
> events. I'm not sure what you mean exactly, but maybe this helps:
>
> [reflection.assembly]::LoadWithPartialName("System.Windows.Forms")
> $objTextBox = New-Object System.Windows.Forms.TextBox
> $objTextBox|get-member
>
> You want to do an "action", so you're likely looking for a method. I
> looked for a "clear" and there was one and it worked.
>
Quote:

>> $OKButton.Add_Click({<HERE IS WHERE I WANT TO CLEAR $objTextBox>})
>
> This should work for you:
> $OKButton.Add_Click({$objTextBox.clear()})
>
> Marco
>
> --
> Microsoft MVP - Windows PowerShell
> http://www.microsoft.com/mvp
>
> PowerGadgets MVP
> http://www.powergadgets.com/mvp
>
> Blog:
> http://marcoshaw.blogspot.com
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Error with Windows.forms.form PowerShell
Questions regarding system.windows.forms PowerShell
[system.Windows.Forms.MessageBox] PowerShell
Using [system.windows.forms.messagebox]::show() PowerShell
Data Fetching and system.windows.forms.form & .datagridview PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46