![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Events with powershell Does powershell know how to deal with events? For e.g.: I create a windows form with a button, how do i know that the button was pressed in power shell? |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: Events with powershell Roy wrote: > Does powershell know how to deal with events? > > For e.g.: > > I create a windows form with a button, how do i know that the button was > pressed in power shell? It /should/ be something like this: Create a function with the right signature: function onPress($sender,$e) { ... } then: $button = new-object Windows.Forms.Button $button.add_Click(onPress) But I don't have PowerShell here, so somebody correct me if I'm wrong. :-) |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: Events with powershell add_click takes a scriptblock so $button.add_click({write-host "it was clicked" }) or i suppose in your example $button.add_click({onPress}) |
My System Specs![]() |
| | #4 (permalink) |
| Guest | Re: Events with powershell klumsy@xtra.co.nz wrote: > add_click takes a scriptblock > > so > $button.add_click({write-host "it was clicked" }) > > or i suppose in your example > > $button.add_click({onPress}) Given that scriptblocks are basically inline functions, it's a shame they can't be used interchangeably. |
My System Specs![]() |
| | #5 (permalink) |
| Guest | Re: Events with powershell Functions and scriptblocks can be used interchangably but not quite the way you expect. If you have a function onClick, then you can bind it to an event handler by doing $button.add_Click($function nClick)You can't simply say onClick because that looks like a command invocation rather than getting a reference to the function itself. (In fact if you just specify the name of the command by itself, you'll get an error. You have to enclose a command invocation in parens to invoke it. This is one area where we require you to be explicit about your intent.) -bruce -- Bruce Payette [MSFT] Windows PowerShell Technical Lead Microsoft Corporation This posting is provided "AS IS" with no warranties, and confers no rights. Visit the Windows PowerShell Team blog at: http://blogs.msdn.com/PowerShell Visit the Windows PowerShell ScriptCenter at: http://www.microsoft.com/technet/scr.../hubs/msh.mspx My Book: http://manning.com/powershell "Adam Milazzo" <adamm@san.rr.com> wrote in message news:u3T6PkTBHHA.204@TK2MSFTNGP04.phx.gbl... > klumsy@xtra.co.nz wrote: >> add_click takes a scriptblock >> >> so >> $button.add_click({write-host "it was clicked" }) >> >> or i suppose in your example >> >> $button.add_click({onPress}) > > Given that scriptblocks are basically inline functions, it's a shame they > can't be used interchangeably. |
My System Specs![]() |
| | #6 (permalink) |
| Guest | RE: Events with powershell Cool stuff! function onClick($sender,$e) {write-Host $textbox.text}; [reflection.assembly]::loadwithpartialname("system.windows.forms"); $window = New-Object windows.forms.form; $window.Size = New-Object system.drawing.size @(200,200); $textbox = new-Object windows.Forms.TextBox; $button = new-Object windows.Forms.Button; $button.add_click($function nClick);$button.Left = 100; $window.Controls.add($textbox); $window.Controls.Add($button); $window.ShowDialog(); |
My System Specs![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Can Powershell handle COM events? | Duncan Smith | PowerShell | 6 | 07-27-2007 08:17 AM |
| New snapin for consuming .NET events in PowerShell | Oisin Grehan | PowerShell | 1 | 05-10-2007 08:10 AM |
| Manipulating mouse events through Powershell | danielfeichtinger@gmail.com | PowerShell | 5 | 04-17-2007 05:19 AM |
| Fire events from Xaml files.. events in Pre compiled Dll's | SureshGubba | Avalon | 1 | 09-15-2006 01:56 PM |