The Netron Project For vb.net

Netron是一个用于实现类似简单Visio图形化功能的C#开源项目,作者在2006年停止了2.5版的更新,随后在2007年发布了3.0版。网络上也出现了基于2.5版的轻量版,相对来说简单很多,虽然可以用来入门学习,但被阉割过的项目总显得有些无味。3.0版相对2.5版来说是质的飞跃,但的的确确确确实实实实在在太“重量”了,所以研究学习2.5版是最折中的选择。

 

我已经把原版的C#源码转换成VB.net,这样对VBFans来说也许是件令人鼓舞的事情。除了语言上的转换之外,还对项目中原有的bug和不足做了如下的小范围修改。

 

(魏滔序原创,转帖请注明出处。)

DiagramControl:删除选中的项目

添加方法:

    Public Sub RemoveSelectedItems()

            For i As Int32 = SelectedItems.Count - 1 To 0 Step -1

                Controller.Model.Remove(SelectedItems(i))

            Next

            Me.Invalidate()

        End Sub

 

Selecttion执行DiagramControl.SelectedItems.Clear时反选

        Private Shared Sub RaiseOnNewSelection()

            RemoveHandler mSelection.OnClear, AddressOf OnShowTracker

            RemoveHandler mSelection.OnItemRemoved, AddressOf OnShowTracker

            AddHandler mSelection.OnClear, AddressOf OnShowTracker

            AddHandler mSelection.OnItemRemoved, AddressOf OnShowTracker

            RaiseEvent OnNewSelection(Nothing, EventArgs.Empty)

        End Sub

 

        Private Shared Sub OnShowTracker(ByVal sender As Object, ByVal e As EventArgs)

            Controller.View.ShowTracker()

        End Sub

 

CollectionBase从索引移除项目时触发OnItemRemoved事件

        Public Sub RemoveAt(ByVal index As Integer)

            Dim Item As T = Me.innerList(index)

            Me.innerList.RemoveAt(index)

            RaiseOnItemRemoved(Item)

        End Sub

 

Connection禁止连线缩放(去除缩放点和选中矩形框)

        Public Sub New(ByVal mFrom As Point, ByVal mTo As Point, ByVal model As IModel)

            MyBase.New(model)

            MyBase.Resizable = False

            Me.From = New Connector(mFrom, model)

            Me.From.Name = "From"

            Me.From.Parent = Me

            Me.To = New Connector(mTo, model)

            Me.To.Name = "To"

            Me.To.Parent = Me

        End Sub

 

ViewResizable = False 时去除获得焦点的选中矩形框

        Public Shared Function GetTracker(ByVal rectangle As Rectangle, ByVal type As TrackerTypes, ByVal showHandles As Boolean) As ITracker

            Select Case type

                Case TrackerTypes.Default

                    If defTracker Is Nothing Then

                        defTracker = New DefaultTracker()

                    End If

                    If showHandles Then

                        defTracker.Transform(rectangle)

                    Else

                        defTracker.Transform(Nothing)

                    End If

                    defTracker.ShowHandles = showHandles

                    Return defTracker

                Case Else

                    Return Nothing

            End Select

        End Function

 

TransformTool:实现鼠标移动时自动变换指针图标

Public Sub MouseMove(ByVal e As MouseEventArgs) Implements IMouseListener.MouseMove 的过程中添加:

            If e.Button = MouseButtons.None AndAlso Enabled AndAlso (Not IsSuspended) Then

                If Selection.SelectedItems.Count > 0 Then

                    Dim gripPoint As Point = Me.Controller.View.Tracker.Hit(e.Location)

                    Dim c As Cursor = Nothing

                    Select Case gripPoint.X

                        Case -1

                            Select Case gripPoint.Y

                                Case -1

                                    c = Cursors.SizeNWSE

                                Case 0

                                    c = Cursors.SizeWE

                                Case 1

                                    c = Cursors.SizeNESW

                            End Select

                        Case 0

                            Select Case gripPoint.Y

                                Case -1

                                    c = Cursors.SizeNS

                                Case 1

                                    c = Cursors.SizeNS

                            End Select

                        Case 1

                            Select Case gripPoint.Y

                                Case -1

                                    c = Cursors.SizeNESW

                                Case 0

                                    c = Cursors.SizeWE

                                Case 1

                                    c = Cursors.SizeNWSE

                            End Select

                    End Select

                    Controller.View.CurrentCursor = c

                End If

            End If

 

TransformTool:缩放图形完成时刷新视图

        Public Sub MouseUp(ByVal e As MouseEventArgs) Implements IMouseListener.MouseUp

            If IsActive Then

                DeactivateTool()

                Dim cmd As New TransformCommand(Me.Controller, origin, scalex, scaley, transformers)

                      Me.Controller.UndoManager.AddUndoCommand(cmd)

                      Me.Controller.View.Invalidate()

            End If

        End Sub

 

ShapeBase:限制图形的最小高度和宽度为10像素

        Public Overridable Sub Transform(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer) Implements IShape.Transform

            Dim a, b As Double

            Dim p As Point

            If width <= 10 Or height <= 10 Then Exit Sub

            For Each cn As IConnector In Me.mConnectors

                a = Math.Round((CDbl(cn.Point.X) - CDbl(mRectangle.X)) / CDbl(mRectangle.Width), 1) * width + x - cn.Point.X

                b = Math.Round((CDbl(cn.Point.Y) - CDbl(mRectangle.Y)) / CDbl(mRectangle.Height), 1) * height + y - cn.Point.Y

                p = New Point(Convert.ToInt32(a), Convert.ToInt32(b))

                cn.Move(p)

            Next cn

            mRectangle = New Rectangle(x, y, width, height)

        End Sub

 

下载

其他版本请自行搜索

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
netronlight .net开源流程图类库,类似visio,这个较轻量级版本多出不少东西。支持Group,支持Undo。但有些东西实现的较为啰嗦。不过不失为一个学习和再开发的项目。 Netron Light v2.5 pre-release The final release will be v3.0 around the summer 2006. You can however rely on the current interfaces and base classes, the core is stable. Many things are still missing in this pre-release but I have also stripped many features and things like documentation, unit tests, code comments, ASP.Net features and so on. While all the code is yours you'll have to register (it'll be around $50,-) for the documentation and all the fancy stuff. I hope to complete the 'ultimate guide to diagramming in C#' by the summer which will be accessible to registered users. Support is still kinda of a problem since I have little time. I hope the Netron forum will continue to deliver support and inspire (thanks to all who keep an eye on the forum). I have considered sort of billable consultancy and delivering custom versions of the diagram control(s) but I fear I don't have enough time and quiting my job to work full-time on Netron is an unreachable dream. Thanks to all of you who have donated to Netron and support this project by Email, chat or via the forum. I hope this pre-release will make you happy in the same way I enjoyed creating it. I beleive it contains a lot of stuff to explore and it's a little pearl of design. Thanks for downloading this, Francois [Francois.Vanderseypen@netronproject.com]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值