彩票走势图

流程图控件FlowChart.NET使用教程:撤消或重做的属性更改

原创|使用教程|编辑:郝浩|2013-05-22 09:23:39.000|阅读 499 次

概述:FlowChart.NET是一个通用的流程图控件,提供了用于创建或编辑图表的直观的用户交互模型。本文来了解一下FlowChart.NET中撤消或重做的属性更改。

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

相关链接:

    FlowChart.NET中对于撤销项目属性的更改不会自动记录,要启用撤消属性更改,您必须明确创建一个ChangeItemCmd实例,并把它添加到历史队列。

    ChangeItemCmd构造函数需要一个作为参数的项目引用,保存项目初始状态用以再通过稍后撤销恢复。在一个或多个项目的属性分配后调用Execute方法,记录项目最终的状态再通过稍后的重做恢复。这样的话,就可以用一个单一的记录来保存项目的属性更改,这个单一的记录也可以作为单一的操作被撤销或是重做。

C#

// Save item state
ChangeItemCmd propChange = new ChangeItemCmd(diagram.Nodes[0], "Change");

// Change properties
ShapeNode shape = (ShapeNode)diagram.Nodes[0];
shape.Text = "new text";
shape.Brush = new SolidBrush(Color.Blue);
shape.Shape = Shape.FromId("Ellipse");

// Add to history
propChange.Execute();

Visual Basic

' Save item state
Dim propChange = New ChangeItemCmd(Diagram.Nodes(0), "Change")

' Change properties
Dim shape As ShapeNode = Diagram.Nodes(0)
shape.Text = "new text"
shape.Brush = New SolidBrush(Color.Blue)
shape.Shape = MindFusion.Diagramming.Shape.FromId("Ellipse")

' Add to history
propChange.Execute()

    如果说想要把几个项目作为一个操作,需要创建一个CompositeCmd实例,以及通过调用AddSubCmd方法来添加ChangeItemCmd命令到这个复合操作上。

C#

if (diagram.Selection.Nodes.Count == 0)
    return;
 
// Make all changes seem like a single operation by
// putting them in composite Command
CompositeCmd composite = new CompositeCmd(
    diagram, "Change selection");
 
foreach (DiagramNode node in diagram.Selection.Nodes)
{
    ShapeNode shape = node as ShapeNode;
    if (shape == null)
        continue;

 
    // Save item state
    ChangeItemCmd propChange = new ChangeItemCmd(shape, "Change");
 
    // Change properties
    shape.Text = "new text";
    shape.Brush = new SolidBrush(Color.Blue);
 
    // Add to the composite
    composite.AddSubCmd(propChange);
}

// Store final state of all contained commands
composite.Execute();

Visual Basic

If diagram.Selection.Nodes.Count = 0 Then
    Return
End If

' Make all changes seem like a single operation by
' putting them in composite Command
Dim composite As CompositeCmd = New CompositeCmd( _
    diagram, "Change selection")

Dim node As DiagramNode
For Each node In diagram.Selection.Nodes

    Dim shape As ShapeNode = CType(node, ShapeNode)
    If Not shape Is Nothing Then

        ' Save item state
        Dim propChange As ChangeItemCmd = New ChangeItemCmd(shape, "Change")

        ' Change properties
        shape.Text = "new text"
        shape.Brush = New SolidBrush(Color.Blue)

        ' Add to the composite
        composite.AddSubCmd(propChange)

    End If

Next

' Store final state of all contained commands
composite.Execute()

标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn

文章转载自:慧都控件

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP