Results 1 to 7 of 7

Thread: Visio graphics

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2002
    Location
    USA, OH
    Posts
    2

    Question Visio graphics

    I am currently desining an application that uses graphics for mind maps, I am able to do this with Javascript, HTML and Flash, but what I am not sure is how to do this with VB.

    The type of graphic design I am trying to do is very simular to visio, you have a shape that are allows connection points. And that is what I am trying to do in VB. I just want to know a simple example or how to do it. Like two shapes connected by a line and the shapes are moveable and the line stays connected to the shapes.

    If anyone can supply any help, I would greatly appreciate it.

    Thank you

  2. #2
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    I don't know what Visio is... but connecting 2 sprites with a line isn't too hard. Open a new project in VB and add the following code, then start it:

    [see next post]
    Last edited by Fox; May 1st, 2002 at 02:34 AM.

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2002
    Location
    USA, OH
    Posts
    2
    Thank you for the code, this does just what I asked. I am now curious if there is a way to connect the sprits dynamicly. Say I want to draw a line from one sprit to another.

    To give you an idea on what visio is, one of its many features is the ability to make flow charts.

    Thank you again for your help.

    Don

  4. #4
    Hyperactive Member Ambivalentiowa's Avatar
    Join Date
    Apr 2002
    Location
    Coming soon to a store near you!
    Posts
    375
    We just got Visio on our school computers. It's very useful for data-flow-diagrams and system flow charts. Also, you can draw hilarious little maps with it.
    -Show me on the doll where the music touched you.

  5. #5
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Well.. just create lines... again, open a nre project blabla.. drag/drop using right mouse button to connect sprite:

    VB Code:
    1. 'Types
    2.     Private Type tSprite
    3.         X As Long
    4.         Y As Long
    5.        
    6.         w As Long
    7.         h As Long
    8.        
    9.         Color As Long
    10.     End Type
    11.    
    12.     Private Type tLine
    13.         Sprite1 As Long
    14.         Sprite2 As Long
    15.        
    16.         Color As Long
    17.     End Type
    18.  
    19. 'Variables
    20.     Private SpriteCount As Long
    21.     Private Sprite() As tSprite
    22.    
    23.     Private LinesCount As Long
    24.     Private Lines() As tLine
    25.    
    26.     Private X2 As Long
    27.     Private Y2 As Long
    28.     Private ActSprite As Long
    29.    
    30. Public Sub DrawSprites()
    31.     Dim A As Long
    32.    
    33.     For A = 0 To SpriteCount
    34.         With Sprite(A)
    35.             Me.Line (.X, .Y)-(.X + .w, .Y + .h), .Color, BF
    36.         End With
    37.     Next
    38. End Sub
    39.  
    40. Public Sub DrawLines()
    41.     Dim A As Long
    42.    
    43.     For A = 0 To LinesCount
    44.         With Lines(A)
    45.             Me.Line (Sprite(.Sprite1).X + (Sprite(.Sprite1).w / 2), Sprite(.Sprite1).Y + (Sprite(.Sprite1).h / 2))-(Sprite(.Sprite2).X + (Sprite(.Sprite2).w / 2), Sprite(.Sprite2).Y + (Sprite(.Sprite2).h / 2)), .Color
    46.         End With
    47.     Next
    48. End Sub
    49.  
    50. Private Function FindSprite(iX As Long, iY As Long) As Long
    51.     Dim A As Long
    52.    
    53.     'Find sprite at specified position
    54.     For A = 0 To SpriteCount
    55.         With Sprite(A)
    56.             If iX > .X And iY > .Y Then
    57.                 If iX < .X + .w And iY < .Y + .h Then
    58.                     'Sprite found
    59.                     FindSprite = A
    60.                    
    61.                     Exit Function
    62.                 End If
    63.             End If
    64.         End With
    65.     Next
    66.    
    67.     'No sprite found
    68.     FindSprite = -1
    69. End Function
    70.  
    71. Public Sub Redraw()
    72.     'Clear
    73.     Me.Cls
    74.    
    75.     'Draw scene
    76.     DrawLines
    77.     DrawSprites
    78. End Sub
    79.  
    80. Private Sub Form_Load()
    81.     'Reset variables
    82.     ActSprite = -1
    83.    
    84.     'Create 2 sample sprites
    85.     SpriteCount = 2
    86.     ReDim Sprite(SpriteCount)
    87.    
    88.     With Sprite(0)
    89.         .X = 100
    90.         .Y = 200
    91.        
    92.         .w = 50
    93.         .h = 50
    94.        
    95.         .Color = RGB(64, 64, 192)
    96.     End With
    97.    
    98.     With Sprite(1)
    99.         .X = 400
    100.         .Y = 100
    101.        
    102.         .w = 50
    103.         .h = 50
    104.        
    105.         .Color = RGB(64, 64, 192)
    106.     End With
    107.    
    108.     With Sprite(2)
    109.         .X = 100
    110.         .Y = 50
    111.        
    112.         .w = 50
    113.         .h = 50
    114.        
    115.         .Color = RGB(64, 64, 192)
    116.     End With
    117.    
    118.     'Connect sprites
    119.     LinesCount = -1
    120. '    ReDim Lines(LinesCount)
    121. '
    122. '    With Lines(0)
    123. '        .Sprite1 = 0
    124. '        .Sprite2 = 1
    125. '
    126. '        .Color = RGB(192, 64, 64)
    127. '    End With
    128. '
    129. '    With Lines(1)
    130. '        .Sprite1 = 1
    131. '        .Sprite2 = 2
    132. '
    133. '        .Color = RGB(192, 64, 64)
    134. '    End With
    135.    
    136.     'Setup window
    137.     With Me
    138.         .AutoRedraw = True
    139.         .ScaleMode = vbPixels
    140.         .Width = 8000
    141.         .Height = 6000
    142.         .Move (Screen.Width - .Width) / 2, (Screen.Height - .Height) / 2
    143.         .Caption = "Connected sprites"
    144.     End With
    145. End Sub
    146.  
    147. Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    148.     'Save mouse position
    149.     X2 = CLng(X)
    150.     Y2 = CLng(Y)
    151.    
    152.     'Find sprite at clicked position
    153.     ActSprite = FindSprite(X2, Y2)
    154.     If ActSprite > -1 Then
    155.         Sprite(ActSprite).Color = RGB(64, 64, 255)
    156.        
    157.         Redraw
    158.     End If
    159. End Sub
    160.  
    161. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    162.     If Button = 1 Then
    163.         'Left button
    164.         If ActSprite > -1 Then
    165.             'Move sprite
    166.             With Sprite(ActSprite)
    167.                 .X = .X + (X - X2)
    168.                 .Y = .Y + (Y - Y2)
    169.             End With
    170.            
    171.             Redraw
    172.         End If
    173.        
    174.         'Save mouse position
    175.         X2 = CLng(X)
    176.         Y2 = CLng(Y)
    177.     End If
    178. End Sub
    179.  
    180. Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    181.     Dim Temp As Long
    182.    
    183.     If ActSprite > -1 Then
    184.         'Save mouse position
    185.         X2 = CLng(X)
    186.         Y2 = CLng(Y)
    187.        
    188.         If Button = 2 Then
    189.             Temp = FindSprite(X2, Y2)
    190.             If Temp > -1 Then
    191.                 If Temp <> ActSprite Then
    192.                     'Allocate memory
    193.                     LinesCount = LinesCount + 1
    194.                     ReDim Preserve Lines(LinesCount)
    195.                    
    196.                     With Lines(LinesCount)
    197.                         'Connect line
    198.                         .Sprite1 = ActSprite
    199.                         .Sprite2 = Temp
    200.                        
    201.                         .Color = RGB(192, 64, 64)
    202.                     End With
    203.                 End If
    204.             End If
    205.         End If
    206.        
    207.         'Release sprite
    208.         Sprite(ActSprite).Color = RGB(64, 64, 192)
    209.         ActSprite = -1
    210.        
    211.         Redraw
    212.     End If
    213. End Sub
    214.  
    215. Private Sub Form_Paint()
    216.     Redraw
    217. End Sub
    218.  
    219. Private Sub Form_Resize()
    220.     Redraw
    221. End Sub
    222.  
    223. Private Sub Form_Unload(Cancel As Integer)
    224.     'Release memory
    225.     Erase Sprite
    226. End Sub


    Btw: I hate flowcharts and I surely won't ever make one!

  6. #6
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    Originally posted by Ambivalentiowa
    Also, you can draw hilarious little maps with it.
    Which is, of course it's main use
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  7. #7
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    Btw: I hate flowcharts and I surely won't ever make one!
    Haha I am doing this stuff in university right now and we have to do it!! So you might need that too some time... I strongly dislike it too though...
    Sanity is a full time job

    Puh das war harter Stoff!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width