/
Form1.vb
63 lines (55 loc) · 2.78 KB
/
Form1.vb
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
Imports DevExpress.Diagram.Core
Imports DevExpress.Utils.Serializing
Imports DevExpress.XtraDiagram
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports System.Windows.Forms
Namespace XtraDiagram.CustomDraw
Partial Public Class Form1
Inherits DevExpress.XtraBars.Ribbon.RibbonForm
Public Sub New()
InitializeComponent()
RegisterShapes()
diagramControl1.CreateRibbon()
diagramControl1.CreateDocking()
End Sub
Public Sub RegisterShapes()
DiagramControl.ItemTypeRegistrator.Register(GetType(DiagramShapeEx))
Dim stencil = New DiagramStencil("customShapes", "Custom Shapes")
stencil.RegisterTool(New FactoryItemTool("activeTaskShape", Function() "Active Task", Function(diagram) New DiagramShapeEx With {.Content = "Active Task", .Status = Status.Active}, New System.Windows.Size(150, 100), False))
stencil.RegisterTool(New FactoryItemTool("inactiveTaskShape", Function() "Inactive Task", Function(diagram) New DiagramShapeEx With {.Content = "Inactive Task", .Status = Status.Inactive}, New System.Windows.Size(150, 100), False))
DiagramToolboxRegistrator.RegisterStencil(stencil)
diagramControl1.OptionsBehavior.SelectedStencils = StencilCollection.Parse("customShapes")
End Sub
Private Sub diagramControl1_CustomGetEditableItemProperties(ByVal sender As Object, ByVal e As DiagramCustomGetEditableItemPropertiesEventArgs) Handles diagramControl1.CustomGetEditableItemProperties
e.Properties.Add(TypeDescriptor.GetProperties(GetType(DiagramShapeEx))("Status"))
End Sub
Private Sub diagramControl1_CustomDrawItem(ByVal sender As Object, ByVal e As CustomDrawItemEventArgs) Handles diagramControl1.CustomDrawItem
Dim shape = TryCast(e.Item, DiagramShapeEx)
If shape Is Nothing Then
Return
End If
e.DefaultDraw()
Dim imagePath = If(shape.Status = Status.Active, "images/actions/apply_16x16.png", "images/actions/cancel_16x16.png")
Dim image = DevExpress.Images.ImageResourceCache.Default.GetImage(imagePath)
Dim margin = 3F
e.Graphics.DrawImage(image, New RectangleF(shape.Width - image.Width - margin, shape.Height - image.Height - margin, image.Width, image.Height))
e.Handled = True
End Sub
End Class
Public Class DiagramShapeEx
Inherits DiagramShape
<XtraSerializableProperty, Category("Info")> _
Public Property Status() As Status
End Class
Public Enum Status
Active
Inactive
End Enum
End Namespace