calling a class with a string... using a combo box... using .net functions in powershell ISE

bLAcKmAgE 1 Reputation point
2022-12-20T12:17:09.667+00:00

This call

[void]addClassesListbox()  
    {  
        $thislisterHandle = $This  
        $this.OlistboxClasses = new-object System.Windows.Forms.ComboBox  
        $this.OlistboxClasses.size = new-object System.Drawing.Size($this.SlistboxClassesX , $this.SlistboxClassesY)  
        $this.olistboxclasses.location = new-object system.drawing.point($this.PlistboxClassesX,  $this.PlistboxClassesY)   
         
  
          
  
        C:\users\upthere\images\workers\testClassChecker2.ps1  
  
        foreach($listed in $this.VCurrentClassList)  
        {  
          
  
            $this.olistboxclasses.Items.Add($listed)  
  
        }  
          
        $thislisterHandle.OlistboxClasses.add_SelectedIndexChanged({  
          
            $thislisterHandle.UcurrentlyListedClass = $thislisterHandle.OlistboxClasses.selectedItem  
            $thislisterHandle.OspectrumForm.text = $thislisterHandle.UcurrentlyListedClass  
  
        }.GetNewClosure())  
           
           
         $this.OspectrumForm.controls.add($this.OlistboxClasses)  
          
    }  

So that you run this script which loads up the box... simple scanning a file for classes with prefix [object]$C for C as in class to S as in size

       class classListChecker  
       {  
          
  
        [object]$listOfClasses   
  
        classListChecker()  
        {  
  
  
           $OcountClasses = @()  
           $OlistClasses = @()  
            
         
           $cat = "`[object`]`$C"  
           #$cat   
           $dog = Get-Content -Path "C:\Users\upThere\images\workers\classLoads.ps1"  
           #$dog   
           $countDogs = 0   
           foreach($inputer in $dog)  
           {  
                $countDogs++   
                $sub = $inputer.tostring()  
                $subPosMatch = $sub.IndexOf($cat)  
                  
              
              
                if($subPosMatch -gt 1)  
                {  
                     #$subPosMatch  
                     #"`n"  
                     #$inputer  
                     #"`n"  
                     #$countDogs  
  
                     $OcountClasses += $inputer  
                }  
             
  
  
              
                  
  
           }  
  
           foreach($checker in $ocountClasses )  
           {  
          
                $sub = $checker.tostring()  
                $sub = $sub.replace("`[object`]","")  
                $sub = $sub.replace("`$C","")  
  
                 
  
                $sub = $sub.replace(" = `$this #999","")  
                $sub = $sub.replace(" ","")  
  
             
                $OlistClasses += $sub  
                     
  
           }  
  
           $this.listOfClasses = $OlistClasses  
             
          
         }  
  
  
          
       }  
         
  
       $retrievalClassList = [classListChecker]::new()  
       $this.VCurrentClassList = $retrievalClassList.listOfClasses  

So that if you have a form like this... you can call out any class with presets and panels and all sorts of goods with just the combobox on your form class
but how do i simply : $dog = "brainsliceclass" ... so that I'm like $newClass = [$dog]::new() ??? anyways this is my work around of it...

class brainSliceVars  
{  
  
        [object]$VBrainSliceClass = $this #666  
          
}  
class brainSliceSpiral : brainSliceVars  
{  
          
              
        [object]$CBrainSliceClass = $this #999  
  
          
}  
  
  
class brainSliceVars2  
{  
  
        [object]$VBrainSliceClass2 = $this #666  
          
}  
class brainSliceSpiral2 : brainSliceVars2  
{  
          
              
        [object]$CBrainSliceClass2 = $this #999  
  
          
}  
  
  
class brainSliceSpiral3 : brainSliceVars2  
{  
          
              
        [object]$CBrainSliceClass3 = $this #999  
  
          
}  
  
class brainSliceSpiral4 : brainSliceVars2  
{  
          
              
        [object]$CBrainSliceClass4 = $this #999  
  
          
}  
  
