Private Class MyWindow1 : Inherits Window
Private manager As AnnAutomationManager
Private viewer As BitmapSourceViewer
Public Sub New(ByVal title As String)
Me.Title = title
Me.Width = 400
Me.Height = 400
viewer = New BitmapSourceViewer()
viewer.Source = New BitmapImage(New Uri(LeadtoolsExamples.Common.ImagesPath.Path + "ScarletMacaws.jpg"))
viewer.Width = Double.NaN
viewer.Height = Double.NaN
manager = New AnnAutomationManager()
CreateMyAutomationObjects(manager)
manager.CreateToolBar()
Dim tbt As ToolBarTray = New ToolBarTray()
tbt.Orientation = Orientation.Horizontal
DockPanel.SetDock(tbt, Dock.Top)
tbt.ToolBars.Add(manager.ToolBar)
Dim dp As DockPanel = New DockPanel()
dp.Children.Add(tbt)
dp.Children.Add(viewer)
Me.Content = dp
Dim automation As AnnAutomation = New AnnAutomation(manager, viewer)
automation.Active = True
automation.UndoCapacity = 12
End Sub
Private Sub CreateMyAutomationObjects(ByVal manager As AnnAutomationManager)
Dim selObj As AnnAutomationObject = New AnnAutomationObject()
selObj.Id = AnnAutomationManager.SelectObjectId
selObj.Name = "Select"
selObj.Object = Nothing
selObj.DrawDesignerType = GetType(AnnRectangleDrawDesigner)
selObj.EditDesignerType = Nothing
selObj.RunDesignerType = Nothing
Dim dv As DrawingVisual = New DrawingVisual()
Using dc As DrawingContext = dv.RenderOpen()
dc.DrawRectangle(New SolidColorBrush(Color.FromRgb(236, 233, 216)), Nothing, New Rect(0, 0, 24, 24))
dc.DrawLine(New Pen(Brushes.Black, 2), New System.Windows.Point(4, 4), New System.Windows.Point(22, 22))
dc.DrawLine(New Pen(Brushes.Black, 2), New System.Windows.Point(4, 22), New System.Windows.Point(22, 4))
dc.Close()
Dim bmp As RenderTargetBitmap = New RenderTargetBitmap(24, 24, 96, 96, PixelFormats.Pbgra32)
bmp.Render(dv)
selObj.ToolBarButtonImage = bmp
End Using
selObj.ToolBarButtonToolTip = New ToolTip()
selObj.ToolBarButtonToolTip.Content = "Select"
selObj.DrawCursor = Cursors.Hand
selObj.ContextMenu = Nothing
Dim selectObj As AnnSelectObject = New AnnSelectObject()
selectObj.BackStroke = Brushes.Black
selectObj.StrokeDashCap = PenLineCap.Square
selectObj.StrokeEndLineCap = PenLineCap.Square
selectObj.StrokeLineJoin = PenLineJoin.Round
selectObj.StrokeMiterLimit = 10.0
selectObj.StrokeStartLineCap = PenLineCap.Square
selectObj.StrokeDashArray.Add(1.5)
selectObj.StrokeDashArray.Add(1.5)
selectObj.StrokeDashOffset = 2.0
selectObj.Stroke = Brushes.White
selectObj.StrokeThickness = 2.0
selObj.Object = selectObj
manager.Objects.Add(selObj)
Dim lineObj As AnnAutomationObject = New AnnAutomationObject()
lineObj.Id = AnnAutomationManager.LineObjectId
lineObj.Name = "Line"
Dim line As AnnLineObject = New AnnLineObject()
line.Stroke = Brushes.Red
line.StrokeThickness = 2.0
lineObj.Object = line
lineObj.DrawDesignerType = GetType(AnnLineDrawDesigner)
lineObj.EditDesignerType = GetType(AnnLineEditDesigner)
lineObj.RunDesignerType = GetType(AnnRunDesigner)
Using dc As DrawingContext = dv.RenderOpen()
dc.DrawRectangle(New SolidColorBrush(Color.FromRgb(236, 233, 216)), Nothing, New Rect(0, 0, 24, 24))
dc.DrawLine(New Pen(Brushes.Black, 2), New System.Windows.Point(4, 4), New System.Windows.Point(22, 22))
dc.Close()
Dim bmp As RenderTargetBitmap = New RenderTargetBitmap(24, 24, 96, 96, PixelFormats.Pbgra32)
bmp.Render(dv)
lineObj.ToolBarButtonImage = bmp
End Using
lineObj.ToolBarButtonToolTip = New ToolTip()
lineObj.ToolBarButtonToolTip.Content = "Draw new line object"
lineObj.DrawCursor = Cursors.Cross
lineObj.ContextMenu = AnnAutomationManager.CreateDefaultObjectContextMenu(lineObj.Id)
manager.Objects.Add(lineObj)
Dim rectObj As AnnAutomationObject = New AnnAutomationObject()
rectObj.Id = AnnAutomationManager.RectangleObjectId
rectObj.Name = "Rectangle"
Dim rect As AnnRectangleObject = New AnnRectangleObject()
rect.Stroke = Brushes.Red
rect.StrokeThickness = 2.0
rect.Fill = Brushes.White
rectObj.Object = rect
rectObj.DrawDesignerType = GetType(AnnRectangleDrawDesigner)
rectObj.EditDesignerType = GetType(AnnRectangleEditDesigner)
rectObj.RunDesignerType = GetType(AnnRunDesigner)
Using dc As DrawingContext = dv.RenderOpen()
dc.DrawRectangle(New SolidColorBrush(Color.FromRgb(236, 233, 216)), Nothing, New Rect(0, 0, 24, 24))
dc.DrawRectangle(Nothing, New Pen(Brushes.Black, 2), New Rect(2, 4, 20, 18))
dc.Close()
Dim bmp As RenderTargetBitmap = New RenderTargetBitmap(24, 24, 96, 96, PixelFormats.Pbgra32)
bmp.Render(dv)
rectObj.ToolBarButtonImage = bmp
End Using
rectObj.ToolBarButtonToolTip = New ToolTip()
rectObj.ToolBarButtonToolTip.Content = "Draw new rectangle object"
rectObj.DrawCursor = Cursors.Cross
rectObj.ContextMenu = AnnAutomationManager.CreateDefaultObjectContextMenu(rectObj.Id)
manager.Objects.Add(rectObj)
Dim groupObj As AnnAutomationObject = New AnnAutomationObject()
groupObj.Id = AnnAutomationManager.GroupObjectId
groupObj.Name = "Group"
groupObj.Object = New AnnGroupObject()
groupObj.DrawDesignerType = Nothing
groupObj.EditDesignerType = GetType(AnnGroupEditDesigner)
groupObj.RunDesignerType = GetType(AnnRunDesigner)
groupObj.ToolBarButtonImage = Nothing
groupObj.ToolBarButtonToolTip = Nothing
groupObj.DrawCursor = Nothing
groupObj.ContextMenu = AnnAutomationManager.CreateDefaultObjectContextMenu(groupObj.Id)
manager.Objects.Add(groupObj)
End Sub
End Class
Private Sub AnnAutomationManager_AnnAutomationManager(ByVal title As String)
Dim window As MyWindow1 = New MyWindow1(title)
window.ShowDialog()
End Sub |