在流程图和项目的外观,而且在整个的流程图中的外观和感觉也会更加的流畅,想要改变外观和主题可以通过简单的替换当前的主题。
主题编辑器
主题编辑器为主题创建和修改提供了简单易于操作的的视觉环境,通过左边的属性网格提供了示例图,里面包含了项目各种类型、可用的内置图列表、项目样式等。在网格中的对于样式的任何修改将会立即映射到图上,如果这个主题应用到图表上,这个预览将会反应改变的效果。这个主题可以在任何时间通过保存菜单进行保存。现有的主题也可以打开和更改。
下图显示了主题编辑器的操作:
自定义样式:
下面的部分描述了如何启用自定义项目类的样式属性,要使用样式,需要创建一个自定义的样式类,可以通过从最接近的现有类型派生出来。比如,对于一个自定义ShapeNode,自定义样式需要从ShapeNodeStyle继承:
C#
public class MyNodeStyle : ShapeNodeStyle
{
}
Visual Basic
Public Class MyNodeStyle
Inherits ShapeNodeStyle
End Class
对于在MyNode中的每个属性都需要定义样式,用一样的名称来定义属性,通过下面的模式键入MyNodeStyle类。比如要是MyNode包含一个输入笔刷的MyBrush属性,下面的代码定义了器相应的样式属性:
C#
public class MyNodeStyle : ShapeNodeStyle
{
public MyNodeStyle()
{
myBrushProperty = RegisterProperty("MyBrush");
}
public Brush MyBrush
{
get { return (Brush)GetValue(myBrushProperty); }
set { SetValue(myBrushProperty, value); }
}
private object myBrushProperty;
}
Visual Basic
Public Class MyNodeStyle
Inherits ShapeNodeStyle
Public Sub New()
myBrushProperty = RegisterProperty("MyBrush")
End Sub
Public Property MyBrush() As Brush
Get
Return DirectCast(GetValue(myBrushProperty), Brush)
End Get
Set
SetValue(myBrushProperty, value)
End Set
End Property
Private myBrushProperty As Object
End Class
现在,在定制MyNode类中,定义一个新属性,EffectiveMyBrush,它将返回MyBrush的实际值:
C#
public Brush EffectiveMyBrush
{
get
{
// Checking for local value
if (MyBrush != null)
return MyBrush;
// Querying the property value through the style system
return (Brush)GetValue("MyBrush");
}
}
Visual Basic
Public ReadOnly Property EffectiveMyBrush() As Brush
Get
' Checking for local value
If MyBrush IsNot Nothing Then
Return MyBrush
End If
' Querying the property value through the style system
Return DirectCast(GetValue("MyBrush"), Brush)
End Get
End Property
记得对序列化注册的样式类,以及定制节点类:
C#
Diagram.RegisterClass(typeof(MyNode), "MyNode", 1);
Diagram.RegisterClass(typeof(MyNodeStyle), "MyNodeStyle", 1);
Visual Basic
Diagram.RegisterClass(GetType(MyNode), "MyNode", 1)
Diagram.RegisterClass(GetType(MyNodeStyle), "MyNodeStyle", 1)
现在你可以风格和主题自定义节点:
C#
Theme theme = new Theme();
MyNodeStyle myNodeStyle = new MyNodeStyle();
myNodeStyle.MyBrush = new SolidBrush(Color.PaleGoldenrod);
theme.RegisterStyle(typeof(MyNode), myNodeStyle);
diagram.Theme = theme;
Visual Basic
Dim theme As New Theme()
Dim myNodeStyle As New MyNodeStyle()
myNodeStyle.MyBrush = New SolidBrush(Color.PaleGoldenrod)
theme.RegisterStyle(GetType(MyNode), myNodeStyle)
diagram.Theme = theme
标签:
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,尊重他人劳动成果
文章转载自:慧都控件
1
好文不易,鼓励一下吧!