Add NewFileIndex
This commit is contained in:
258
EDMI_ClientSuite/FormEntityDesigner/frmEntityDesigner.vb
Normal file
258
EDMI_ClientSuite/FormEntityDesigner/frmEntityDesigner.vb
Normal file
@@ -0,0 +1,258 @@
|
||||
Imports System.ComponentModel
|
||||
Imports DevExpress.XtraEditors.Repository
|
||||
Imports DevExpress.XtraVerticalGrid
|
||||
Imports DigitalData.GUIs.ClientSuite.ClassControlUtils
|
||||
Imports DigitalData.GUIs.ClientSuite.ControlProperties
|
||||
|
||||
Public Class frmEntityDesigner
|
||||
Private _IsMouseDown As Boolean = False
|
||||
Private _IsMouseMoving As Boolean = False
|
||||
|
||||
Private _BeginPosition As Point = Nothing
|
||||
Private _EndPosition As Point = Nothing
|
||||
Private _LastCursorPosition As Point = Nothing
|
||||
|
||||
Private _CurrentControl As Control = Nothing
|
||||
Private _ControlBuilder As ClassControlBuilder = Nothing
|
||||
|
||||
Private _DragDropButtonList As New List(Of Button)
|
||||
|
||||
Private Sub frmEntityDesigner_Load(sender As Object, e As EventArgs) Handles Me.Load
|
||||
' Assign Control Types to DragDrop Buttons
|
||||
btnLabel.Tag = ControlType.Label
|
||||
btnTextbox.Tag = ControlType.TextBox
|
||||
btnCombobox.Tag = ControlType.Combobox
|
||||
|
||||
' Add Default Editors for certain datatypes in the PropertyGrid
|
||||
Dim oColorEditor = New RepositoryItemColorEdit()
|
||||
Dim oBooleanEditor = New RepositoryItemCheckEdit()
|
||||
|
||||
PropertyGridMain.DefaultEditors.Add(GetType(Color), oColorEditor)
|
||||
PropertyGridMain.DefaultEditors.Add(GetType(Boolean), oBooleanEditor)
|
||||
|
||||
' Create the control builder
|
||||
_ControlBuilder = New ClassControlBuilder(DesignMode:=True)
|
||||
|
||||
' Create a list of all DragDrop buttons
|
||||
_DragDropButtonList.Add(btnLabel)
|
||||
_DragDropButtonList.Add(btnTextbox)
|
||||
_DragDropButtonList.Add(btnCombobox)
|
||||
|
||||
' Add EventHandlers for each button
|
||||
For Each oButton As Button In _DragDropButtonList
|
||||
AddHandler oButton.MouseDown, AddressOf DragDropButton_MouseDown
|
||||
AddHandler oButton.MouseMove, AddressOf DragDropButton_MouseMove
|
||||
Next
|
||||
End Sub
|
||||
|
||||
#Region "Control Buttons Events"
|
||||
Private Sub DragDropButton_MouseDown(sender As Object, e As MouseEventArgs)
|
||||
_IsMouseDown = True
|
||||
End Sub
|
||||
|
||||
Private Sub DragDropButton_MouseMove(sender As Button, e As MouseEventArgs)
|
||||
If _IsMouseDown Then
|
||||
Dim oButton = sender
|
||||
Dim oType As ControlType = oButton.Tag
|
||||
|
||||
oButton.DoDragDrop(oType.ToString, DragDropEffects.Copy)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub SnapPanelMain_DragEnter(sender As Object, e As DragEventArgs) Handles PanelMain.DragEnter
|
||||
If (e.Data.GetDataPresent(DataFormats.Text)) Then
|
||||
e.Effect = DragDropEffects.Copy
|
||||
Else
|
||||
e.Effect = DragDropEffects.None
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub SnapPanelMain_DragDrop(sender As Object, e As DragEventArgs) Handles PanelMain.DragDrop
|
||||
Dim data As String = e.Data.GetData(DataFormats.Text)
|
||||
Dim type = ClassUtils.ToEnum(Of ClassControlUtils.ControlType)(data)
|
||||
|
||||
HandleDragDrop(type)
|
||||
End Sub
|
||||
#End Region
|
||||
|
||||
#Region "Control Events"
|
||||
Private Sub Control_MouseDown(sender As Control, e As MouseEventArgs)
|
||||
If e.Button = MouseButtons.Left Then
|
||||
_CurrentControl = sender
|
||||
_BeginPosition = e.Location
|
||||
|
||||
' Set the mode flag to signal the MouseMove event handler that it
|
||||
' needs to now calculate new positions for our control
|
||||
_IsMouseMoving = True
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub Control_MouseMove(sender As Object, e As MouseEventArgs)
|
||||
If _CurrentControl Is Nothing Or Not _IsMouseMoving Then
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
Cursor = Cursors.Hand
|
||||
|
||||
Dim oCursorPosition As Point = PanelMain.PointToClient(Cursor.Position)
|
||||
Dim oNewPosition As New Point(oCursorPosition.X - _BeginPosition.X, oCursorPosition.Y - _BeginPosition.Y)
|
||||
|
||||
' If control will be moved out the of bounds of the panel at TOP/LEFT side, exit.
|
||||
If oNewPosition.X < 0 Or oNewPosition.Y < 0 Then
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
_CurrentControl.Location = oNewPosition
|
||||
End Sub
|
||||
|
||||
Private Sub Control_MouseUp(sender As Object, e As MouseEventArgs)
|
||||
If Not _IsMouseMoving Then
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
_IsMouseMoving = False
|
||||
_EndPosition = e.Location
|
||||
|
||||
Cursor = Cursors.Default
|
||||
End Sub
|
||||
|
||||
Private Sub Control_MouseClick(sender As Control, e As MouseEventArgs)
|
||||
TabControlMain.SelectedTabPage = TabPageProperties
|
||||
HandleLoadProperties(sender)
|
||||
End Sub
|
||||
|
||||
Private Sub Control_MouseEnter(sender As Control, e As EventArgs)
|
||||
Cursor = Cursors.Hand
|
||||
End Sub
|
||||
|
||||
Private Sub Control_MouseLeave(sender As Control, e As EventArgs)
|
||||
Cursor = Cursors.Default
|
||||
End Sub
|
||||
|
||||
Private Sub SetEventHandlers(Control As Control)
|
||||
AddHandler Control.MouseDown, AddressOf Control_MouseDown
|
||||
AddHandler Control.MouseMove, AddressOf Control_MouseMove
|
||||
AddHandler Control.MouseUp, AddressOf Control_MouseUp
|
||||
AddHandler Control.MouseClick, AddressOf Control_MouseClick
|
||||
AddHandler Control.MouseEnter, AddressOf Control_MouseEnter
|
||||
AddHandler Control.MouseLeave, AddressOf Control_MouseLeave
|
||||
End Sub
|
||||
#End Region
|
||||
|
||||
Private Sub HandleLoadProperties(Control As Control)
|
||||
Dim oMetadata As ControlMetadata = Control.Tag
|
||||
Dim oType = oMetadata.Type
|
||||
Dim oProps As ClassBaseProperties = Nothing
|
||||
|
||||
Select Case oType
|
||||
Case ControlType.Label
|
||||
oProps = New ClassLabelProperties With {
|
||||
.Id = oMetadata.Id,
|
||||
.Name = Control.Name,
|
||||
.Type = oType,
|
||||
.Location = Control.Location,
|
||||
.Size = Control.Size,
|
||||
.Font = Control.Font,
|
||||
.Color = Control.ForeColor,
|
||||
.Caption = Control.Text
|
||||
}
|
||||
Case ControlType.TextBox
|
||||
oProps = New ClassTextboxProperties With {
|
||||
.Id = oMetadata.Id,
|
||||
.Name = Control.Name,
|
||||
.Type = oType,
|
||||
.Location = Control.Location,
|
||||
.Size = Control.Size,
|
||||
.Font = Control.Font,
|
||||
.Color = ForeColor,
|
||||
.IsReadOnly = False,
|
||||
.IsRequired = False,
|
||||
.Multiline = False,
|
||||
.TabIndex = 0,
|
||||
.TabStop = 1,
|
||||
.DefaultValue = ""
|
||||
}
|
||||
Case ControlType.Combobox
|
||||
oProps = New ClassComboboxProperties() With {
|
||||
.Id = oMetadata.Id,
|
||||
.Name = Control.Name,
|
||||
.Type = oType,
|
||||
.Location = Control.Location,
|
||||
.Size = Control.Size,
|
||||
.Font = Control.Font,
|
||||
.Color = ForeColor,
|
||||
.IsReadOnly = False,
|
||||
.IsRequired = False,
|
||||
.TabIndex = 0,
|
||||
.TabStop = 1,
|
||||
.DefaultValue = "",
|
||||
.StaticList = New StaticList()
|
||||
}
|
||||
Case Else
|
||||
Exit Sub
|
||||
End Select
|
||||
|
||||
PropertyGridMain.SelectedObject = oProps
|
||||
End Sub
|
||||
|
||||
Private Sub HandleDragDrop(type As ControlType)
|
||||
Dim oCursorPosition As Point = PanelMain.PointToClient(Cursor.Position)
|
||||
Dim oControl As Control = Nothing
|
||||
|
||||
Select Case type
|
||||
Case ControlType.Label
|
||||
oControl = _ControlBuilder.CreateLabel()
|
||||
Case ControlType.TextBox
|
||||
oControl = _ControlBuilder.CreateTextbox()
|
||||
Case ControlType.Combobox
|
||||
oControl = _ControlBuilder.CreateCombobox()
|
||||
Case Else
|
||||
MsgBox($"Unknown Control Type {type.ToString}")
|
||||
Exit Sub
|
||||
End Select
|
||||
|
||||
' Set Location to current cursor position
|
||||
oControl.Location = oCursorPosition
|
||||
|
||||
' Attach Eventhandlers
|
||||
SetEventHandlers(oControl)
|
||||
|
||||
' Add the control to the panel
|
||||
PanelMain.Controls.Add(oControl)
|
||||
End Sub
|
||||
|
||||
Private Sub PropertyGridMain_RowChanged(sender As Object, e As DevExpress.XtraVerticalGrid.Events.RowChangedEventArgs) Handles PropertyGridMain.RowChanged
|
||||
If e.ChangeType <> RowChangeTypeEnum.Value Then
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
Dim oPropertyName As String = e.Properties.FieldName
|
||||
Dim oPropertyValue = e.Properties.Value
|
||||
|
||||
|
||||
Select Case oPropertyName
|
||||
Case "Name"
|
||||
_CurrentControl.Name = oPropertyValue
|
||||
Case "Location"
|
||||
_CurrentControl.Location = oPropertyValue
|
||||
Case "X"
|
||||
_CurrentControl.Location = New Point(oPropertyValue, _CurrentControl.Location.Y)
|
||||
Case "Y"
|
||||
_CurrentControl.Location = New Point(_CurrentControl.Location.X, oPropertyValue)
|
||||
Case "Size"
|
||||
_CurrentControl.Size = oPropertyValue
|
||||
Case "Width"
|
||||
_CurrentControl.Size = New Size(oPropertyValue, _CurrentControl.Height)
|
||||
Case "Height"
|
||||
_CurrentControl.Size = New Size(_CurrentControl.Width, oPropertyValue)
|
||||
Case "Font"
|
||||
_CurrentControl.Font = oPropertyValue
|
||||
Case "Color"
|
||||
_CurrentControl.ForeColor = oPropertyValue
|
||||
Case "Caption"
|
||||
If TypeOf _CurrentControl Is Label Then
|
||||
_CurrentControl.Text = oPropertyValue
|
||||
End If
|
||||
End Select
|
||||
End Sub
|
||||
End Class
|
||||
Reference in New Issue
Block a user