Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
# ============================================
# FONCTIONS PERSONNALISÉES AVEC DESIGN MODERNE
# ============================================
function Add-Tb {
param(
[string]$Name,
[string]$Placeholder = "",
[int]$X,
[int]$Y,
[int]$Width = 320,
[int]$Height = 40,
[bool]$Required = $false,
[System.Windows.Forms.Form]$Form
)
$textBox = New-Object System.Windows.Forms.TextBox
$textBox.Location = New-Object System.Drawing.Point($X, $Y)
$textBox.Size = New-Object System.Drawing.Size($Width, $Height)
$textBox.Name = $Name
$textBox.Font = New-Object System.Drawing.Font("Segoe UI", 10, [System.Drawing.FontStyle]::Regular)
$textBox.BorderStyle = [System.Windows.Forms.BorderStyle]::FixedSingle
$textBox.BackColor = [System.Drawing.Color]::FromArgb(248, 250, 252)
$textBox.ForeColor = [System.Drawing.Color]::FromArgb(30, 41, 59)
# Placeholder text
if ($Placeholder -ne "") {
$textBox.Text = $Placeholder
$textBox.ForeColor = [System.Drawing.Color]::FromArgb(148, 163, 184)
$textBox.Add_GotFocus({
if ($this.Text -eq $Placeholder) {
$this.Text = ""
$this.ForeColor = [System.Drawing.Color]::FromArgb(30, 41, 59)
}
})
$textBox.Add_LostFocus({
if ($this.Text.Trim() -eq "") {
$this.Text = $Placeholder
$this.ForeColor = [System.Drawing.Color]::FromArgb(148, 163, 184)
}
})
}
# Animation hover
$textBox.Add_MouseEnter({
if ($this.Text -ne $Placeholder -or $Placeholder -eq "") {
$this.BackColor = [System.Drawing.Color]::FromArgb(241, 245, 249)
$this.BorderStyle = [System.Windows.Forms.BorderStyle]::FixedSingle
}
})
$textBox.Add_MouseLeave({
if ($this.Text -ne $Placeholder -or $Placeholder -eq "") {
$this.BackColor = [System.Drawing.Color]::FromArgb(248, 250, 252)
}
})
# Validation en temps réel pour les champs obligatoires
if ($Required) {
$textBox.Add_TextChanged({
if ($this.Text.Trim() -eq "" -or $this.Text -eq $Placeholder) {
$this.BackColor = [System.Drawing.Color]::FromArgb(254, 242, 242)
$this.BorderStyle = [System.Windows.Forms.BorderStyle]::FixedSingle
} else {
$this.BackColor = [System.Drawing.Color]::FromArgb(237, 247, 237)
$this.BorderStyle = [System.Windows.Forms.BorderStyle]::FixedSingle
}
})
}
return $textBox
}
function New-Bouton {
param(
[string]$Text,
[int]$X,
[int]$Y,
[int]$Width = 320,
[int]$Height = 45,
[string]$Style = "primary", # primary, secondary, success, danger
[scriptblock]$OnClick
)
$button = New-Object System.Windows.Forms.Button
$button.Location = New-Object System.Drawing.Point($X, $Y)
$button.Size = New-Object System.Drawing.Size($Width, $Height)
$button.Text = $Text
$button.Font = New-Object System.Drawing.Font("Segoe UI", 10, [System.Drawing.FontStyle]::Bold)
$button.FlatStyle = [System.Windows.Forms.FlatStyle]::Flat
$button.Cursor = [System.Windows.Forms.Cursors]::Hand
$button.FlatAppearance.BorderSize = 0
# Styles de bouton modernes
switch ($Style) {
"primary" {
$button.BackColor = [System.Drawing.Color]::FromArgb(59, 130, 246)
$button.ForeColor = [System.Drawing.Color]::White
}
"secondary" {
$button.BackColor = [System.Drawing.Color]::FromArgb(100, 116, 139)
$button.ForeColor = [System.Drawing.Color]::White
}
"success" {
$button.BackColor = [System.Drawing.Color]::FromArgb(34, 197, 94)
$button.ForeColor = [System.Drawing.Color]::White
}
"danger" {
$button.BackColor = [System.Drawing.Color]::FromArgb(239, 68, 68)
$button.ForeColor = [System.Drawing.Color]::White
}
default {
$button.BackColor = [System.Drawing.Color]::FromArgb(59, 130, 246)
$button.ForeColor = [System.Drawing.Color]::White
}
}
# Animations hover et click
$button.Add_MouseEnter({
$originalColor = $this.BackColor
$this.BackColor = [System.Drawing.Color]::FromArgb(
[Math]::Min($originalColor.R + 20, 255),
[Math]::Min($originalColor.G + 20, 255),
[Math]::Min($originalColor.B + 20, 255)
)
})
$button.Add_MouseLeave({
switch ($Style) {
"primary" { $this.BackColor = [System.Drawing.Color]::FromArgb(59, 130, 246) }
"secondary" { $this.BackColor = [System.Drawing.Color]::FromArgb(100, 116, 139) }
"success" { $this.BackColor = [System.Drawing.Color]::FromArgb(34, 197, 94) }
"danger" { $this.BackColor = [System.Drawing.Color]::FromArgb(239, 68, 68) }
}
})
$button.Add_MouseDown({
$originalColor = $this.BackColor
$this.BackColor = [System.Drawing.Color]::FromArgb(
[Math]::Max($originalColor.R - 40, 0),
[Math]::Max($originalColor.G - 40, 0),
[Math]::Max($originalColor.B - 40, 0)
)
})
$button.Add_MouseUp({
$this.BackColor = [System.Drawing.Color]::FromArgb(
[Math]::Min($originalColor.R + 20, 255),
[Math]::Min($originalColor.G + 20, 255),
[Math]::Min($originalColor.B + 20, 255)
)
})
if ($OnClick) {
$button.Add_Click($OnClick)
}
return $button
}
function Add-Label {
param(
[string]$Text,
[int]$X,
[int]$Y,
[int]$Width = 320,
[int]$Height = 25,
[string]$Style = "normal" # normal, title, subtitle, required
)
$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point($X, $Y)
$label.Size = New-Object System.Drawing.Size($Width, $Height)
$label.Text = $Text
switch ($Style) {
"title" {
$label.Font = New-Object System.Drawing.Font("Segoe UI", 14, [System.Drawing.FontStyle]::Bold)
$label.ForeColor = [System.Drawing.Color]::FromArgb(15, 23, 42)
}
"subtitle" {
$label.Font = New-Object System.Drawing.Font("Segoe UI", 11, [System.Drawing.FontStyle]::Regular)
$label.ForeColor = [System.Drawing.Color]::FromArgb(71, 85, 105)
}
"required" {
$label.Font = New-Object System.Drawing.Font("Segoe UI", 9, [System.Drawing.FontStyle]::Regular)
$label.ForeColor = [System.Drawing.Color]::FromArgb(239, 68, 68)
}
default {
$label.Font = New-Object System.Drawing.Font("Segoe UI", 10, [System.Drawing.FontStyle]::Regular)
$label.ForeColor = [System.Drawing.Color]::FromArgb(30, 41, 59)
}
}
return $label
}
# ============================================
# INTERFACE PRINCIPALE MODERNE
# ============================================
# Création du formulaire avec design moderne
$form = New-Object System.Windows.Forms.Form
$form.Text = "Application Professionnelle"
$form.Size = New-Object System.Drawing.Size(400, 450)
$form.StartPosition = "CenterScreen"
$form.BackColor = [System.Drawing.Color]::White
$form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedSingle
$form.MaximizeBox = $false
# Header avec dégradé
$headerPanel = New-Object System.Windows.Forms.Panel
$headerPanel.Location = New-Object System.Drawing.Point(0, 0)
$headerPanel.Size = New-Object System.Drawing.Size(400, 80)
$headerPanel.BackColor = [System.Drawing.Color]::FromArgb(59, 130, 246)
$titleLabel = New-Object System.Windows.Forms.Label
$titleLabel.Location = New-Object System.Drawing.Point(20, 20)
$titleLabel.Size = New-Object System.Drawing.Size(360, 40)
$titleLabel.Text = "FORMULAIRE PROFESSIONNEL"
$titleLabel.Font = New-Object System.Drawing.Font("Segoe UI", 16, [System.Drawing.FontStyle]::Bold)
$titleLabel.ForeColor = [System.Drawing.Color]::White
$headerPanel.Controls.Add($titleLabel)
# Contenu principal
$contentPanel = New-Object System.Windows.Forms.Panel
$contentPanel.Location = New-Object System.Drawing.Point(20, 100)
$contentPanel.Size = New-Object System.Drawing.Size(360, 300)
$contentPanel.BackColor = [System.Drawing.Color]::White
# Labels
$nameLabel = Add-Label -Text "Nom complet *" -X 0 -Y 10 -Style "subtitle"
$emailLabel = Add-Label -Text "Adresse email *" -X 0 -Y 80 -Style "subtitle"
$messageLabel = Add-Label -Text "Message" -X 0 -Y 150 -Style "subtitle"
$requiredNote = Add-Label -Text "* Champs obligatoires" -X 0 -Y 240 -Style "required"
# TextBox avec design moderne
$txtNom = Add-Tb -Name "txtNom" -Placeholder "Entrez votre nom" -X 0 -Y 35 -Required $true -Form $form
$txtEmail = Add-Tb -Name "txtEmail" -Placeholder "exemple@domaine.com" -X 0 -Y 105 -Required $true -Form $form
$txtMessage = Add-Tb -Name "txtMessage" -Placeholder "Votre message ici..." -X 0 -Y 175 -Height 60 -Form $form
# Boutons avec design moderne
$btnValider = New-Bouton -Text "VALIDER LE FORMULAIRE" -X 0 -Y 270 -Style "success" -OnClick {
$erreurs = @()
# Validation du nom
if ($txtNom.Text.Trim() -eq "" -or $txtNom.Text -eq "Entrez votre nom") {
$txtNom.BackColor = [System.Drawing.Color]::FromArgb(254, 242, 242)
$erreurs += "Le nom est obligatoire"
}
# Validation de l'email
if ($txtEmail.Text.Trim() -eq "" -or $txtEmail.Text -eq "exemple@domaine.com") {
$txtEmail.BackColor = [System.Drawing.Color]::FromArgb(254, 242, 242)
$erreurs += "L'email est obligatoire"
} elseif ($txtEmail.Text -notmatch '^[^@]+@[^@]+\.[^@]+$' -and $txtEmail.Text -ne "exemple@domaine.com") {
$txtEmail.BackColor = [System.Drawing.Color]::FromArgb(254, 242, 242)
$erreurs += "Format d'email invalide"
}
if ($erreurs.Count -gt 0) {
# Message d'erreur stylé
$errorMsg = "Veuillez corriger les erreurs suivantes :`n`n"
$errorMsg += ($erreurs -join "`n• ")
[System.Windows.Forms.MessageBox]::Show(
$errorMsg,
"Validation du formulaire",
[System.Windows.Forms.MessageBoxButtons]::OK,
[System.Windows.Forms.MessageBoxIcon]::Warning
)
} else {
# Succès - Simulation d'envoi
$btnValider.Text = "ENVOI EN COURS..."
$btnValider.Enabled = $false
# Simulation de délai
$timer = New-Object System.Windows.Forms.Timer
$timer.Interval = 1500
$timer.Add_Tick({
$timer.Stop()
[System.Windows.Forms.MessageBox]::Show(
"Formulaire soumis avec succès !`n`n" +
"Nom: $($txtNom.Text)`n" +
"Email: $($txtEmail.Text)`n" +
"Message: $($txtMessage.Text)",
"Confirmation",
[System.Windows.Forms.MessageBoxButtons]::OK,
[System.Windows.Forms.MessageBoxIcon]::Information
)
$btnValider.Text = "VALIDER LE FORMULAIRE"
$btnValider.Enabled = $true
# Réinitialisation optionnelle
# $txtNom.Text = "Entrez votre nom"
# $txtNom.ForeColor = [System.Drawing.Color]::FromArgb(148, 163, 184)
# $txtEmail.Text = "exemple@domaine.com"
# $txtEmail.ForeColor = [System.Drawing.Color]::FromArgb(148, 163, 184)
# $txtMessage.Text = "Votre message ici..."
# $txtMessage.ForeColor = [System.Drawing.Color]::FromArgb(148, 163, 184)
})
$timer.Start()
}
}
$btnAnnuler = New-Bouton -Text "ANNULER" -X 170 -Y 320 -Width 150 -Style "secondary" -OnClick {
$result = [System.Windows.Forms.MessageBox]::Show(
"Voulez-vous vraiment annuler ?",
"Confirmation",
[System.Windows.Forms.MessageBoxButtons]::YesNo,
[System.Windows.Forms.MessageBoxIcon]::Question
)
if ($result -eq [System.Windows.Forms.DialogResult]::Yes) {
$form.Close()
}
}
# Ajout des contrôles au panel de contenu
$contentPanel.Controls.Add($nameLabel)
$contentPanel.Controls.Add($emailLabel)
$contentPanel.Controls.Add($messageLabel)
$contentPanel.Controls.Add($requiredNote)
$contentPanel.Controls.Add($txtNom)
$contentPanel.Controls.Add($txtEmail)
$contentPanel.Controls.Add($txtMessage)
$contentPanel.Controls.Add($btnValider)
$contentPanel.Controls.Add($btnAnnuler)
# Ajout des panels au formulaire
$form.Controls.Add($headerPanel)
$form.Controls.Add($contentPanel)
# Effet de fondu à l'ouverture
$form.Opacity = 0
$timerFadeIn = New-Object System.Windows.Forms.Timer
$timerFadeIn.Interval = 10
$timerFadeIn.Add_Tick({
if ($form.Opacity -lt 1) {
$form.Opacity += 0.05
} else {
$timerFadeIn.Stop()
}
})
# Affichage du formulaire
$form.Add_Shown({
$timerFadeIn.Start()
$txtNom.Focus()
})
$form.ShowDialog() | Out-Null
· Bleu moderne (#3B82F6) pour l'en-tête
· Gris subtils pour les arrière-plans
· Vert de succès (#22C55E)
· Rouge d'erreur (#EF4444)
# Changer la palette de couleurs
$button.BackColor = [System.Drawing.Color]::FromArgb(139, 92, 246) # Violet
$button.BackColor = [System.Drawing.Color]::FromArgb(14, 165, 233) # Cyan
# Ajouter une ombre (simulée)
$panel.BorderStyle = [System.Windows.Forms.BorderStyle]::FixedSingle
$panel.Padding = New-Object System.Windows.Forms.Padding(1)