Click here to Skip to main content
15,867,835 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all,

I have create N of button's in WinForm dynamically at runtime, but I would like to select all the controls at run time like in windows 7 OS desktop we will select all icon's by mouse.
Like that I would like to select all control's which I have created in my WinForm.

Please give me some sample code, or sample program.
I don't know how to start, your help will be useful to me.
Posted
Updated 12-Nov-11 7:24am
v2

 
Share this answer
 
Comments
sameertm 12-Nov-11 13:06pm    
dear friend.. i want to select those control's which created and move to some other location with in the form.. ?
thatraja 12-Nov-11 13:16pm    
Its not a big deal, when you move those controls(like icons in desktop) just save the top & left values of those controls & then retrieve those top & left values of those controls & position those in form based on values, that's all.
RaviRanjanKr 12-Nov-11 13:22pm    
My 5+
sameertm 12-Nov-11 13:24pm    
can u give some sample code please, it will be helpful to me
Sergey Alexandrovich Kryukov 12-Nov-11 20:20pm    
How is this relevant to the question? The real problem is the lack of correct concept. Please see my solution.
--SA
This is no easy task. You will have to capture your first mouse click, move your mouse and check the location of your mouse at the mouse release too. You can accomplish this with the MouseDown[^] and MouseUp[^] Events of your Form. Calculate the square you have drawn and give all the Controls in it some selected appearance (for example change the background color). Then comes the hard part. Moving them.
There are some pretty good articles about that, right here on CP.
Runtime Editable Control[^]
Excerpt from the book World of Movable Objects[^]
Move controls on a form at runtime[^]
 
Share this answer
 
Comments
RaviRanjanKr 12-Nov-11 13:22pm    
nice Answer, My 5+
Sander Rossel 12-Nov-11 13:24pm    
Thanks Ravi :)
thatraja 12-Nov-11 13:28pm    
5! for the 3rd link
Sander Rossel 12-Nov-11 13:30pm    
Thanks :)
Sergey Alexandrovich Kryukov 12-Nov-11 20:19pm    
No, Naerling, I disagree. The things are simpler -- such concept is not applicable. Please see my solution.
--SA
There is no such concept as selection of controls. When you show controls in Designer view, the controls behave like graphical objects and can be selected. During run-time, one and only one control can be focused, and the selection is not applicable, but it is applicable to content of some controls, such as selected grid view cell, selected combo box item, etc. For a control itself, selection is not applicable.

So, the question either does not makes sense or it should be correctly re-formulated.

—SA
 
Share this answer
 
Comments
Sander Rossel 13-Nov-11 4:57am    
I have a theory... EVERYTHING is possible. It may not be smart to do such things, or the code to do it is really messy, but it CAN be done somehow :)
Let me put it like this: you are building a WinForms application for a customer and that customer calls "we wan't to be able to select and move our controls like desktop icons. It's absolutely necessary that we can do this", what do you tell them? Yes sir, the customer is king. Or sorry, but this can't be done.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900