1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| Public FondDÉcran As Image
Public CouleurDeFond As Color
Private _Buffer As System.Drawing.BufferedGraphics
Protected Overrides Sub OnSizeChanged(ByVal e As System.EventArgs)
MyBase.OnSizeChanged(e)
On Error Resume Next
If _Buffer IsNot Nothing Then _Buffer.Dispose() ' vu qu'on risque de passer plusieurs fois ici, on s'arrange pour ne pas faire de fuite de mémoire en détruisant l'ancienne valeur
_buffer = system.drawing.bufferedgraphicsManager.Current.Allocate(Me.creategraphics, Me.clientrectangle)
End Sub ' on demande l'allocation du buffer en lui donnant me.creategraphics comme surface de rendu par défaut, et la faille
Protected Overrides Sub OnPaintBackground(ByVal e As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaintBackground(e)
_Buffer.Render(e.Graphics) ' on demande le rendu sur le graphics fournit par onpaint
'Modes de dessin
_Buffer.Graphics.InterpolationMode = Drawing2D.InterpolationMode.NearestNeighbor
_Buffer.Graphics.PixelOffsetMode = Drawing2D.PixelOffsetMode.HighQuality
'Représente les mesures de la barre où tous mes controles sont dessus
Dim PnlTop = PnlNavigationStrip.Top
Dim PnlHeight = PnlNavigationStrip.Height
_Buffer.Graphics.Clip = New Region(e.ClipRectangle)
'Exclue le reste (en Dessous de ma barre de navigation)
_Buffer.Graphics.ExcludeClip(New Rectangle(0, PnlTop + PnlHeight, Me.Width, Me.Height))
'Peint la couleur de fond
REM Je ne peux pas simplement changer la couleur avec Me.Backcolor car le tout est peint sur de la transparence (Windows 7)
Dim b As New Bitmap(1, 1)
Dim g As Graphics = Graphics.FromImage(b)
g.Clear(CouleurDeFond)
_Buffer.Graphics.DrawImage(b, 0, 0, Me.ClientSize.Width + 10, PnlTop + PnlHeight)
'Dessine l'image de fond
_Buffer.Graphics.DrawImage(FondDÉcran, Me.Width - FondDÉcran.Width - SystemInformation.SizingBorderWidth - 2, _
0, _
FondDÉcran.Width, _
FondDÉcran.Height)
'Dessine des bordures
Dim p As New Pen(Color.FromArgb(150, 255, 255, 255))
'Haut
_Buffer.Graphics.DrawLine(Pens.Black, 1, 1, Me.Width, 1)
_Buffer.Graphics.DrawLine(p, 1, 2, Me.Width, 2)
'Gauche
_Buffer.Graphics.DrawLine(Pens.Black, 1, 1, 1, PnlTop + PnlHeight)
_Buffer.Graphics.DrawLine(p, 2, 2, 2, PnlTop + PnlHeight)
'Droite
_Buffer.Graphics.DrawLine(Pens.Black, Me.Width, 1, Me.Width, PnlTop + PnlHeight)
_Buffer.Graphics.DrawLine(p, Me.Width - 1, 2, Me.Width - 1, PnlTop + PnlHeight)
End Sub |
Partager