IconNode class Imports MindFusion.Diagramming
Imports MindFusion.Drawing
Imports System.ComponentModel
Public Class IconNode
Inherits DiagramNode
Shared Sub New()
defaultIcon = New Bitmap(50, 50)
Dim graphics As Graphics = graphics.FromImage(defaultIcon)
Dim font As Font = New Font("Arial", 48, FontStyle.Bold, GraphicsUnit.Pixel)
graphics.FillRectangle(Brushes.Transparent, 0, 0, 50, 50)
graphics.DrawString("?", font, Brushes.Black, 0, 0)
font.Dispose()
graphics.Dispose()
End Sub
Public Sub New(ByVal diagram As Diagram)
MyBase.New(diagram)
imgIcon = defaultIcon
title = "Test-Titel"
format = New StringFormat
format.Alignment = StringAlignment.Center
format.LineAlignment = StringAlignment.Center
Bounds = New RectangleF(Bounds.Location, CalculateSize())
End Sub
Public Overrides Sub Draw(ByVal graphics As IGraphics, ByVal options As RenderOptions)
Dim iconSizePixels As Rectangle = New Rectangle(0, 0, imgIcon.Width, imgIcon.Height)
Dim imageSize As RectangleF = MindFusion.Utilities.DeviceToDoc(graphics, iconSizePixels)
' Draw the icon center at the top
graphics.DrawImage(imgIcon, _
Bounds.X + Bounds.Width / 2 - imageSize.Width / 2, Bounds.Y)
'Draw the label at the bottom
Dim labelBounds As RectangleF = RectangleF.FromLTRB( _
Bounds.X, Bounds.Y + imageSize.Height, Bounds.Right, Bounds.Bottom)
graphics.DrawString(title, _
Font, Brushes.Black, labelBounds, format)
End Sub
Public Overrides Sub DrawShadow(ByVal graphics As IGraphics, ByVal options As RenderOptions)
End Sub
Private Function CalculateSize() As SizeF
Dim tempImage As Bitmap = New Bitmap(1, 1)
Dim graphics As Graphics = graphics.FromImage(tempImage)
Dim measureGraphics As IGraphics = New GdiGraphics(graphics)
measureGraphics.PageUnit = Parent.MeasureUnit
Dim iconSizePixels As Rectangle = New Rectangle(0, 0, imgIcon.Width, imgIcon.Height)
Dim imageSize As RectangleF = MindFusion.Utilities.DeviceToDoc( _
measureGraphics, iconSizePixels)
measureGraphics.Dispose()
tempImage.Dispose()
Dim textSize As SizeF = Parent.MeasureString(title, Font, Integer.MaxValue, format)
Return New SizeF( _
Math.Max(imageSize.Width, textSize.Width), _
imageSize.Height + textSize.Height)
End Function
Protected Overrides Sub UpdateCreate(ByVal current As PointF)
MyBase.UpdateCreate(current)
Bounds = New RectangleF(current, CalculateSize())
End Sub
Protected Overrides Sub SaveTo(ByVal writer As System.IO.BinaryWriter, ByVal ctx As PersistContext)
MyBase.SaveTo(writer, ctx)
' Save the label using the standard .NET BinaryWriter
writer.Write(title)
'writer.Write(NodeName) macht Probleme beim laden
'writer.Write(NodeName)
' Save the image using the FlowChart.NET built-in image saving code,
' which stores the contents of shared images only once.
ctx.SaveImage(imgIcon)
End Sub
Protected Overrides Sub LoadFrom(ByVal reader As System.IO.BinaryReader, ByVal ctx As PersistContext)
MyBase.LoadFrom(reader, ctx)
title = reader.ReadString()
NodeName = reader.ReadString()
'imgIcon = ctx.LoadImage() macht Probleme beim laden
'imgIcon = ctx.LoadImage()
End Sub
Public Property Icon() As Image
Get
Return imgIcon
End Get
Set(ByVal Value As Image)
imgIcon = Value
Bounds = New RectangleF(Bounds.Location, CalculateSize())
End Set
End Property
Public Property Label() As String
Get
Return title
End Get
Set(ByVal Value As String)
title = Value
Bounds = New RectangleF(Bounds.Location, CalculateSize())
End Set
End Property
<CategoryAttribute("Application"), _
Browsable(True), _
[ReadOnly](False), _
BindableAttribute(False), _
DefaultValueAttribute(""), _
DesignOnly(False), _
DescriptionAttribute("Name eingeben")> _
Public Property Name() As String
Get
Return NodeName
End Get
Set(ByVal Value As String)
NodeName = Value
End Set
End Property
Private imgIcon As Image
Private title As String
Private NodeName As String
Private format As StringFormat
Private Shared defaultIcon As Image
End Class