locked
Selecting and moving mutiple form controls at runtime RRS feed

  • Question

  • At design time in the IDE, you can ctrl-click or drag a box around multiple controls on a form and move them all at once. How do you do that at runtime. I need to be able to create image maps based on textual copies of medical claim forms that are generated from different systems and the ability to create dynamic label controls and move a single or multiple controls and resize is required. How does MS do this in the IDE???
    Wednesday, August 25, 2010 8:56 PM

Answers

All replies

  • Hi d1huss,

     

    Welcome to MSDN forums.

     

    You'll need to implement the functionality yourself. Please check the following tutorials/demo for some ideas.

     

    How to Clone & Serialize & Copy & Paste a Windows Forms Control at runtime
    http://www.codeproject.com/cs/miscctrl/ControlCloneTst.asp

     

     

    Crafting a C# Forms Editor application from scratch

    http://www.codeproject.com/csharp/SharpFormEditorDemo.asp

     

     

    By the way, the following .Net Programming FAQs may be helpful to you.

     

    Visual Basic .NET General FAQ
    http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/5f2a5f51-169b-4b56-89d6-01b1d314fdf0
    Visual Basic Express FAQ
    http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvb/thread/ab6675a0-44c2-4d92-a4f7-2b6332e4092c

     

    Visual C# General FAQ

    http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/2d666562-ed08-4461-bf92-7808913b4e96

    Visual C# Express FAQ

    http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvcs/thread/e9a8388e-a702-474d-b8c5-0942ef29fc12

     

    Windows Forms General FAQ

    http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/28f84724-af3e-4fa1-bd86-b0d1499eaefa

    http://www.syncfusion.com/FAQ/WindowsForms/Default.aspx

     

     

    Best regards,

    Guang-ming Bian

    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help
    Thursday, August 26, 2010 8:32 AM
  • In fact easier than you probably think, 

    Here in this Tip is a sample.

    http://www.vb-tips.com/MoveControl.aspx


    Success
    Cor
    Thursday, August 26, 2010 9:00 AM
  • I have already created an application that will do what the example you listed does. I can created label controls on the fly and move them without any problem. What I want to be able to do is select multiple controls on the form and move them all at once, just like you can do in the IDE of visual studio.
    Thursday, August 26, 2010 7:56 PM
  • How do you select controls?  Is it Ctrl+Click, or are you drawing rectangles around them?   Whatever method you choose, the code to move all controls is simply a repetition of the code to move one of them.  Or is the problem in determining what represents valid and invalid positions to move to, or how to handle controls that are moved off the form?   Or is the problem in working out how to select more than one conrol?

    You can't exactly replicate the IDE of visual studio, because in VS the controls are not active, but in your application, I presume, you want the controls to be active and functional.

    Or are you trying to construct a design program that generates a data file for use in your application to create custom forms on the fly?

     

    Thursday, August 26, 2010 10:29 PM
  • In addition to Acamar,

    You can probably do this, but be aware that it is not an often asked question, while you don't get the more difficult solutions not for free as those are not given by Microsoft.

    And like you told you created the moving yourself, so you see that even for moving one control there is no standard solution in Forms (or WPF or whatever UI layer).

    So you need like the guys and girls at Microsoft did create a kind of own solution for that. Be aware that the newest version of Visual Studio is for a big part done with WPF, while at Microsoft are more developers than one.

    If something is a problem they often escape to C++ or if it is really deep create something new related to the kernel. You are not able to do that, you simply cannot reach the kernel.

    However, I assume that it is possible to do what you want and guys like Acamar and John find this often a challenge. I know that making the start for this kind of programs is rather easy but to keep it working for instance without getting controls out of the screen is mostly more transpiration than inspiration.


    Success
    Cor
    Friday, August 27, 2010 8:30 AM
  • My main problem at this point is selecting multiple controls. The keydown event doesn't seem to trap the mouse click for doing a Ctrl+Click. I would like to follow the standard convention for selecting multiple controls and not use a Ctrl+another key (a,b,c etc). I know I could stack the controls into an array and then loop through the array to move each control. 

    My programming experience is in web side of VS. Windows forms are a new adventure.

    Monday, August 30, 2010 2:30 PM
  • What is the code you are using to detect the mouse clicks and key presses?  The following should distinguish between ordinary clicks and clicks with the Ctrl key pressed:

        Dim Selectedlist As List(Of Control) = New List(Of Control)

        
    Private Sub Button1_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles Button1.Click
            
    If Control.ModifierKeys = Keys.Control Then
                Selectedlist.Add(sender)
            
    End If
        End Sub

    But for some controls you may need to use the mousedown event instead of the click event.

    Tuesday, August 31, 2010 7:03 AM