OVH Cloud OVH Cloud

MDI Backcolor......

2 réponses
Avatar
Stéphane
Bonjour,

J'ai trouvé un article de Microsoft qui démontre comment changer la couleur
de fond d'un fenêtre MDI...

http://support.microsoft.com/default.aspx?scid=kb;en-us;319417

Le problème...

Cette façon de faire ne convient pas si l'on utilise une valeur de
"DockPadding"...

La couleur de l'espace client est changé mais pas celle du padding....

Quelqu'un peut m'aider à changer la couleur du "DockPadding" .....


Merci !


Stéphane

2 réponses

Avatar
Zoury
Salut Stéphane ! :O)

Voici un exemple :
'***
Option Explicit On

Imports System.ComponentModel

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Code généré par le Concepteur Windows Form "

Public Sub New()
MyBase.New()

'Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()

If (IsMdiContainer) Then
BackColor = SystemColors.AppWorkspace
Else
BackColor = SystemColors.Control
End If

End Sub

'La méthode substituée Dispose du formulaire pour nettoyer la liste des
composants.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Requis par le Concepteur Windows Form
Private components As System.ComponentModel.IContainer

'REMARQUE : la procédure suivante est requise par le Concepteur Windows
Form
'Elle peut être modifiée en utilisant le Concepteur Windows Form.
'Ne la modifiez pas en utilisant l'éditeur de code.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(568, 366)
Me.DockPadding.All = 50
Me.IsMdiContainer = True
Me.KeyPreview = True
Me.Name = "Form1"
Me.Text = "Form1"

End Sub

#End Region

<DefaultValue(GetType(SystemColors), "SystemColors.Control"), _
Browsable(True), _

DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
Public Overrides Property BackColor() As Color
Get
Return MyBase.BackColor
End Get
Set(ByVal Value As Color)
MyBase.BackColor = Value
If (Me.Controls.Count) Then
PaintMDIClientBackColor()
End If
End Set
End Property

Protected Sub PaintMDIClientBackColor()
Dim ctl As Control
For Each ctl In Me.Controls
If (ctl.GetType() Is GetType(MdiClient)) Then
DirectCast(ctl, MdiClient).BackColor = BackColor
End If
Next
End Sub

Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)
e.Graphics.FillRectangle(New SolidBrush(BackColor), e.ClipRectangle)
End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
PaintMDIClientBackColor()
End Sub

Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
' on test la propriété
Me.BackColor = Color.Firebrick
End Sub

End Class
'***

--
Cordialement
Yanick
MVP pour Visual Basic
"Stéphane" a écrit dans le message de
news:
Bonjour,

J'ai trouvé un article de Microsoft qui démontre comment changer la


couleur
de fond d'un fenêtre MDI...

http://support.microsoft.com/default.aspx?scid=kb;en-us;319417

Le problème...

Cette façon de faire ne convient pas si l'on utilise une valeur de
"DockPadding"...

La couleur de l'espace client est changé mais pas celle du padding....

Quelqu'un peut m'aider à changer la couleur du "DockPadding" .....


Merci !


Stéphane


Avatar
Stéphane
Merci beaucoup Zoury,

Je ne pouvais demander mieux...

Au plaisir !

Stéphane

"Zoury" wrote:

Salut Stéphane ! :O)

Voici un exemple :
'***
Option Explicit On

Imports System.ComponentModel

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Code généré par le Concepteur Windows Form "

Public Sub New()
MyBase.New()

'Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()

If (IsMdiContainer) Then
BackColor = SystemColors.AppWorkspace
Else
BackColor = SystemColors.Control
End If

End Sub

'La méthode substituée Dispose du formulaire pour nettoyer la liste des
composants.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Requis par le Concepteur Windows Form
Private components As System.ComponentModel.IContainer

'REMARQUE : la procédure suivante est requise par le Concepteur Windows
Form
'Elle peut être modifiée en utilisant le Concepteur Windows Form.
'Ne la modifiez pas en utilisant l'éditeur de code.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(568, 366)
Me.DockPadding.All = 50
Me.IsMdiContainer = True
Me.KeyPreview = True
Me.Name = "Form1"
Me.Text = "Form1"

End Sub

#End Region

<DefaultValue(GetType(SystemColors), "SystemColors.Control"), _
Browsable(True), _

DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
Public Overrides Property BackColor() As Color
Get
Return MyBase.BackColor
End Get
Set(ByVal Value As Color)
MyBase.BackColor = Value
If (Me.Controls.Count) Then
PaintMDIClientBackColor()
End If
End Set
End Property

Protected Sub PaintMDIClientBackColor()
Dim ctl As Control
For Each ctl In Me.Controls
If (ctl.GetType() Is GetType(MdiClient)) Then
DirectCast(ctl, MdiClient).BackColor = BackColor
End If
Next
End Sub

Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)
e.Graphics.FillRectangle(New SolidBrush(BackColor), e.ClipRectangle)
End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
PaintMDIClientBackColor()
End Sub

Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
' on test la propriété
Me.BackColor = Color.Firebrick
End Sub

End Class
'***

--
Cordialement
Yanick
MVP pour Visual Basic
"Stéphane" a écrit dans le message de
news:
> Bonjour,
>
> J'ai trouvé un article de Microsoft qui démontre comment changer la
couleur
> de fond d'un fenêtre MDI...
>
> http://support.microsoft.com/default.aspx?scid=kb;en-us;319417
>
> Le problème...
>
> Cette façon de faire ne convient pas si l'on utilise une valeur de
> "DockPadding"...
>
> La couleur de l'espace client est changé mais pas celle du padding....
>
> Quelqu'un peut m'aider à changer la couleur du "DockPadding" .....
>
>
> Merci !
>
>
> Stéphane