![]() |
|
|||||||
| Notices |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Guest
Posts: n/a
|
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() |
|
|
|
#2 |
|
Guest
Posts: n/a
|
Re: System.Windows.Forms.Form
You can set its 'text' property to an empty string ....
$OKButton.Add_Click({$objTextBox.Text=""}) -- Jon "William Holmes" <> wrote in message news:%.gbl... > 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() |
|
|
|
#3 |
|
Guest
Posts: n/a
|
Re: System.Windows.Forms.Form
William Holmes wrote:
> 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. > $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 PowerGadgets MVP Blog: |
|
|
|
#4 |
|
Guest
Posts: n/a
|
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]" <> wrote in message news:#.gbl... > William Holmes wrote: >> 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. > >> $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 > > > PowerGadgets MVP > > > Blog: > |
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
< Windows Help - MS Office Help - Hardware Support >
| New To Site? | Need Help? |