Results 1 to 25 of 25

Thread: how can i create user controls so that it work at run time also

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    167

    how can i create user controls so that it work at run time also

    Hi all!
    i am developing an application in v.b 6.0. it consists of some user controls (developed by using Activex controls...)... I am able to drag and drop the user contols on the screen and these are working also...

    Actually, my GUI consists of some images( like a generator symbols in electronics, and these are in acircuit), those are nothing but user controls. each one consists of click event and some other properties..
    Now what i have to do is.. i have to be able to drag and drop the user controls at run time also..
    for ex: take any M.s word application, eventhough we are typing some data, we will be able to drag and drop some tables, circles, rectangles, text boxes.. etc..

    Like wise, suppose if my user wants to insert a usercontrol at run time into the circuit( asume that he pressed F5, and clicked on some user contols , in the middle, he thought that if there wold be an extra usercontrol, it would be better) at this situation also .. my user should be able to drag and drop the required user control....so that it also should have all propertis and events.

    could you please say, Whether it is possible in V.b or not? if possible and you know How to do this pls provide me a sample code....

    Thanks in advance..
    regards:
    raghunadhs.

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: how can i create user controls so that it work at run time also

    The only way that I can think of to do this is to have each type of user control be already on the form with an Index value of 0 which will make them the first member of their own control arrays. They could be invisible to start with. Then you could perhaps have the user drag a picture of the particular user control to the spot where he wants it. At the end of the drag/drop you could substitute the usercontrol(0) for the picture and make it visible, or, if the usercontrol(0) was already in use Load usercontrol(1) and make it visible.

  3. #3
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: how can i create user controls so that it work at run time also

    If im not wrong you would need to achieve this using a control array.

    Basically you create your control. Then copy and paste it.. say YES to create a control array.

    Ill post the code later on when i get home to do this at runtime.
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: how can i create user controls so that it work at run time also

    Quote Originally Posted by some1uk03
    If im not wrong you would need to achieve this using a control array.

    Basically you create your control. Then copy and paste it.. say YES to create a control array.

    Ill post the code later on when i get home to do this at runtime.
    That's pretty much what I said.

  5. #5
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: how can i create user controls so that it work at run time also

    K here ya go...

    Try this on a new project.

    Add a picturebox and set its INDEX property to 0. Then create a button and add the code below.

    Code:
    Private CountArray As Integer
    
    Private Sub Command1_Click()
    CountArray = CountArray + 1
    Load Picture1(CountArray)
    Picture1(CountArray).Top = Picture1(CountArray - 1).Top + 300
    Picture1(CountArray).Visible = True
    End Sub
    Hope you'll get the idea.
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  6. #6

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    167

    Re: how can i create user controls so that it work at run time also

    Hi some1uk03!
    i have looked at your example.. its working... now i will start to use this in my real application, and i will make u know the feed back soon, if i get any problem,again i will come to u to take help...

    Thanks:
    regards:
    raghunadhs

    Quote Originally Posted by some1uk03
    K here ya go...

    Try this on a new project.

    Add a picturebox and set its INDEX property to 0. Then create a button and add the code below.

    Code:
    Private CountArray As Integer
    
    Private Sub Command1_Click()
    CountArray = CountArray + 1
    Load Picture1(CountArray)
    Picture1(CountArray).Top = Picture1(CountArray - 1).Top + 300
    Picture1(CountArray).Visible = True
    End Sub
    Hope you'll get the idea.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    167

    Re: how can i create user controls so that it work at run time also

    Hi martinliss,
    i will follow u r suggestion, and make know the feed back
    thanks:
    regards:
    raghunadhs


    Quote Originally Posted by MartinLiss
    The only way that I can think of to do this is to have each type of user control be already on the form with an Index value of 0 which will make them the first member of their own control arrays. They could be invisible to start with. Then you could perhaps have the user drag a picture of the particular user control to the spot where he wants it. At the end of the drag/drop you could substitute the usercontrol(0) for the picture and make it visible, or, if the usercontrol(0) was already in use Load usercontrol(1) and make it visible.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    167

    Re: how can i create user controls so that it work at run time also

    Hi some1uk03!
    I worked with the control array concept... if u don't mind let me explain my requirements once...

    (1): there must be a usercontrol, user should be able to drag and drop the user control at his required location ar run time( u r logic wehat u mentioned is doing some thing like this, but i am unable to drag and drop at my required location)
    (2): he should be able to resize it, and able to delete it( if he feels that it is not required).
    (3): like a M.S word application, my v.b application should have a tool kit, which consists of user contrls, so that when ever the user drag and drop a particular user control at any where on the form by selecting itself, it should work
    Actaully, i don't know whether it is possible in V.B 6.0 or not!...

    if it is possible in v.b pls tell me how to do it...
    Thanks in advance:
    regards:
    raghunadhs.


    Quote Originally Posted by some1uk03
    K here ya go...

    Try this on a new project.

    Add a picturebox and set its INDEX property to 0. Then create a button and add the code below.

    Code:
    Private CountArray As Integer
    
    Private Sub Command1_Click()
    CountArray = CountArray + 1
    Load Picture1(CountArray)
    Picture1(CountArray).Top = Picture1(CountArray - 1).Top + 300
    Picture1(CountArray).Visible = True
    End Sub
    Hope you'll get the idea.

  9. #9
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: how can i create user controls so that it work at run time also

    Ok for the drag and drop add this:

    Code:
    Private CountArray As Integer      'Count the Created Object Array
    Private AllowDrag As Boolean       'Disallow Arrayed object to create other objects
    
    
    
    Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
    If AllowDrag = False Then Exit Sub
    CountArray = CountArray + 1
    Load Picture1(CountArray)
    Picture1(CountArray).Visible = True
    Picture1(CountArray).Print CountArray
    
    Picture1(CountArray).Move (X - Source.Width / 2), (Y - Source.Height / 2)
    End Sub
    
    Private Sub Form_Load()
    Picture1(0).AutoRedraw = True
    End Sub
    
    Private Sub Picture1_DragOver(Index As Integer, Source As Control, X As Single, Y As Single, State As Integer)
    If Not Index = 0 Then
    AllowDrag = False
    Else
    AllowDrag = True
    End If
    End Sub
    As for Removing the Object use:

    Unload Picture1( the array number goes here )

    You can put this in a menu and then call it in the Picture1 Mouse Down event to Remove the Item.

    Also for resizing thats to do with your OWN ActiveX controls. You will need to add that yourself.
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  10. #10

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    167

    Re: how can i create user controls so that it work at run time also

    Hi some1uko3!
    I am seeing u r code, i will get back u with feed back soon.. thanks for u r immediate correspondence..
    regards:
    raghunadhs

    Quote Originally Posted by some1uk03
    Ok for the drag and drop add this:

    Code:
    Private CountArray As Integer      'Count the Created Object Array
    Private AllowDrag As Boolean       'Disallow Arrayed object to create other objects
    
    
    
    Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
    If AllowDrag = False Then Exit Sub
    CountArray = CountArray + 1
    Load Picture1(CountArray)
    Picture1(CountArray).Visible = True
    Picture1(CountArray).Print CountArray
    
    Picture1(CountArray).Move (X - Source.Width / 2), (Y - Source.Height / 2)
    End Sub
    
    Private Sub Form_Load()
    Picture1(0).AutoRedraw = True
    End Sub
    
    Private Sub Picture1_DragOver(Index As Integer, Source As Control, X As Single, Y As Single, State As Integer)
    If Not Index = 0 Then
    AllowDrag = False
    Else
    AllowDrag = True
    End If
    End Sub
    As for Removing the Object use:

    Unload Picture1( the array number goes here )

    You can put this in a menu and then call it in the Picture1 Mouse Down event to Remove the Item.

    Also for resizing thats to do with your OWN ActiveX controls. You will need to add that yourself.

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    167

    Re: how can i create user controls so that it work at run time also

    Hi some1uk03!

    I tried your code, working properly.., sorry for delay, i have taken this mean time for doing some other stuff to implement this..

    suppose if the user wants to delete one picture/usercontrol, he will be able to select that one and able to delete it, by pressing "delete" button.. so what i am doing is simply finding the key code of the "delete" button and if user attempts to delete the picture, i will check whether he pressed delete or not, if so according to u r suggestion, i am unloading it.

    before deleting, user has to select the deletable picture/usercontrol with mouse's left click.. but the application, what i have developed is working if user selects the picture with mouse's right click and pressing delete button ,why it is behaving like this! what is the remedy for this. pls tell me, if u know it... one thing.. in u r code, u forgot to set the picture's dragMode propery to "automatic", just i am saying this for new users who may want to practise this.. like me(till now i did not know this , i am new to v.b)
    Thanks in advance:
    regards:
    raghunadhs.

  12. #12

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    167

    Re: how can i create user controls so that it work at run time also

    Hi martinLiss!,
    now i am attaching the sub which is having problem. pls go through it and let me know u r suggestions.
    thanks in advance:
    regards:
    raghunadhs.

    Quote Originally Posted by MartinLiss
    Please show the sub that contains the delete code.

  14. #14
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: how can i create user controls so that it work at run time also

    Quote Originally Posted by raghunadhs
    Hi martinLiss!,
    now i am attaching the sub which is having problem. pls go through it and let me know u r suggestions.
    thanks in advance:
    regards:
    raghunadhs.
    I don't see any code or attachment.

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    167

    Re: how can i create user controls so that it work at run time also

    sorry for inconveniance... i forgot to attach.
    Thanks :
    regards:
    raghunadhs

    Quote Originally Posted by MartinLiss
    I don't see any code or attachment.
    Attached Files Attached Files

  16. #16
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: how can i create user controls so that it work at run time also

    The best thing to do would be to have a double-click of the picture be an indication that the user wants to delete it rather than select-with-mouse-and-press-delete-key. The problem is however that with the drag-drop code in the program, as soon as you click the picture VB thinks that you are doing drag-drop so normal left-click or double-click doesn't work and I don't know how to fix the problem.

  17. #17

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    167

    Re: how can i create user controls so that it work at run time also

    Ok! martin, i will follow u r suggestion, and let u know feed back.
    Thanks:
    regards:
    raghunadh
    Quote Originally Posted by MartinLiss
    The best thing to do would be to have a double-click of the picture be an indication that the user wants to delete it rather than select-with-mouse-and-press-delete-key. The problem is however that with the drag-drop code in the program, as soon as you click the picture VB thinks that you are doing drag-drop so normal left-click or double-click doesn't work and I don't know how to fix the problem.

  18. #18
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: how can i create user controls so that it work at run time also

    I found a solution! New code is indicated by 'new

    vb Code:
    1. Private CountArray As Integer      'Count the Created Object Array
    2. Private AllowDrag As Boolean       'Disallow Arrayed object to create other objects
    3. 'new
    4. Private bLeftMouseClick As Boolean
    5.  
    6.  
    7. Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
    8. If AllowDrag = False Then Exit Sub
    9. CountArray = CountArray + 1
    10. Load Picture1(CountArray)
    11. Picture1(CountArray).Visible = True
    12. Picture1(CountArray).Print CountArray
    13.  
    14. Picture1(CountArray).Move (X - Source.Width / 2), (Y - Source.Height / 2)
    15. End Sub
    16.  
    17. Private Sub Form_Load()
    18. Picture1(0).AutoRedraw = True
    19. End Sub
    20.  
    21. Private Sub Picture1_DragOver(Index As Integer, Source As Control, X As Single, Y As Single, State As Integer)
    22. If Not Index = 0 Then
    23. AllowDrag = False
    24. Else
    25. AllowDrag = True
    26. End If
    27. 'new
    28. bLeftMouseClick = True
    29. End Sub
    30.  
    31. Private Sub Picture1_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
    32. 'new
    33. If bLeftMouseClick Then
    34.  
    35. If KeyCode = 46 Then
    36.    MsgBox (KeyCode)
    37.    Unload Picture1(Index)
    38.  End If
    39.  
    40.  'new
    41.  End If
    42.  bLeftMouseClick = False
    43.  
    44. End Sub

  19. #19

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    167

    Re: how can i create user controls so that it work at run time also

    Hi martinLiss!,
    I am going to home.. i will look at it tomorrow.. and will feed back you. once again thanks for u r immediate reply... Have a good day.
    regards:
    raghunadhs

    [QUOTE=MartinLiss]I found a solution! New code is indicated by 'new

    [highlight='vb']Private CountArray As Integer 'Count the Created Object Array
    Private AllowDrag As Boolean 'Disallow Arrayed object to create other objects
    'new
    Private bLeftMouseClick As Boolean

  20. #20
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: how can i create user controls so that it work at run time also

    Ok heres the edited version of the project.

    Now you can right click and you'll get a popup menu. Just run the program and youll see.
    Attached Files Attached Files
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  21. #21

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    167

    Re: how can i create user controls so that it work at run time also

    Hi some1uk03!
    Its really wonderful. here i could not get one thing. how can u add these two menu items, mnuDelete,mnuRclick i tried for these alot, eventhough these are visible in properties window, i could not trace out on form. how did u achieve this?
    pls tell me....
    thanks in advance:
    regards:
    raghunadh
    Quote Originally Posted by some1uk03
    Ok heres the edited version of the project.

    Now you can right click and you'll get a popup menu. Just run the program and youll see.

  22. #22

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    167

    Re: how can i create user controls so that it work at run time also

    MarinLiss!
    Yes your code is working.now itself, i am able to delete it by selecting the picture with mouse's left clik. i will implement it in my app and will let u know any feed back.
    Thank u very much...
    refards:
    raghunadhs.

    [QUOTE=MartinLiss]I found a solution! New code is indicated by 'new

  23. #23
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: how can i create user controls so that it work at run time also

    how can u add these two menu items, mnuDelete,mnuRclick i tried for these alot, eventhough these are visible in properties window, i could not trace out on form. how did u achieve this?
    Using the MENU EDITOR. (3rd Icon from left)
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  24. #24

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    167

    Re: how can i create user controls so that it work at run time also

    Hi some1uk03!
    now i have understood u r code, and surprised. till now i don't know how to use that menu editor... thanks alot..
    regards:
    raghunadhs

    Quote Originally Posted by some1uk03
    Using the MENU EDITOR. (3rd Icon from left)

  25. #25

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    167

    Re: how can i create user controls so that it work at run time also

    Hi!
    Again i came to this thread after long gap... sorry for this gap. now as per your suggestions, i created a object which will be able to drag and drop on the screen and consists of click event..etc
    Actually my applications contains a GUI.It is working also,and this run time drag and drop objects for user purpose, that means he can be able to create his own GUI by clicking a "new" option in "file" menu( my applicaiton contains a menu bar also).then a new window should come,there user must be able to drag and drop objects....
    now my question is
    (a): when ever user clicks "new" menu option, a form should appear and it should be placed beside my user tool box(where my drag and drop objects placed), how can i achieve this?
    (b): my friend suggested me MDI forms, i don't have any idea about this. suppose if i use this MDI forms, can i put my user controls on the parent form, so that it should be inherited to child forms also..
    if the question is not clear, please let me know that...

    Thanks in advance:
    regards:
    raghuandhs



    Quote Originally Posted by some1uk03
    Using the MENU EDITOR. (3rd Icon from left)

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