Question [RESOLU]Formulaires .net et powershell

Plus d'informations
il y a 2 ans 9 mois #31092 par Percival
Réponse de Percival sur le sujet Formulaires .net et powershell
"Si un traitement accède aux propriétés des objets en lecture seulement tu peux construire un objet personnalisé ( Get-FormDatas) et le passer en paramètre ainsi ton traitement sur les données n'a pas besoin de connaitre comment ta forme est structurée."

Effectivement comme ça cela marche très bien, mais les objets ne sont qu'accessibles en lecture, dommage .
En passant le control parent je récupérer tout, cependant c'est pas simple d'accéder directement aux objets .

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 2 ans 9 mois #31110 par ericlm128
Réponse de ericlm128 sur le sujet Formulaires .net et powershell
Ce que je fait des fois, mais qui n'est surement pas propre au sens POO, c'est transmettre la "form" principal et trouver le contrôle correspondant en fonction de son nom "Name"
function Test($Form){
    $Form.Controls.Find("OldComputerNameTextBox_NewPage", $true).Text
}

# Creation du formulaire
$Form = New-Object System.Windows.Forms.Form
$Form.Text = 'Intégration de postes'
$Form.Size = New-Object System.Drawing.Size( 1000 , 550 )
$Form.SizeGripStyle = 'Hide'    
$Form.MaximizeBox = $false
$Form.ShowIcon = $True
$Form.ShowInTaskbar = $True
$Form.TopMost = $True    

$Form.StartPosition = "CenterScreen"

# Create tab controls
$TabControl = New-object System.Windows.Forms.TabControl
$TabControl.DataBindings.DefaultDataSourceUpdateMode = 0
$TabControl.Location = New-Object System.Drawing.Size( 10 , 10 )
$TabControl.Size = New-Object System.Drawing.Size( 480 , 490 )
$TabControl.Name = 'TabControl'
$Form.Controls.Add( $TabControl )

# Crée l'onglet "Nouvel Ordinateur"
$NewComputerTabPage = New-Object System.Windows.Forms.TabPage
$NewComputerTabPage.DataBindings.DefaultDataSourceUpdateMode = 0
$NewComputerTabPage.UseVisualStyleBackColor = $True
$NewComputerTabPage.Text = 'Ordinateur'
$NewComputerTabPage.BackColor = 'LightSkyBlue'
$NewComputerTabPage.Name = 'NewComputerTabPage'
$TabControl.Controls.Add( $NewComputerTabPage )  

# Création du groupe infos ordinateur
$NewComputerInfoGroupBox = New-Object System.Windows.Forms.GroupBox
$NewComputerInfoGroupBox.Location = New-Object System.Drawing.Size( 10, 10 )
$NewComputerInfoGroupBox.Size = New-Object System.Drawing.Size( 450 , 125 )
$NewComputerInfoGroupBox.Text = 'Informations Ordinateur'
$NewComputerInfoGroupBox.Name = 'NewComputerInfoGroupBox'
$NewComputerTabPage.Controls.Add( $NewComputerInfoGroupBox )           

# Box nom Courant PC
$OldComputerNameLabel_NewPage = New-Object System.Windows.Forms.Label
$OldComputerNameLabel_NewPage.Location = New-Object System.Drawing.Size( 12 , 35 )
$OldComputerNameLabel_NewPage.Size = New-Object System.Drawing.Size( 80 , 22 )
$OldComputerNameLabel_NewPage.Text = 'Nom Actuel'
$OldComputerNameLabel_NewPage.Name = 'OldComputerNameLabel_NewPage'
$NewComputerInfoGroupBox.Controls.Add( $OldComputerNameLabel_NewPage )

