CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Aug 2009
    Posts
    20

    [RESOLVED] How to move controls like visual studio?

    I would like to learn how to move a control like the visual studio program. In the toolbox you have a list of all your controls (button, listbox etc....). They are labels and when you double click or drag on the label the associated control shows up on the form.

    How can I do something like this in my application???

    Hope someone can reply soon.

    Thanks in advanced

    daveofgv

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: How to move controls like visual studio?

    I would think that it is all done with code in mouse events. You click on label control in toolbox then when you click on the form it goes into the mode to drag out the label move and so on.
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Aug 2009
    Posts
    20

    Re: How to move controls like visual studio?

    How would the label create another type of control and you can do it over and over and so on?

    Example:

    There is a label that says button. You click (or drag) it over to the form and a button appears that is movable. You can do as many times as you want to create many buttons.

    I see all the examples of moveable controls, however, creating unlimited controls from a single label.

    Does this make sense?

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: How to move controls like visual studio?

    I'd start with a WPF applications project. There are some WPF samples out there that show you how to move objects around the screen with the mouse.

    I searched bing with "moving objects in WPF with the mouse" and came up with a few hits.

    This sample looks pretty good (although I don't know if it's in VB or C#).

    http://www.codeproject.com/KB/WPF/WP...?display=Print

  5. #5
    Join Date
    Aug 2009
    Posts
    20

    Re: How to move controls like visual studio?

    Thanks for all you help, however, that's not what I need (maybe I haven't explained it properly).

    If you open Visual Studio - create a new project (vb.net) - when form1 shows up add a button.

    If you look - in the toolbox you will see the word "Button". If you drag it over to the form a button appears. You can add as many as you want. (Or radio button or listbox or whatever you want to add)

    That's the concept I am trying to figure out. Drag a label onto the form and that control appears.

    Hope that makes sense. If anyone knows the concept please help.

    Thanks in advanced

    daveofgv

  6. #6
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: How to move controls like visual studio?

    When you select a button object from the toolbox in the ide basically what it does is creates a new object which happens to be a button, this button will be positioned and sized based on mouse input and will have a default name such as button1 or whatever is next in sequence. Behind the scenes there is code generated that will initialize the button object at run time.

    It is not something that can be done with just a couple of lines of code to be sure.

    The question is what is the goal, buttons are useless without code behind them so what is it that you are ultimately trying to do?
    Always use [code][/code] tags when posting code.

  7. #7
    Join Date
    Aug 2009
    Posts
    20

    Re: How to move controls like visual studio?

    Thanks for your reply.

    The reason why I am asking - we are having some clients arrive at work from China.... We are going to help structure their file system and the way they have directories setup.
    We want to use our overhead projector and would like to drag and drop controls so we can show them on the screen. - instead of power point, paint etc.... This way we can add and take away with a simple task. (kinda like adding or removing a button from form1).

    I would be nice to be able to execute the way the flow chart is and automatically setup the folders.

    Example:

    Root directory
    sub folder
    sub folder etc...

    If I have a label named "Root Folder" and drag and drop there will be a box shape on the form that says "Root Folder". If I can change the default name to whatever I would like would be good.

    Then I drag a label named "sub folder" and rename it as above. I would like to connect the sub folder to the Root Folder and when execute the directories are automatically created.

    That is ideal.

  8. #8
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: How to move controls like visual studio?

    So what you are asking is really nothing at all like the ide. Sounds like you want to display an icon with a caption and create/rename a folder on the pc. You could add code to handle drag and drop but not really needed. You could just click on the tool icon or label for root folder and have it appear on the screen then when you click on sub folder tool click on the folder icon which you want it to be a sub folder of and place the icon accordingly.
    Always use [code][/code] tags when posting code.

  9. #9
    Join Date
    Aug 2009
    Posts
    20

    Re: How to move controls like visual studio?

    In a way - yes. However, I suppose, the big question is how to have the same label (tool icon) create multiple icons on the screen?

    I have seen sites with code to create movable controls on a form and even a lot of google searches for drag and drop and even create a control at runtime, however, they only show one control at a time. What if someone wanted to create multiple controls (from the same tool icon) that are movable at runtime?

  10. #10
    Join Date
    Aug 2009
    Posts
    20

    Re: How to move controls like visual studio?

    I guess I will close this thread since it appears my project will be a lot bigger then expected. The original title is easier then I thought, however, my real question will be about creating controls.

    I realized that I will have to create a couple controls that will do what is needed. I will post a new thread if I can't figure this out about creating controls.

    thanks for help above.

    daveofgv

  11. #11
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: [RESOLVED] How to move controls like visual studio?

    You always create one at a time. You can do it in a loop of course and create 100 of them with 1 click if that is what you need but they are still created one at a time. Not sure what it is now you are trying to do, in one instance you talk about creating controls and in another your are talking about creating folders with a display for the user to organize them. There is a big difference between the 2.
    Always use [code][/code] tags when posting code.

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

Featured