function Set-DeployCenterButtonStyle { param( [Parameter(Mandatory=$true)][System.Windows.Forms.Button]$Button, [Parameter(Mandatory=$true)][System.Collections.IDictionary]$Theme, [ValidateSet('Button','PrimaryButton','DangerButton')][string]$Role = 'Button' ) $style = $Theme[$Role] $Button.BackColor = $style.Background $Button.ForeColor = $style.Foreground $Button.FlatStyle = [System.Windows.Forms.FlatStyle]::Flat $Button.UseVisualStyleBackColor = $false $Button.FlatAppearance.BorderSize = 1 $Button.FlatAppearance.BorderColor = $style.Border $Button.FlatAppearance.MouseOverBackColor = $style.HoverBackground $Button.FlatAppearance.MouseDownBackColor = $style.PressedBackground if (-not $Button.Enabled) { $Button.BackColor = $style.DisabledBackground $Button.ForeColor = $style.DisabledForeground } } function New-DeployCenterComboBox { param( [Parameter(Mandatory=$true)][string]$Name, [Parameter(Mandatory=$true)][System.Collections.IDictionary]$Theme, [Parameter(Mandatory=$true)][System.Drawing.Font]$Font, [Parameter(Mandatory=$true)][string[]]$Items ) $comboBox = New-Object System.Windows.Forms.ComboBox $comboBox.Name = $Name $comboBox.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList $comboBox.FlatStyle = [System.Windows.Forms.FlatStyle]::Flat $comboBox.BackColor = $Theme.PanelAlt $comboBox.ForeColor = $Theme.Text $comboBox.Font = $Font $comboBox.IntegralHeight = $false $comboBox.MaxDropDownItems = 12 foreach ($item in $Items) { [void]$comboBox.Items.Add($item) } return $comboBox } function Set-DeployCenterComboBoxTheme { param( [Parameter(Mandatory=$true)][System.Windows.Forms.ComboBox]$ComboBox, [Parameter(Mandatory=$true)][System.Collections.IDictionary]$Theme ) $ComboBox.BackColor = $Theme.PanelAlt $ComboBox.ForeColor = $Theme.Text } function New-DeployCenterPartitionProfileSelector { param( [Parameter(Mandatory=$true)][System.Windows.Forms.GroupBox]$Parent, [Parameter(Mandatory=$true)][string[]]$ProfileNames, [Parameter(Mandatory=$true)][System.Collections.IDictionary]$Theme, [Parameter(Mandatory=$true)][System.Drawing.Font]$Font ) $label = New-Object System.Windows.Forms.Label $label.Text = 'Profil de partitionnement' $label.Size = New-Object System.Drawing.Size(240, 17) $label.ForeColor = $Theme.Text $label.BackColor = [System.Drawing.Color]::Transparent $label.Font = $Font $comboBox = New-DeployCenterComboBox -Name 'cmbPartitionProfile' -Theme $Theme -Font $Font -Items $ProfileNames $Parent.Controls.Add($label) $Parent.Controls.Add($comboBox) Set-DeployCenterPartitionProfileSelectorLayout -Label $label -ComboBox $comboBox -Width ($Parent.ClientSize.Width - 24) return [pscustomobject]@{ Label = $label; ComboBox = $comboBox } } function Set-DeployCenterPartitionProfileSelectorLayout { param( [Parameter(Mandatory=$true)][System.Windows.Forms.Label]$Label, [Parameter(Mandatory=$true)][System.Windows.Forms.ComboBox]$ComboBox, [Parameter(Mandatory=$true)][int]$Width ) $Label.Location = New-Object System.Drawing.Point(12, 66) $ComboBox.Location = New-Object System.Drawing.Point(12, 84) $ComboBox.Size = New-Object System.Drawing.Size([Math]::Max(250, $Width), 26) } function Show-DeployCenterMessage { param( [Parameter(Mandatory=$true)][string]$Message, [Parameter(Mandatory=$true)][string]$Title, [ValidateSet('Information','Warning','Error')][string]$Icon = 'Information', [System.Windows.Forms.Form]$Owner = $null, [Parameter(Mandatory=$true)][System.Collections.IDictionary]$Theme, [Parameter(Mandatory=$true)][System.Drawing.Font]$Font ) $messageForm = New-Object System.Windows.Forms.Form $messageForm.Text = $Title $messageForm.StartPosition = if ($Owner) { 'CenterParent' } else { 'CenterScreen' } $messageForm.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedDialog $messageForm.ShowInTaskbar = $false $messageForm.MinimizeBox = $false $messageForm.MaximizeBox = $false $messageForm.BackColor = $Theme.Background $messageForm.ForeColor = $Theme.Text $messageForm.Font = $Font $messageWidth = 390 $textSize = [System.Windows.Forms.TextRenderer]::MeasureText( $Message, $Font, (New-Object System.Drawing.Size($messageWidth, 0)), [System.Windows.Forms.TextFormatFlags]::WordBreak ) $messageHeight = [Math]::Max(42, $textSize.Height + 8) $messageForm.ClientSize = New-Object System.Drawing.Size(470, ($messageHeight + 94)) $iconLabel = New-Object System.Windows.Forms.Label $iconLabel.Location = New-Object System.Drawing.Point(18, 24) $iconLabel.Size = New-Object System.Drawing.Size(34, 34) $iconLabel.Text = if ($Icon -eq 'Information') { 'i' } else { '!' } $iconLabel.TextAlign = [System.Drawing.ContentAlignment]::MiddleCenter $iconLabel.Font = New-Object System.Drawing.Font('Segoe UI', [single]16, [System.Drawing.FontStyle]::Bold) $iconLabel.ForeColor = if ($Icon -eq 'Error') { $Theme.Danger } else { $Theme.Accent } $iconLabel.BackColor = [System.Drawing.Color]::Transparent $messageForm.Controls.Add($iconLabel) $messageLabel = New-Object System.Windows.Forms.Label $messageLabel.Location = New-Object System.Drawing.Point(64, 20) $messageLabel.Size = New-Object System.Drawing.Size($messageWidth, $messageHeight) $messageLabel.Text = $Message $messageLabel.ForeColor = $Theme.Text $messageLabel.BackColor = [System.Drawing.Color]::Transparent $messageLabel.TextAlign = [System.Drawing.ContentAlignment]::MiddleLeft $messageLabel.Font = $Font $messageForm.Controls.Add($messageLabel) $buttonPanel = New-Object System.Windows.Forms.Panel $buttonPanel.Dock = [System.Windows.Forms.DockStyle]::Bottom $buttonPanel.Height = 58 $buttonPanel.BackColor = $Theme.PanelAlt $messageForm.Controls.Add($buttonPanel) $okButton = New-Object System.Windows.Forms.Button $okButton.Text = 'OK' $okButton.Location = New-Object System.Drawing.Point(362, 10) $okButton.Size = New-Object System.Drawing.Size(92, 36) $okButton.Font = $Font $okButton.Cursor = [System.Windows.Forms.Cursors]::Hand $okButton.DialogResult = [System.Windows.Forms.DialogResult]::OK Set-DeployCenterButtonStyle -Button $okButton -Theme $Theme -Role 'PrimaryButton' $buttonPanel.Controls.Add($okButton) $messageForm.AcceptButton = $okButton $messageForm.CancelButton = $okButton if ($Owner) { [void]$messageForm.ShowDialog($Owner) } else { [void]$messageForm.ShowDialog() } $messageForm.Dispose() } Export-ModuleMember -Function Set-DeployCenterButtonStyle, New-DeployCenterComboBox, Set-DeployCenterComboBoxTheme, New-DeployCenterPartitionProfileSelector, Set-DeployCenterPartitionProfileSelectorLayout, Show-DeployCenterMessage