473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

node diagram

hi all
its been a while since i've worked on a VB program and im currently facing difficulties with the following code.I'm trying to create a diagram with nodes which you can manipulate and enter data.So far the program creates the nodes with numbered text by dragging the node and moves them by right click them.I want to be able to go back and delete any node i want plus to be able to access the nodes(enter text,extra form with info that the user will give)
If you can provide pointers or links to example code or literature, it
would be appreciated.

image control-index property 0

' [ Class1 ] ------------------------------------------------
Option Explicit

Public X As Long
Public Y As Long
Public Text As String
Public Handle As Image

Again Thanks
Public Kids As New Collection


Friend Sub RenderLines(Surface As Variant)
Dim Item As Class1
'Connect lines first, then do circles/text
For Each Item In Kids
Surface.Line (X, Y)-(Item.X, Item.Y), vbBlack
Item.RenderLines Surface
Next
End Sub

Friend Sub RenderText(Surface As Variant)
Dim Item As Class1
' draw the circles and text
Surface.Circle (X, Y), 500, vbBlack
Surface.CurrentX = X - Surface.TextWidth(Text) \ 2
Surface.CurrentY = Y - Surface.TextHeight(Text) \ 2
Surface.Print Text;

For Each Item In Kids
Item.RenderText Surface
Next
Handle.Move X - 500, Y - 500, 1000, 1000
End Sub

Public Function Locate(ByVal Index As Long) As Class1
Dim kid As Class1
Dim test As Class1
' reutrns the class whose handle has a certain Index
If Handle.Index = Index Then
Set Locate = Me
Else
For Each kid In Kids
Set test = kid.Locate(Index)
If Not test Is Nothing Then
Set Locate = test
Exit For
End If
Next
End If
End Function




' [ Form1 ] -------------------------------------------------------
Option Explicit
Private Node As Class1
Private Drawing As Boolean
Private StartX As Long, StartY As Long
Private OldX As Long, OldY As Long
Private StartNode As Class1


Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
DropIt Source, X, Y
End Sub

Private Sub Form_Load()
Me.FillStyle = vbFSSolid
Me.FillColor = vbWhite
Me.DrawWidth = 2
Set Node = NewItem(ScaleWidth \ 2, ScaleHeight \ 2, "Root", Image1(0))
End Sub

Private Sub Form_Paint()
Node.RenderLines Me
Node.RenderText Me
End Sub

Private Sub Image1_DragDrop(Index As Integer, Source As Control, X As Single, Y As Single)
Dim img As Image
Set img = Node.Locate(Index).Handle
DropIt Source, img.Left + X, img.Top + Y
End Sub

Private Sub Image1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
'Select Draw Mode
Drawing = True
DrawMode = vbInvert
DrawStyle = vbDot
'Store start values
Set StartNode = Node.Locate(Index)
StartX = StartNode.X
StartY = StartNode.Y
OldX = X + StartNode.Handle.Left
OldY = Y + StartNode.Handle.Top
Else
OldX = X
OldY = Y
Node.Locate(Index).Handle.Drag vbBeginDrag
End If
End Sub

Private Sub Image1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim XX As Long, YY As Long
If Drawing Then
' Convert Image click to Form coordinates
XX = X + StartNode.Handle.Left
YY = Y + StartNode.Handle.Top
'Erase old line
Line (StartX, StartY)-(OldX, OldY), vbBlack
'Draw new line
Line (StartX, StartY)-(XX, YY), vbBlack
OldX = XX
OldY = YY
End If
End Sub

Private Sub Image1_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
If Drawing Then
Drawing = False
DrawMode = vbCopyPen
DrawStyle = vbSolid
' Create a new Image control, make it visible
Load Image1(Image1.Count)
Image1(Image1.Count - 1).Visible = True
' Add a new item to the node
Node.Locate(Index).Kids.Add NewItem(X + StartNode.Handle.Left, _
Y + StartNode.Handle.Top, CStr(Image1.Count - 1), _
Image1(Image1.Count - 1))
Refresh
End If
End Sub

Private Function NewItem(ByVal X As Long, ByVal Y As Long, Text As String, Handle As Image) As Class1
Set NewItem = New Class1
With NewItem
.X = X
.Y = Y
.Text = Text
Set .Handle = Handle
End With
End Function

Private Sub DropIt(Source As Image, ByVal X As Long, ByVal Y As Long)
Dim This As Class1
' Drops item
Set This = Node.Locate(Source.Index)
This.X = X - (OldX - 500)
This.Y = Y - (OldY - 500)
Source.Drag vbEndDrag
Refresh
End Sub
Jun 15 '06 #1
0 1896

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Mikael P | last post by:
Hi, I am using argouml ( really neat UML modeling tool) to create a model. I export the model to xmi format ( it's xml). My UML-diagram looks like this: Brand A |
1
by: Maria | last post by:
Heya, I am doing some background reading about the database and i am a little bit confused, i would appreciated any help.... Assume been asked to draw the ER diagram for the following...
0
by: pavlaras | last post by:
hi all its been a while since i've worked on a VB program and im currently facing difficulties with the following code.I'm trying to create a diagram with nodes which you can manipulate and enter...
70
by: Anson.Stuggart | last post by:
I'm designing a debounce filter using Finite State Machine. The FSM behavior is it follows the inital input bit and thinks that's real output until it receives 3 consecutive same bits and it...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.