# Nom Actuel du poste text box
$OldComputerNameTextBox_NewPage = New-Object System.Windows.Forms.TextBox
$OldComputerNameTextBox_NewPage.ReadOnly = $True
$OldComputerNameTextBox_NewPage.Location = New-Object System.Drawing.Size( 100 , 34 )
$OldComputerNameTextBox_NewPage.Size = New-Object System.Drawing.Size( 120 , 20 )
$OldComputerNameTextBox_NewPage.Text = "Ordi1"
$OldComputerNameTextBox_NewPage.Name = 'OldComputerNameTextBox_NewPage'
$NewComputerInfoGroupBox.Controls.Add( $OldComputerNameTextBox_NewPage )

Test $Form

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 2 ans 9 mois - il y a 2 ans 9 mois #31112 par ericlm128
Réponse de ericlm128 sur le sujet Formulaires .net et powershell
A noter que l'exemple n'est pas terrible car il de met pas en évidence ton problème
function Test(){
    $OldComputerNameTextBox_NewPage.Text
}

# Creation du formulaire
$Form = New-Object System.Windows.Forms.Form
$Form.Text = 'Intégration de postes'
$Form.Size = New-Object System.Drawing.Size( 1000 , 550 )
$Form.SizeGripStyle = 'Hide'    
$Form.MaximizeBox = $false
$Form.ShowIcon = $True
$Form.ShowInTaskbar = $True
$Form.TopMost = $True    
    
$Form.StartPosition = "CenterScreen"

# Create tab controls
$TabControl = New-object System.Windows.Forms.TabControl
$TabControl.DataBindings.DefaultDataSourceUpdateMode = 0
$TabControl.Location = New-Object System.Drawing.Size( 10 , 10 )
$TabControl.Size = New-Object System.Drawing.Size( 480 , 490 )
$Form.Controls.Add( $TabControl )

# Crée l'onglet "Nouvel Ordinateur"
$NewComputerTabPage = New-Object System.Windows.Forms.TabPage
$NewComputerTabPage.DataBindings.DefaultDataSourceUpdateMode = 0
$NewComputerTabPage.UseVisualStyleBackColor = $True
$NewComputerTabPage.Text = 'Ordinateur'
$NewComputerTabPage.BackColor = 'LightSkyBlue'
$TabControl.Controls.Add( $NewComputerTabPage )  
        
# Création du groupe infos ordinateur
$NewComputerInfoGroupBox = New-Object System.Windows.Forms.GroupBox
$NewComputerInfoGroupBox.Location = New-Object System.Drawing.Size( 10, 10 )
$NewComputerInfoGroupBox.Size = New-Object System.Drawing.Size( 450 , 125 )
$NewComputerInfoGroupBox.Text = 'Informations Ordinateur'
$NewComputerTabPage.Controls.Add( $NewComputerInfoGroupBox )           
    
# Box nom Courant PC
$OldComputerNameLabel_NewPage = New-Object System.Windows.Forms.Label
$OldComputerNameLabel_NewPage.Location = New-Object System.Drawing.Size( 12 , 35 )
$OldComputerNameLabel_NewPage.Size = New-Object System.Drawing.Size( 80 , 22 )
$OldComputerNameLabel_NewPage.Text = 'Nom Actuel'
$NewComputerInfoGroupBox.Controls.Add( $OldComputerNameLabel_NewPage )
    
# Nom Actuel du poste text box
$OldComputerNameTextBox_NewPage = New-Object System.Windows.Forms.TextBox
$OldComputerNameTextBox_NewPage.ReadOnly = $True
$OldComputerNameTextBox_NewPage.Location = New-Object System.Drawing.Size( 100 , 34 )
$OldComputerNameTextBox_NewPage.Size = New-Object System.Drawing.Size( 120 , 20 )
$OldComputerNameTextBox_NewPage.Text = "Ordi1"
$NewComputerInfoGroupBox.Controls.Add( $OldComputerNameTextBox_NewPage )
    
Test
 
Dernière édition: il y a 2 ans 9 mois par ericlm128.

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 10 mois 2 semaines #33207 par Percival
Réponse de Percival sur le sujet Formulaires .net et powershell
Merci pour vos réponses . ;)

Connexion ou Créer un compte pour participer à la conversation.

Temps de génération de la page : 0.065 secondes
Propulsé par Kunena