how do i get options on $combobox.add_....

Tagged: 

This topic contains 11 replies, has 2 voices, and was last updated by Profile photo of Dan Potter Dan Potter 3 months, 1 week ago.

  • Author
    Posts
  • #52333
    Profile photo of Chris Bakker
    Chris Bakker
    Participant

    I have been playing arount with combobox in powershell.
    With the $combobox|get-member you can see a lot of options.
    But how do i see what is possible with $combobox.add_? (example $combobox.add_TextChanged)
    Is there any way to see what more commands there are possible?

  • #52342
    Profile photo of Dan Potter
    Dan Potter
    Participant

    All the properties and methods for all controls are on msdn. If you are using an editor with intellisence you should be able to see them as well.

    • #52352
      Profile photo of Chris Bakker
      Chris Bakker
      Participant

      No, it will show $combobox.TextChanged
      But not $combobox.add_TextChanged

      • This reply was modified 3 months, 1 week ago by Profile photo of Chris Bakker Chris Bakker.
  • #52357
    Profile photo of Dan Potter
    Dan Potter
    Participant

    Add is when we dynamically add events to a form after it's loaded. Typically this is done in the form design but sometimes it's necessary to add/remove events so they are not processed.

    Textchanged is the scriptblock that is executed when the event fires.

    Untitled20mb image hosting

  • #52359
    Profile photo of Dan Potter
    Dan Potter
    Participant
  • #52435
    Profile photo of Chris Bakker
    Chris Bakker
    Participant

    Using powershell ise, add_ commands not in there.
    I know what its for, but as intelicense knows what commands there are, you must be able to get the commands throught the powershell command line.
    Im Just wondering where and how.....

  • #52485
    Profile photo of Dan Potter
    Dan Potter
    Participant

    Add-Type -AssemblyName System.Windows.Forms
    $form1=New-Object System.Windows.Forms.Form
    $cb=New-Object System.Windows.Forms.combobox
    $form1.Controls.Add($cb)

    $cb |gm -membertype event

    $tc = {write-host 'do something'}

    $cb.add_textchanged($tc)

    $form1.ShowDialog()

  • #52489
    Profile photo of Dan Potter
    Dan Potter
    Participant

    I rarely code forms in notepad anymore, here's a good article on how the eventhandlers are added in PS.

    http://social.technet.microsoft.com/wiki/contents/articles/25911.how-to-add-a-powershell-gui-event-handler-part-1.aspx

    I'm not a sapien salesman although I should get a commission:D Download the trial and play around with it. It'll open your mind to how windows forms work.

  • #52671
    Profile photo of Chris Bakker
    Chris Bakker
    Participant

    Found the solution:

    $combobox | gm -MemberType Method -Force

    Thanks for the input

  • #52680
    Profile photo of Dan Potter
    Dan Potter
    Participant

    Incorrect, you said you were looking for the events. There is a big difference.

    • #52763
      Profile photo of Chris Bakker
      Chris Bakker
      Participant

      Yep, bit of confusion there. But it seems that the add_.... are listed as methods and can be seen by useing the -force option

      PS C:\Users\Chris> $objListBox| gm -Force -MemberType Method

      TypeName: System.Windows.Forms.ComboBox

      Name MemberType Definition
      —- ———- ———-
      add_AutoSizeChanged Method void add_AutoSizeChanged(System.EventHandler value)
      add_BackColorChanged Method void add_BackColorChanged(System.EventHandler value)
      ......

      Sorry for the mixup of terms.

      • This reply was modified 3 months, 1 week ago by Profile photo of Chris Bakker Chris Bakker.
      • This reply was modified 3 months, 1 week ago by Profile photo of Chris Bakker Chris Bakker.
  • #52775
    Profile photo of Dan Potter
    Dan Potter
    Participant

    Ah, I get what you're saying. All the events correspond to the add_ remove_ set_ and since I know that those are my options I don't need to look up the methods.

You must be logged in to reply to this topic.