Imports
System.ComponentModel
Imports
System.ComponentModel.Design
<Designer(
"System.Windows.Forms.Design.ParentControlDesigner, System.Design", GetType(IDesigner))> _
Public
Class PolicyGroupCtrl
#If
DEBUG Then
Private m_changeService As IComponentChangeService
Private m_host As IDesignerHost
#End
If
#If
DEBUG Then
Private Sub PolicyGroupCtrl_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragDrop
'An Object was dropped
If Me.DesignMode Then
Try
lblStatus.Text =
"DragDrop"
Dim binaryFile As String = DirectCast(e.Data.GetData("System.String"), String)
Dim elem As PolicyObject.PolicyElement = Nothing
Dim grp As PolicyObject.PolicyGroup = Nothing
elem =
DirectCast(PolicyObject.Utils.BinaryDeserialize(binaryFile), PolicyObject.PolicyElement)
If Not elem Is Nothing Then
'A policy element was dropped
'===================================================================================================
'CODE: Add a new component
Dim trx As DesignerTransaction = m_host.CreateTransaction()
Dim newName As String = "ctl" & elem.Key.Replace("/", "_")
Dim newObj As PolicyObjectCtrls.PolicyElementCtrl = DirectCast(m_host.CreateComponent(Type.GetType("PolicyObjectCtrls.PolicyElementCtrl"), newName), PolicyObjectCtrls.PolicyElementCtrl)
newObj.Location =
Me.PointToClient(New Point(e.X, e.Y))
newObj.Height = 20
newObj.Width = 100
newObj.Text =
"Programmatically Added Control"
newObj.Parent =
DirectCast(Me, System.Windows.Forms.Control)
'newObj.Parent = DirectCast(m_host.RootComponent, System.Windows.Forms.Control)
'Me.Parent.Controls.Add(newObj)
trx.Commit()
'TODO: Figure out if I even need to do this
'Use ComponentChangeService to announce changing of the Containers' Controls collection
'm_changeService.OnComponentChanging(m_host.RootComponent,TypeDescriptor.GetProperties(m_host.RootComponent)("Controls")
'===================================================================================================
Else
'An unknown object type was dropped so DO NOTHING
MessageBox.Show(
"Error", "Unknown Item Dropped")
End If
Catch ex As Exception
MessageBox.Show(ex.Message,
"DragDrop Exception", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If 'If Me.DesignMode Then
End Sub
Private Sub PolicyGroupCtrl_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragEnter
If Me.DesignMode Then
If e.Data.GetDataPresent("System.String") Then
lblStatus.Text =
"DragDropEffects.Copy"
e.Effect = DragDropEffects.Copy
Else
lblStatus.Text =
"DragDropEffects.None"
e.Effect = DragDropEffects.None
End If
End If
End Sub
#End
If
#If
DEBUG Then
Public Overrides Property Site() As ISite
Get
Return MyBase.Site
End Get
Set(ByVal Value As ISite)
' Clear any component change event handlers.
'ClearChangeNotifications()
' Set the new Site value.
MyBase.Site = Value
If Me.DesignMode Then
' Requests an IComponentChangeService from the design time environment using Component.Site.GetService()
m_changeService =
CType(GetService(GetType(IComponentChangeService)), IComponentChangeService)
' Requests an IDesignerHost service from the design time environment using Component.Site.GetService()
m_host =
CType(GetService(GetType(IDesignerHost)), IDesignerHost)
End If
' Register event handlers for component change events.
'RegisterChangeNotifications()
End Set
End Property
#End
If
Private Sub PolicyGroupCtrl_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
#If
DEBUG Then
Me.AllowDrop = Me.DesignMode
Me.lblStatus.Visible = Me.DesignMode
Me.BorderStyle = Windows.Forms.BorderStyle.FixedSingle
#Else
Me.BorderStyle = Windows.Forms.BorderStyle.None
#End
If
End Sub
End
Class