Another refresh question

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 5 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
SvanGool
Posts: 37
Last visit: Mon Nov 27, 2023 2:02 am

Re: Another refresh question

Post by SvanGool »

I've inserted the code into my main project but for some reason it is nog working.

In the mainform I call the childform:
  1. $buttonRemoteToegang_Click= {
  2.     #TODO: Place custom script here
  3.     Show-PopupDienstenRemoteToegang_psf ([ref]$buttonRemoteToegang) -SamAccountName $SamAccountName -IctDienstRemoteToegang $IctDienstRemoteToegang -upn $upn
  4. }
In the childform i have:
  1. param (
  2.     [string]$upn,
  3.     [string]$SamAccountName,
  4.     [string]$IctDienstRemoteToegang,
  5.     [ref]$buttonRemoteToegang
  6. )
  7.  
  8. $buttonRemoteToegangRSA_Click = {
  9.     #TODO: Place custom script here
  10.     $result = [System.Windows.Forms.MessageBox]::Show("Wil je $upn rechten geven op remote toegang middels RSA (softtoken)?", "Remote toegang RSA", 'YesNo', 'Warning');
  11.     if ($result -eq [System.Windows.Forms.DialogResult]::Yes)
  12.     {
  13.         #eerste checken of gebruiker al in de SMS groep staat
  14.         if ($IctDienstRemoteToegang -eq 'RemoteSMS')
  15.         {
  16.             Remove-ADGroupMember -Identity 'Gebruikers Remote Toegang SMS' -Member $SamAccountName -Confirm:$false
  17.         }
  18.        
  19.         #Toevoegen aan RSA groep
  20.         Add-ADGroupMember -Identity 'Gebruikers Remote Toegang RSA' -Members $SamAccountName
  21.         [System.Windows.Forms.MessageBox]::Show("$upn heeft nu rechten op remote toegang middels RSA (softtoken).", "Remote toegang RSA", 'Ok', 'Information');
  22.     }
  23.     Set-Variable -Name IctDienstRemoteToegang -Value 'RemoteRSA' -Scope Global
  24.     $buttonRemoteToegang.ImageIndex = 0
  25.     $formICTDienstRemoteToega.Close()
  26.    
  27. }
With the first sollution I got an empty button (so no index, 0 or 1, was placed).
With the second one I get:
ERROR: The property 'ImageIndex' cannot be found on this object. Verify that the property exists and can be set.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Another refresh question

Post by jvierra »

You are not passing the parameters as they are defined.
User avatar
SvanGool
Posts: 37
Last visit: Mon Nov 27, 2023 2:02 am

Re: Another refresh question

Post by SvanGool »

I don't understand. Can you give me a hint?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Another refresh question

Post by jvierra »

You define your parameters in one order but have passed them in a different order. If we use named parameters then we should name all parameters and pass by name. Mixing these will only lead to failure.

If you pass by ref use the objects "Value". If you pass directly then don't use a ref. You are mixing and matching many incompatible methods.
User avatar
SvanGool
Posts: 37
Last visit: Mon Nov 27, 2023 2:02 am

Re: Another refresh question

Post by SvanGool »

Ok, thanks I've sorted that out. But still got no image after $buttonRemoteToegang.Value.ImageIndex = 0.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Another refresh question

Post by jvierra »

Here is a working example. You will have to debug your other code since there is no way for me to do that.
Attachments
ImageListExample.zip
(99.39 KiB) Downloaded 100 times
User avatar
SvanGool
Posts: 37
Last visit: Mon Nov 27, 2023 2:02 am

Re: Another refresh question

Post by SvanGool »

I figured it out, it was the initial loading of the form where I used:
  1. $buttonRemoteToegang.Image = $imagelistDnstRemoteToegang.Images[0]
  2. and
  3. $buttonRemoteToegang.Image = $imagelistDnstRemoteToegang.Images[1]
After I changed that into $buttonRemoteToegang.ImageIndex = 0 the change through the childform is working.

Thanks for your help!
This topic is 5 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked