header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
How to Capture Form Close Event
Last Post 07 Sep 2010 01:33 AM by Agaton. 3 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Resolved
AgatonUser is Offline
New Member
New Member
Posts:6
Avatar

--
03 Sep 2010 05:41 AM
    In a windows form, I don't want to close the windows but simple hide it, if an user uses Cross (x) button.
    I need to redisplay the same windows later on. The $form.close() does also a $form.dispose() and the $form becomes unusable. $form.show() does no longer work

    In VB you can workarrount this problem like this

    private void Form1_FormClosing(object sender, FormClosingEventArgs e) { e.Cancel = true this.visable = false }
    Does any one have a solution for this in powershell ?
    Thx

    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    03 Sep 2010 06:45 AM

    $form1.add_FormClosing([System.Windows.Forms.FormClosingEventHandler]{
    $_.Cancel=$true
    $form1.Visible=$false
    })

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    Joel "Jaykul" BennettUser is Offline
    Basic Member
    Basic Member
    Posts:112
    Avatar

    --
    03 Sep 2010 06:49 AM
    Yeah! Just do the same thing: handle the event.
    I think you can use $this in the event handler, and you don't need to cast:

    $form = new-object system.windows.forms.form
    $form.Add_FormClosing( { $_.Cancel = $true; $this.Visible = $false } )
    $form.ShowDialog()
    # now close it ... it will show "Cancel"
    $form.ShowDialog() #yay, it works multiple times!
    # now close it ... it will show "Cancel" again ...

    AgatonUser is Offline
    New Member
    New Member
    Posts:6
    Avatar

    --
    07 Sep 2010 01:33 AM
    Thx. This solves my problem. So simple
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer