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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
Imports System
Imports System.ComponentModel
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Drawing.Drawing2D
Public Class Cl_CercleControl
Inherits Control
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
Me.PaintCercleControl(e)
'RAJOUTE CECI
'APPEL A LA CLASSE DE BASE OnPaint
MyBase.OnPaint(e)
End Sub
Protected Sub PaintCercleControl(ByVal e As PaintEventArgs)
Dim myPath As New Drawing2D.GraphicsPath
Dim reg1 As New Region
Dim g As Graphics = e.Graphics
'******************************************************************************
' Dessin du rectangle support
'******************************************************************************
e.Graphics.FillRectangle(New SolidBrush(Color.Red), Me.ClientRectangle)
Dim Rec_Support As New Rectangle(0, 0, Me.ClientRectangle.Width - 1, Me.ClientRectangle.Height - 1)
myPath.StartFigure()
myPath.AddEllipse(Rec_Support)
myPath.CloseFigure()
'******************************************************************************
' Définition des régions
'******************************************************************************
Me.Region = New Region(myPath)
e.Graphics.SmoothingMode = SmoothingMode.HighQuality
e.Graphics.FillPath(Brushes.Pink, myPath)
e.Graphics.DrawPath(Pens.Black, myPath)
End Sub
Private Sub Quartier_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
MsgBox("Cercle !")
'PEINTURE A RAFRAICHIR
Me.Refresh()
End Sub
Public Sub New()
MyBase.New()
' Enable Double Buffering to remove flicker
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.UserPaint, True)
Me.SetStyle(ControlStyles.DoubleBuffer, True)
Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True)
'RAJOUTE CECI POUR GERER LA REPEINTURE DU CONTROLE LORS DU RESIZE
Me.SetStyle(ControlStyles.ResizeRedraw, True)
End Sub
End Class
Imports System
Imports System.ComponentModel
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Drawing.Drawing2D
Public Class Cl_TriangleControl
Inherits Control
'RAJOUTE CECI PORTEE GLOBALE
Dim myCercle As New Cl_CercleControl
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
Me.PaintTriangleControl(e)
'RAJOUTE CECI
'APPEL A LA CLASSE DE BASE OnPaint
MyBase.OnPaint(e)
End Sub
Protected Sub PaintTriangleControl(ByVal e As PaintEventArgs)
Dim myPath As New Drawing2D.GraphicsPath
Dim reg1 As New Region
Dim g As Graphics = e.Graphics
'******************************************************************************
' Dessin du rectangle support
'******************************************************************************
e.Graphics.FillRectangle(New SolidBrush(Color.Transparent), Me.ClientRectangle)
Dim Rec_Support As New Rectangle(0, 0, Me.ClientRectangle.Width - 1, Me.ClientRectangle.Height - 1)
myPath.StartFigure()
myPath.AddLine(Rec_Support.X, Rec_Support.Y, Rec_Support.Width, Rec_Support.Height - 1)
myPath.AddLine(Rec_Support.Width, Rec_Support.Height - 1, Rec_Support.X, Rec_Support.Height - 1)
myPath.CloseFigure()
'******************************************************************************
' Définition des régions
'******************************************************************************
Me.Region = New Region(myPath)
e.Graphics.SmoothingMode = SmoothingMode.HighQuality
e.Graphics.FillPath(Brushes.Aqua, myPath)
e.Graphics.DrawPath(Pens.Black, myPath)
'DEPLACER
'l'ajout d'un control au container parent ne peut pas
'dans l"evenement peinture du parent
'zone reserve exclusiment à peinture du parent.
'Dim myCercle As New Cl_CercleControl
'myCercle.Width = 50
'myCercle.Height = 50
'Me.Controls.Add(myCercle)
End Sub
Private Sub Quartier_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
MsgBox("Triangle !")
'PEINTURE A RAFRAICHIR
Me.Refresh()
End Sub
Public Sub New()
MyBase.New()
' Enable Double Buffering to remove flicker
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.UserPaint, True)
Me.SetStyle(ControlStyles.DoubleBuffer, True)
Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True)
'RAJOUTE CECI POUR GERER LA REPEINTURE DU CONTROLE
Me.SetStyle(ControlStyles.ResizeRedraw, True)
'ICI AJOUT DU 2EME CONTROL "MYCERCLE" ET SON POSITION SE FERONT ICI
myCercle.Width = 50
myCercle.Height = 50
Me.Controls.Add(myCercle)
'POSITION PEUT ETRE DOCKE ou PERSONNALISE
myCercle.Dock = DockStyle.Fill
End Sub
End Class |
Partager