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 176 177 178 179 180 181 182 183 184 185 186 187
|
Imports System.Windows.Forms.Design
Namespace Editor
' This control provides the custom UI for the LightShape property
' of the MarqueeBorder. It is used by the LightShapeEditor.
Public Class LightShapeSelectionControl
Inherits UserControl
Private lightShapeValue As MarqueeLightShape = MarqueeLightShape.Square
Private editorService As IWindowsFormsEditorService
Private squarePanel As Panel
Private circlePanel As Panel
' Required designer variable.
Private components As System.ComponentModel.Container = Nothing
' This constructor takes a MarqueeLightShape value from the
' design-time environment, which will be used to display
' the initial state.
Public Sub New(
ByVal lightShape As MarqueeLightShape,
ByVal editorService As IWindowsFormsEditorService)
' This call is required by the Windows.Forms Form Designer.
InitializeComponent()
' Cache the light shape value provided by the
' design-time environment.
Me.lightShapeValue = lightShape
' Cache the reference to the editor service.
Me.editorService = editorService
' Handle the Click event for the two panels.
AddHandler Me.squarePanel.Click, AddressOf squarePanel_Click
AddHandler Me.circlePanel.Click, AddressOf circlePanel_Click
End Sub
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
' Be sure to unhook event handlers
' to prevent "lapsed listener" leaks.
RemoveHandler Me.squarePanel.Click, AddressOf squarePanel_Click
RemoveHandler Me.circlePanel.Click, AddressOf circlePanel_Click
If (components IsNot Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
' LightShape is the property for which this control provides
' a custom user interface in the Properties window.
Public Property LightShape() As MarqueeLightShape
Get
Return Me.lightShapeValue
End Get
Set(ByVal Value As MarqueeLightShape)
If Me.lightShapeValue <> Value Then
Me.lightShapeValue = Value
End If
End Set
End Property
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e)
Dim gCircle As Graphics = Me.circlePanel.CreateGraphics()
Try
Dim gSquare As Graphics = Me.squarePanel.CreateGraphics()
Try
' Draw a filled square in the client area of
' the squarePanel control.
gSquare.FillRectangle(
Brushes.Red,
0,
0,
Me.squarePanel.Width,
Me.squarePanel.Height)
' If the Square option has been selected, draw a
' border inside the squarePanel.
If Me.lightShapeValue = MarqueeLightShape.Square Then
gSquare.DrawRectangle(
Pens.Black,
0,
0,
Me.squarePanel.Width - 1,
Me.squarePanel.Height - 1)
End If
' Draw a filled circle in the client area of
' the circlePanel control.
gCircle.Clear(Me.circlePanel.BackColor)
gCircle.FillEllipse(
Brushes.Blue,
0,
0,
Me.circlePanel.Width,
Me.circlePanel.Height)
' If the Circle option has been selected, draw a
' border inside the circlePanel.
If Me.lightShapeValue = MarqueeLightShape.Circle Then
gCircle.DrawRectangle(
Pens.Black,
0,
0,
Me.circlePanel.Width - 1,
Me.circlePanel.Height - 1)
End If
Finally
gSquare.Dispose()
End Try
Finally
gCircle.Dispose()
End Try
End Sub
Private Sub squarePanel_Click(
ByVal sender As Object,
ByVal e As EventArgs)
Me.lightShapeValue = MarqueeLightShape.Square
Me.Invalidate(False)
Me.editorService.CloseDropDown()
End Sub
Private Sub circlePanel_Click(
ByVal sender As Object,
ByVal e As EventArgs)
Me.lightShapeValue = MarqueeLightShape.Circle
Me.Invalidate(False)
Me.editorService.CloseDropDown()
End Sub
#Region "Component Designer generated code"
'/ <summary>
'/ Required method for Designer support - do not modify
'/ the contents of this method with the code editor.
'/ </summary>
Private Sub InitializeComponent()
Me.squarePanel = New Panel
Me.circlePanel = New Panel
Me.SuspendLayout()
'
' squarePanel
'
Me.squarePanel.Location = New Point(8, 10)
Me.squarePanel.Name = "squarePanel"
Me.squarePanel.Size = New Size(60, 60)
Me.squarePanel.TabIndex = 2
'
' circlePanel
'
Me.circlePanel.Location = New Point(80, 10)
Me.circlePanel.Name = "circlePanel"
Me.circlePanel.Size = New Size(60, 60)
Me.circlePanel.TabIndex = 3
'
' LightShapeSelectionControl
'
Me.Controls.Add(squarePanel)
Me.Controls.Add(circlePanel)
Me.Name = "LightShapeSelectionControl"
Me.Size = New Size(150, 80)
Me.ResumeLayout(False)
End Sub
#End Region
End Class
End Namespace |
Partager