Question WindowsForm, Textbox & Label

Plus d'informations
il y a 7 ans 7 mois #22128 par ThomasM
Bonjour à toutes et à tous,

débutant dans la matière, je viens à vous car je me retrouve dans une impasse.

Après de longue recherche sur le net (peut-être pas assez), je n'ai pas trouvé ce que je cherchais !

Dans le but d'un script pour simplifier l'ajout et la suppression de licence d'Office 365, je souhaite afficher ce que j'écris dans une texbox dans une seconde form en WindowsForm via PowerShell ISE.

$form1 :
[code:1]
# Label_1 : Champs de recherche d'un utilisateur
$label_1 = New-Object System.Windows.Forms.Label
$label_1.Size = New-Object System.Drawing.Size(350,20)
$Label_1.Location = New-Object System.Drawing.Point(10,20)
$label_1.Text = \"Veuillez entrer le nom d'utilisateur concerné :\"

# Zone de texte_1
$textbox_1 = New-Object System.Windows.Forms.TextBox
$textbox_1.Size = New-Object System.Drawing.Size(260,20)
$TextBox_1.Location = New-Object System.Drawing.Point(10,40)
$form2.Controls.Add($textBox_1)

$form2.Topmost = $true

$form2.Add_Shown({$textbox_1.Select})

if ($result_1 -eq [System.Windows.Forms.DialogResult]::OK)
{
$x
$x
}
[/code:1]

$form2
[code:1]
# Affichage du nom d'utilisateur recherché : \"_ru\" = Recherche Unitaire
$label_ru = New-Object System.Windows.Forms.Label
$label_ru.Text = $textbox_1
$label_ru.Size = New-Object System.drawing.Size(160,30)
$label_ru.Location = New-Object System.drawing.Point(30,10)
[/code:1]

Comme vous pouvez le constater, ce premier essaie n'a rien donné.

Je vous remercie de l'aide apporté,

Bonne journée/soirée

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

Plus d'informations
il y a 7 ans 7 mois #22129 par Laurent Dardenne
Salut,
n3wman écrit:

je souhaite afficher ce que j'écris dans une texbox dans une seconde form en WindowsForm via PowerShell ISE.

Je n'ai pas compris l'objectif.
Peux-tu nous donner un code fonctionnel ?

Tutoriels PowerShell

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