class brainSliceSpiral5 : brainSliceVars2  
{  
          
              
        [object]$CBrainSliceClass5 = $this #999  
  
          
}  
  
  
class sunSliceSpiralVars  
{  
  
        [object]$VSunSliceClass = $this #666  
          
}  
class sunSliceSpiral : sunSliceSpiralVars  
{  
          
              
        [object]$CSunSliceClass = $this #999  
  
          
}  

...
...
also notice that I have managed to stick on those regular .net c# functions by using add_ to any regular event. Without its actual name there like as in the c# docs.
SO far... I havent seen anybody use this... please link me up and beat this page -> https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.combobox.selectedindexchanged?view=windowsdesktop-7.0

$cat = "`[object`]`$C"  
       $cat   
       $dog = Get-Content -Path "C:\Users\upThere\images\workers\classLoads.ps1"  
       #$dog   
  
       foreach($inputer in $dog)  
       {  
           
            $sub = $inputer.tostring()  
            $subPosMatch = $sub.IndexOf($cat)  
            #$wordSub = $sub  
              
              
            if($subPosMatch -gt 1)  
            {  
                 $subPosMatch  
                 "`n"  
                 $inputer  
            }  
             
              
              
  
       }  
  
       $UstringIllUse  
       $hotdog = "  
  
       `$nextClasso  = `[$UstringIllUse`]::new(  
          
        `$SdisplayPictureBoxX  ,  
        `$SdisplayBMPX ,  
        `$SvariableTextboxX ,  
        `$SvariableTextboxY ,  
        `$PtrackbarX ,  
        `$PtrackbarY ,  
        `$SprintResizeX ,  
        `$SprintResizeY    
    )  
    "  
    $hotdog >> "C:\users\upThere\images\workers\createClassLaunch.ps1"  
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,628 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. bLAcKmAgE 1 Reputation point
    2022-12-21T10:03:34.91+00:00

    Forcing it to work with modules...
    results...the combobox lets me pick any preloaded class with pre-defs... and the form updates itself correctly...
    using that I can fire off the function without HARDCODING .

    try{  
           $UstringIllUse = $thisLevel.UcurrentlyListedClass  
           $leg = $UstringIllUse.length  
      
           if($leg -eq 0)  
           {  
                $UstringIllUse = "default"  
           }   
      
             
           $hotdog = "  
             
      
           Using module '.`\CLASSLOADS.psm1'  
           try`{  
           `$thisnewlevel.OcurrentClassLoaded.mainPanel.dispose()   
           `}  
           catch  
           `{`}  
           `$thisnewlevel.OcurrentClassLoaded = `[$UstringIllUse`]::new(  
              
           `$thisnewlevel.SdisplayPictureBoxX ,   
           `$thisnewlevel.SdisplayBMPX ,  
           `$thisnewlevel.SvariableTextboxX ,   
           `$thisnewlevel.SvariableTextboxY ,  
           `$thisnewlevel.PtrackbarX ,   
           `$thisnewlevel.PtrackbarY ,   
           `$thisnewlevel.SprintResizeX ,  
           `$thisnewlevel.SprintResizeY  
        )  
          
        "  
          
      
        $nameOfSender = "C:\users\upThere\images\workers\createClassLaunch.ps1"  
        $trueThere = Test-Path -path $nameOfSender  
        if($trueThere -eq $true)  
        {  
            Remove-Item $nameOfSender  
        }  
        $hotdog >> "C:\users\upThere\images\workers\createClassLaunch.ps1"  
          
        }  
        catch  
        {  
        $hotdog >> "C:\users\upThere\images\workers\createClassLaunch.ps1"  
              
        }  
    

    273071-hmhm.gif

    classSelectedFromList()  
        {  
               
              $thisLevel = $this      
              c:\users\upThere\images\workers\setCurrentClass.ps1  
              $thisnewlevel = $this    
              C:\users\upthere\images\workers\createClassLaunch.ps1  
      
                
        }  
      
      
    }  
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.