Results 1 to 13 of 13

Thread: Adding Two Picture box

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2006
    Posts
    30

    Adding Two Picture box

    The VB attachment regarding for connects two Picturebox by a line connector. In this project there is two button one for adding Picture box and another one for drawing line as connector.I am facing problem to connect the two picturebox by lineconnector button. While Picture box moving the picturebox loose its connections with previous picture box. I want to join the picturebox by the lineconnector. And the pictureboxs always in connected via the line even the picturebox move by mouse move???Anyone have an idea how to slove this problem?????
    Attached Files Attached Files

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Jan 2006
    Posts
    30

    Re: Adding Two Picture box

    Can any one help my project?????May be i didnot explain better in my post.I will better expalin if any one have specific question regarding the project..thanks in advance.

  3. #3
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: Adding Two Picture box

    most people use .zip so any chance for that? .rar i cant open and many others dont have winrar either.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jan 2006
    Posts
    30

    Re: Adding Two Picture box

    I upload the its .Zip file again in this post.Anyway thanks for ur information.I am not aware about this info in before.
    Attached Files Attached Files

  5. #5
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: Adding Two Picture box

    ill check it when i get back from work and ill see if i can see anything wrong with you code.

  6. #6
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: Adding Two Picture box

    ok, the first line you have
    VB Code:
    1. Dim i, j, K, m As Integer
    you do know that i, j, k would be variant because they are not specified as anything else right?

    VB Code:
    1. Private Sub SetLine(X As Single, Y As Single)
    2.     'Stting line Co-ordinate(Start ponit and End Point)
    3.     cx2 = X
    4.     cy2 = Y
    5.    
    6.     m1 = (cx1 + cx1) / 2
    7.     m2 = (cy1 + cy2) / 2
    8.    
    9.     With MyLine.Item(Linecount - 3)
    10.         .X1 = cx1
    11.         .Y1 = cy1
    12.         .X2 = m1
    13.         .Y2 = m2
    14.     End With
    15.    
    16.     With MyLine.Item(Linecount - 2)
    17.         .X1 = m1
    18.         .Y1 = m2
    19.         .X2 = X
    20.         .Y2 = m2
    21.     End With
    22.    
    23.     With MyLine.Item(Linecount - 1)
    24.         .X1 = X
    25.         .Y1 = m2
    26.         .X2 = X
    27.         .Y2 = Y
    28.     End With
    29. End Sub
    I am not able to make much sense of the above. youre using variables but many i cant find as having a value? for example: cx1 and cy1.

    last of all
    VB Code:
    1. Private Sub Command2_Click()
    2. 'Activating connector button
    3. blFlag = True
    4. End Sub
    youve set a boolean flag to true and youre doing nothing else. command2 is for the lineconnector commandbutton so shouldnt you call the setline sub from there?

    meaning something like:
    VB Code:
    1. Private Sub Command2_Click()
    2. 'Activating connector button
    3. blFlag = True
    4. SetLine 'could say call SetLine, but just saying SetLine does the same thing
    5. End Sub

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Jan 2006
    Posts
    30

    Re: Adding Two Picture box

    VB Code:
    1. Dim i, j, K, m As Integer
    variant i is used for creating pcturebox array or index...I meam in every click on addpicturebox creat a new picturebox
    variant j is used for moving the picturebox on form.
    VB Code:
    1. For j = i To 1 Step -1
    .
    k and m i dont use it at yet.I decleard it just if i may have use it later like to remove the line on using another command button.
    VB Code:
    1. Private Sub SetLine(X As Single, Y As Single)
    I use the setline function coz when u r going to draw the line in this project in runtime u get there is three step in each line and each of them have three individual index which i declared as linecount.the co-ordinate of this three step is codded as
    VB Code:
    1. With MyLine.Item(Linecount - 3)(First step is for drawing a verticle line)
    2.         .X1 = cx1
    3.         .Y1 = cy1
    4.         .X2 = m1
    5.         .Y2 = m2
    6.     End With
    7.    
    8.     With MyLine.Item(Linecount - 2)(2nd step drwaing a horizontal line)
    9.         .X1 = m1
    10.         .Y1 = m2
    11.         .X2 = X
    12.         .Y2 = m2
    13.     End With
    14.    
    15.     With MyLine.Item(Linecount - 1)(third step drawing another last verticle line)
    16.         .X1 = X
    17.         .Y1 = m2
    18.         .X2 = X
    19.         .Y2 = Y
    20.     End With
    The value of cx1 and cy1 getting from this line during mouse down period
    VB Code:
    1. Private Sub PicArray_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
    2. cx1 = PicArray.Item(Index).Left + PicArray.Item(Index).Width / 2
    3. cy1 = PicArray.Item(Index).Top + PicArray.Item(Index).Height
    value of m1 and m2 getting from
    VB Code:
    1. m1 = (cx1 + cx1) / 2
    2.     m2 = (cy1 + cy2) / 2
    value of cx2 and cy2 getting from
    VB Code:
    1. cx2 = PicArray.Item(Index).Left + PicArray.Item(Index).Width / 2
    2.  cy2 = PicArray.Item(Index).Top

    I set bflag coz i have two parallel works in mouse down period.
    VB Code:
    1. Private Sub PicArray_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)If blFlag = True Then
    2.     FromPicture = Index
    3.     Screen.MousePointer = vbCrosshair
    4.     Line1 = True
    5. ......................
    6. ...............'Picture box Moving by Mouse Down
    7. NewX = PicArray(Index).Left + X
    8. NewY = PicArray(Index).Top + Y
    9. Dim j As Integer
    10.     For j = i To 1 Step -1
    11.     If (PicArray(Index).Visible = True) And
    So when one works is active another should be inactive.I just use bflag true or false only active the line drawing works when linconnector button click and keep the other works like moving picturebox inactive.
    U can ask more regarding this,If this above info is not enough.

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Jan 2006
    Posts
    30

    Re: Adding Two Picture box

    i want to move the line alongwith picturebox move........but in this project i am not able to do this i.e the line is keep in its positions while moving the picturebox.Simply the line would like to use just as a connector.

  9. #9
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Re: Adding Two Picture box

    We've all been seeing the problem but not correcting it.. the basic fix is pretty easy unless I'm not understanding what the program's supposed to do.

    Change this line:
    VB Code:
    1. Dim i, j, K, m As Integer

    to this:
    VB Code:
    1. Dim i As Integer, j As Integer, K As Integer, m As Integer

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Jan 2006
    Posts
    30

    Re: Adding Two Picture box

    I update the program according to ur corrections..............In this project there is two button one for adding Picture box and another one for drawing line as connector.i just able to add picturebox and draw line on lineconnector button click. I wish the picturboxs are always in connected via the line appears on lineconnector button click.But now While Picture box moves it loose its connections with previous picture box. I want to join the picturebox by the lineconnector. And the pictureboxs always in connected via the line even the picturebox move by mouse move......................
    Attached Files Attached Files

  11. #11
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Re: Adding Two Picture box

    Recalculate the lines on the event where the picture box is moved.

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Jan 2006
    Posts
    30

    Re: Adding Two Picture box

    If this is a single line with single index then its not a very difficult task it.But the main problem I use three index for drwaing a single connections coz the connector line has three steps with three individual index.....one clue i can give you...In PicArray_Mousemove we need to ensure the line co-ordinate.......
    Line starting point (cx1,cy1) start from middle of the picturebox on upper side, end point(cx2,cy2) end at top middle portion of the picturebox on dow side.
    I edit the code like that
    VB Code:
    1. Private Sub PicArray_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
    2.     'Picture box moving by Mouse Move
    3.       If Line1 = True Then
    4.         X = PicArray.Item(Index).Left + X
    5.         Y = PicArray.Item(Index).Top + Y
    6.         SetLine X, Y
    7.        
    8.         If FromPicture <> 0 And FromPicture <> Index Then
    9.         cx2 = PicArray.Item(Index).Left + PicArray.Item(Index).Width / 2
    10.             cy2 = PicArray.Item(Index).Top
    11.             SetLine cx2, cy2
    12.             Line1 = False
    13.             FromPicture = 0
    14.             Screen.MousePointer = vbDefault
    15.         Else
    16.             If FromPicture <> 0 And FromPicture <> Index Then
    17.                 Unload MyLine.Item(Linecount - 3)
    18.                 Unload MyLine.Item(Linecount - 2)
    19.                 Unload MyLine.Item(Linecount - 1)
    20.                 Line1 = False
    21.             End If
    22.         End If
    23.     End If
    24.     NewX = PicArray(Index).Left + X
    25.     NewY = PicArray(Index).Top + Y
    26.         If DRAGGED_SHAPE <> -1 Then
    27.             PicArray(DRAGGED_SHAPE).Left = NewX - distX
    28.             PicArray(DRAGGED_SHAPE).Top = NewY - distY
    29.           If Linecount >= 3 Then
    30.            cx1 = PicArray.Item(Index).Left + PicArray.Item(Index).Width / 2
    31.            cy1 = PicArray.Item(Index).Top + PicArray.Item(Index).Height
    32.            cx2 = PicArray.Item(Index).Left + PicArray.Item(Index).Width / 2
    33.            cy2 = PicArray.Item(Index).Top
    34.             m1 = (cx1 + cx1) / 2
    35.             m2 = (cy1 + cy2) / 2
    36.            With MyLine.Item(Linecount - 3)
    37.         .X1 = cx1
    38.         .Y1 = cy1
    39.         .X2 = m1
    40.         .Y2 = m2
    41.     End With
    42.    
    43.     With MyLine.Item(Linecount - 2)
    44.         .X1 = m1
    45.         .Y1 = m2
    46.         .X2 = X
    47.         .Y2 = m2
    48.     End With
    49.    
    50.     With MyLine.Item(Linecount - 1)
    51.         .X1 = X
    52.         .Y1 = m2
    53.         .X2 = X
    54.         .Y2 = Y
    55.     End With
    56.         End If
    57.         End If
    58. End Sub
    I am facing problem now i cannot fixed the line co-ordinate during picturebox moving period with mouse event.....

  13. #13

    Thread Starter
    Junior Member
    Join Date
    Jan 2006
    Posts
    30

    Re: Adding Two Picture box

    VB Code:
    1. Private Sub PicArray_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
    2. .........
    3. .........
    4. .........
    5. [COLOR=DarkRed]cx1 = PicArray.Item(Index).Left + PicArray.Item(Index).Width / 2
    6. cy1 = PicArray.Item(Index).Top + PicArray.Item(Index).Height
    7. cx2 = PicArray.Item(Index).Left + PicArray.Item(Index).Width / 2
    8. cy2 = PicArray.Item(Index).Top[/COLOR]
    The problem I think in mouse move period the start point of the line (cx1,cy1) and the end ponit of the line (cx2,cy2) get the same pictureindex.But i coudnot fixup the problem.It will be sloved if it is possible to declare start line ponit getting the picture index from where its start and end line point getting the picture index where it would to be end.I higlighted the portion on red color.Can any one give the idea???????

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