Plus d'informations
il y a 7 ans 7 mois #22130 par Philippe
[code:1][void] [System.Reflection.Assembly]::LoadWithPartialName(\"System.Drawing\"«»)
[void] [System.Reflection.Assembly]::LoadWithPartialName(\"System.Windows.Forms\"«»)

$FormA = New-Object System.Windows.Forms.Form
$FormA.Size = New-Object System.Drawing.Size(300,300)

$TextBox1 = New-Object System.Windows.Forms.TextBox
$TextBox1.Location = New-Object System.Drawing.Point(10,10)
$FormA.Controls.Add($TextBox1)


$Button = New-Object System.Windows.Forms.Button
$Button.Location = New-Object System.Drawing.Point(10,50)
$Button.Text = \"Suivant\"
$FormA.Controls.Add($Button)

$Button.Add_Click({
$Script:Texte = $TextBox1.Text
$FormA.Close()
})

$FormA.Add_Shown({ $FormA.Activate() })

[void] $FormA.ShowDialog()

$FormB = New-Object System.Windows.Forms.Form
$FormB.Size = New-Object System.Drawing.Size(300,300)

$TextBox2 = New-Object System.Windows.Forms.TextBox
$TextBox2.Location = New-Object System.Drawing.Point(10,10)
$TextBox2.Text = $Texte
$FormB.Controls.Add($TextBox2)

$FormB.Add_Shown({ $FormB.Activate() })

[void] $FormB.ShowDialog()
[/code:1]

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

Plus d'informations
il y a 7 ans 7 mois #22134 par ThomasM
Réponse de ThomasM sur le sujet Re:WindowsForm, Textbox & Label
Bonjour,
merci à vous deux pour vos réponse;
@Laurent Dardenne, ce que Mortasgus m'a répondu est exactement ce que je cherchais. Je te remercie d'avoir planché sur mon cas aussi rapidement !

Le but de mon script est de pouvoir simplifier, dans un premier temps, l'ajout et la suppression des licences Office 365 à \"mes\" utilisateurs via un AzureAD mais je n'arrivais tout simplement pas à afficher dans une form ce que j'écrivais dans une texbox dans une autre form.

@Mortasgus, je te remercie pour ta réponse aussi rapide !

Bonne journée à vous,

PS : si le script peut vous intéresser, je le partagerais ici (pour l'instant, je viens de finir l'interface graphique. J'attaque le \"dur\" ^^)

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

Plus d'informations
il y a 7 ans 7 mois #22145 par Philippe
je t'en pris ;)

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

Plus d'informations
il y a 7 ans 7 mois #22148 par ThomasM
Réponse de ThomasM sur le sujet Re:WindowsForm, Textbox & Label
Bonjour,
j'ai essayé de remanier de façon à ce que cela fonctionne dans mon script (jusqu'ici normal).

Voici mon nouveau problème : Quand j'écris n'importe quoi dans une textbox qui se trouve dans une form2, je n'ai pas de suite le résultat.
Je m'explique : il faut que j’éteigne le script, que je le relance, ne rien écrire dans la textbox appuyer sur mon bouton suivant et la seulement il m'affiche ce que j'ai mis auparavant ...

Étant débutant, je ne cherche pas à ce qu'on me donne tout cuit (même si la dernière réponse m'a fait gagner du temps :D) si vous pouviez me guider de la démarche à suivre, cela serait sympa ! merci

voici ma form2 et form3 entière :
[code:1]#####################################################################################
# Page 2 - Recherche du ou des utilisateurs
# Début.form2
#####################################################################################

#################################################
# CONFIGURATION DE LA WINDOWS FORM
#################################################

# Chargement des Windows Form
[void][System.Reflection.Assembly]::LoadWithPartialName(\"System.Windows.forms\"«»)
[void][System.Reflection.Assembly]::LoadWithPartialName(\"System.Drawing\"«»)

# Creation de la form principale
$form2 = New-Object Windows.Forms.form

# Pour supprimer le bouton quitter (croix rouge)
$form2.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedDialog
$form2.ControlBox = $false

# Pour mettre la fenêtre en grand écran
$form2.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedDialog
$form2.WindowState=\"Maximized\"

# Titre
$form2.Text = \"Centre d'administation des licences O365\"


#################################################
# AJOUT DES COMPOSANTS
#################################################

# Bouton Suivant
$button_suivant2 = New-Object System.Windows.Forms.Button
$button_suivant2.Text = \"Suivant\"
$button_suivant2.Size = New-Object System.Drawing.Size(110,23)
$button_suivant2.Location = New-Object System.drawing.Point(300,40)
$form2.Controls.Add($suivant2)

# Bouton Fermer
$button_fermer2 = New-Object System.Windows.Forms.Button
$button_fermer2.Text = \"Fermer\"
$button_fermer2.Size = New-Object System.drawing.Size(110,23)
$button_fermer2.Location = New-Object System.drawing.Point(300,220)

# Bouton Parcourir
$button_parcourir = New-Object System.Windows.Forms.Button
$button_parcourir.Text = \"Parcourir\"
$button_parcourir.Size = New-Object System.Drawing.Size(110,23)
$button_parcourir.Location = New-Object System.Drawing.Point(300,120)

# Bouton Valider
$button_valider = New-Object System.Windows.Forms.Button
$button_valider.Text = \"Valider\"
$button_valider.Size = New-Object System.Drawing.Size(110,23)
$button_valider.Location = New-Object System.Drawing.Point(300,150)

# Label_1 : Champs de recherche d'un utilisateur
$label_1 = New-Object System.Windows.Forms.Label
$label_1.Size = New-Object System.Drawing.Size(350,20)
$Label_1.Location = New-Object System.Drawing.Point(10,20)
$label_1.Text = \"Veuillez entrer le nom d'utilisateur concerné :\"

# Label_2 : Sélectionner un fichier .csv
$label_2 = New-Object System.Windows.Forms.Label
$label_2.Size = New-Object System.Drawing.Size(350,20)
$label_2.Location = New-Object System.Drawing.Point(10,100)
$label_2.text = \"Sélectionner un fichier :\"

# Zone de texte_1
$textbox_1 = New-Object System.Windows.Forms.TextBox
$textbox_1.Size = New-Object System.Drawing.Size(260,20)
$textbox_1.Location = New-Object System.Drawing.Point(10,40)
$form2.Controls.Add($textbox_1)

$form2.Topmost = $true

# Zone de texte_2
$textbox_2 = New-Object Windows.Forms.TextBox
$textbox_2.Size = New-Object System.Drawing.Size(260,20)
$textbox_2.Location = New-Object System.Drawing.Point(10,120)
$textbox_2.Text = \"\"
$form2.Controls.Add($textbox_2)

$form2.Topmost = $true

$form2.Add_Shown({$textbox_2.Select})


#################################################
# GESTION D'EVENEMENTS
#################################################

# Bouton \"Fermer\"
$button_fermer2.Add_Click(
{
$form2.Close()
$form3.Close()
})

# Bouton \"Suivant\"
$button_suivant2.Add_Click(
{
$Script:Texte = $TextBox_1.Text
$form2.Hide()
$form3.ShowDialog()
})
$form2.Add_Shown({ $form2.Activate })

# Bouton \"Parcourir\"
$Button_parcourir.Add_Click(
{
#Création d'un objet \"ouverture de fichier\"
$parcourir = New-Object System.Windows.Forms.OpenFileDialog
#Initialisation du chemin par défaut
$parcourir.initialDirectory = \"C:\"
#Ici on va afficher que les fichiers en \".csv\"
$parcourir.Filter = \"CSV Files (*.csv)| *.csv\"
#Affiche la fenêtre d'ouverture de fichier
$retour = $parcourir.ShowDialog()
#Traitement du retour, si \"Valider\" on affiche le fichier sélectionné dans la TextBox_2, Sinon on affiche un fichier par défaut.
if ($retour -eq \"OK\"«»)
{
$textbox_2.Text = $parcourir.Filename
}
else
{
$textbox_2.Text = \"D:exemple.csv\"
}
})

# Bouton \"Valider\"
$Button_valider.Add_Click(
{
$form2.Hide()
$form3.ShowDialog()
})

#################################################
# Ajout des composants a la Form
#################################################

$form2.Controls.Add($button_suivant2)
$form2.Controls.Add($button_fermer2)
$form2.Controls.Add($button_parcourir)
$form2.Controls.Add($Button_valider)
$form2.Controls.Add($label_1)
$form2.Controls.Add($label_2)
$form2.Controls.Add($texbox_1)
$form2.Controls.Add($texbox_2)
#$form2.Controls.Add($result_1)

$form2.ShowDialog()


#####################################################################################
# Fin.form2
#####################################################################################
# Page 3 - Attribution ou Suppression des licences pour un ou plusieurs utilisateurs
# Début.form3
#####################################################################################

#################################################
# CONFIGURATION DE LA WINDOWS FORM
#################################################

# Chargement des Windows Form
[void][System.Reflection.Assembly]::LoadWithPartialName(\"System.Windows.forms\"«»)
[void][System.Reflection.Assembly]::LoadWithPartialName(\"System.Drawing\"«»)

# Creation de la form principale
$form3 = New-Object Windows.Forms.form

# Pour supprimer le bouton quitter (croix rouge)
$form3.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedDialog
$form3.ControlBox = $false

# Pour mettre la fenêtre en grand écran
$form3.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedDialog
$form3.WindowState=\"Maximized\"

# Titre
$form3.Text = \"Centre d'administation des licences O365 - NEXITY\"


#################################################
# AJOUT DES COMPOSANTS
#################################################

# Bouton Suivant
$button_suivant3 = New-Object System.Windows.Forms.Button
$button_suivant3.Text = \"Suivant\"
$button_suivant3.Size = New-Object System.Drawing.Size(120,40)
$button_suivant3.Location = New-Object System.drawing.Point(150,200)

# Bouton Quitter
$Button_fermer3 = New-Object System.Windows.Forms.Button
$button_fermer3.Text = \"Fermer\"
$button_fermer3.Size = New-Object System.drawing.Size(120,40)
$button_fermer3.Location = New-Object System.drawing.Point(150,250)

# Affichage du nom d'utilisateur recherché : \"_ru\" = Recherche Unitaire
$label_ru = New-Object System.Windows.Forms.Label
$label_ru.Text = $Texte
$label_ru.Size = New-Object System.drawing.Size(160,30)
$label_ru.Location = New-Object System.drawing.Point(30,10)
$form3.Controls.Add($label_ru)

$form3.Add_Shown({ $form3.Activate })

# CheckBox x10 - Case à cocher
$checkbox_un = new-object System.Windows.Forms.CheckBox
$checkbox_un.AutoSize = $true
$checkbox_un.Location = New-Object System.Drawing.Point(30,50)
$checkbox_un.Size = New-Object System.Drawing.Size(60,20)
$checkbox_un.Name = \"checkbox_un\"
$checkbox_un.Text = \"Office 365 Entreprise - E3\"

$checkbox_deux = new-object System.Windows.Forms.CheckBox
$checkbox_deux.AutoSize = $true
$checkbox_deux.Location = New-Object System.Drawing.Point(30,70)
$checkbox_deux.Size = New-Object System.Drawing.Size(80,20)
$checkbox_deux.Name = \"checkbox_deux\"
$checkbox_deux.Text = \"Microsoft Planner - E3\"

$checkbox_trois = new-object System.Windows.Forms.CheckBox
$checkbox_trois.AutoSize = $true
$checkbox_trois.Location = New-Object System.Drawing.Point(30,90)
$checkbox_trois.Size = New-Object System.Drawing.Size(100,20)
$checkbox_trois.Name = \"checkbox_trois\"
$checkbox_trois.Text = \"Sway - E3\"

$checkbox_quatre = new-object System.Windows.Forms.CheckBox
$checkbox_quatre.AutoSize = $true
$checkbox_quatre.Location = New-Object System.Drawing.Point(30,110)
$checkbox_quatre.Size = New-Object System.Drawing.Size(120,20)
$checkbox_quatre.Name = \"checkbox_quatre\"
$checkbox_quatre.Text = \"Yammer Entreprise - E3\"

$checkbox_cinq = new-object System.Windows.Forms.CheckBox
$checkbox_cinq.AutoSize = $true
$checkbox_cinq.Location = New-Object System.Drawing.Point(30,130)
$checkbox_cinq.Size = New-Object System.Drawing.Size(140,20)
$checkbox_cinq.Name = \"checkbox_cinq\"
$checkbox_cinq.Text = \"Azure Rights Management - E3\"

$checkbox_six = new-object System.Windows.Forms.CheckBox
$checkbox_six.AutoSize = $true
$checkbox_six.Location = New-Object System.Drawing.Point(230,50)
$checkbox_six.Size = New-Object System.Drawing.Size(60,60)
$checkbox_six.Name = \"checkbox_six\"
$checkbox_six.Text = \"Office 365 ProPlus - E3\"

$checkbox_sept = new-object System.Windows.Forms.CheckBox
$checkbox_sept.AutoSize = $true
$checkbox_sept.Location = New-Object System.Drawing.Point(230,70)
$checkbox_sept.Size = New-Object System.Drawing.Size(60,90)
$checkbox_sept.Name = \"checkbox_sept\"
$checkbox_sept.Text = \"Skype Entreprise Online (plan 2) - E3\"

$checkbox_huit = new-object System.Windows.Forms.CheckBox
$checkbox_huit.AutoSize = $true
$checkbox_huit.Location = New-Object System.Drawing.Point(230,90)
$checkbox_huit.Size = New-Object System.Drawing.Size(60,110)
$checkbox_huit.Name = \"checkbox_huit\"
$checkbox_huit.Text = \"Office Online - E3\"

$checkbox_neuf = new-object System.Windows.Forms.CheckBox
$checkbox_neuf.AutoSize = $true
$checkbox_neuf.Location = New-Object System.Drawing.Point(230,110)
$checkbox_neuf.Size = New-Object System.Drawing.Size(60,130)
$checkbox_neuf.Name = \"checkbox_neuf\"
$checkbox_neuf.Text = \"SharePoint Online (plan 2) - E3\"

$checkbox_dix = new-object System.Windows.Forms.CheckBox
$checkbox_dix.AutoSize = $true
$checkbox_dix.Location = New-Object System.Drawing.Point(230,130)
$checkbox_dix.Size = New-Object System.Drawing.Size(60,150)
$checkbox_dix.Name = \"checkbox_dix\"
$checkbox_dix.Text = \"Exchange (plan 2) - E3\"


#################################################
# GESTION D'EVENEMENTS
#################################################

# Gestion d'événement quand on clique sur le bouton fermer
$button_fermer3.Add_Click(
{
$form3.Close()
})

# Gestion d'événement quand on clique sur le bouton suivant
$button_suivant3.Add_Click(
{
$form3.AcceptButton = $button_suivant3
})

# Ajout des composants a la Form
$form3.Controls.Add($button_suivant3)
$form3.Controls.Add($button_fermer3)
$form3.Controls.Add($label_ru)
$form3.Controls.Add($checkbox_un)
$form3.Controls.Add($checkbox_deux)
$form3.Controls.Add($checkbox_trois)
$form3.Controls.Add($checkbox_quatre)
$form3.Controls.Add($checkbox_cinq)
$form3.Controls.Add($checkbox_six)
$form3.Controls.Add($checkbox_sept)
$form3.Controls.Add($checkbox_huit)
$form3.Controls.Add($checkbox_neuf)
$form3.Controls.Add($checkbox_dix)

#####################################################################################
# Fin.form3
#####################################################################################
# Fin du script
#####################################################################################[/code:1]

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

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