Many drag and drop targets, but no way to 'handle' them efficiently?
Many drag and drop targets, but no way to 'handle' them efficiently?
(OP)
New Question: The C# 2008 app I'm working on needs to be a drag and drop interface where the contents of any textbox should be able to be copied / moved to any other textbox on the form. I have the basic code to do this and it is working fine. The problem I have is that there are over 100 textboxes on the form, and writing the specific statements required to cover all of them one at a time will surely cause an out of memory error. (Kidding of course but it's a lot of repeated code and I'd like to find a way to reduce the number of lines way down.
If I were working in Visual Basic I would simply use a Handles statement to have one set of code work for all of the textboxes on the form. But this is C# and there is no Handles statement. How would I do something like this in C# without that?
If it helps I can break up the text boxes into seven different groups of like items. Might be easier for readability and seven groups may be better than one huge group, and certainly better than over 100 individual objects being handled the same way.
Thanks for any help you can offer!
Craig
If I were working in Visual Basic I would simply use a Handles statement to have one set of code work for all of the textboxes on the form. But this is C# and there is no Handles statement. How would I do something like this in C# without that?
If it helps I can break up the text boxes into seven different groups of like items. Might be easier for readability and seven groups may be better than one huge group, and certainly better than over 100 individual objects being handled the same way.
Thanks for any help you can offer!
Craig
RE: Many drag and drop targets, but no way to 'handle' them efficiently?
In lieu of the Handles clause in VB.NET, it is actually simple to create a single procedure that "Handles" the events for several like controls (like text boxes). What you do is create a generic routine almost exactly like the routine you would write for each individual control, but just once. Then you include a statement like this:
TextBox txt = (TextBox)sender;
...At the beginning of the routine. Where you would normally include the name of the individual control you simply use tst instead and use the dot operator and properties / methods as you normally would.
Then you assign events on each textbox and link them to the generic routine by clicking on each control and then opening the Events area of the Properties window. For Drag and Drop, you create the routines below and then in the DragDrop, DragEnter and MouseDown events you select the appropriate routine name to link it to. You can link as many controls to the routines as you want and because you are referencing the Sender the common routine will work for ALL the controls linked to it.
Hope this helps someone. Seems like something incredibly useful that isn't explained clearly almost anywhere. I got luck after hours of searching and found an undocumented piece of code that showed me the way.
Craig
CODE --> Sharp
RE: Many drag and drop targets, but no way to 'handle' them efficiently?
CODE
RE: Many drag and drop targets, but no way to 'handle' them efficiently?
RE: Many drag and drop targets, but no way to 'handle' them efficiently?
CODE