![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Newbie
Join Date: Apr 2008
Posts: 19
Rep Power: 0
![]() |
Re: Dragging and Dropping
First thing you are right about this being in some new kind of thread but I wasn't sure because it was already on the subject of d&d, If you ask me start an new thread I will do so Happily!
I'm using right now visual studio 2008 and its an full version. What I'm trying to do is this: I want to create an win form that has in it lets say 12 labels and 12 text box and I want the user to d&d the right label in the right text box (I already created something like that in VB6 (but that was a bit easier because their it wasn't hard to create an array of controls) but it wasn't with the d&d option! it sounds simple enough, after all that I need to do is make sure that once the user clicks on the label (or press on it and I think that click event is the one I need to catch ) I will give the control (the label) the x&y location of the mouse and then make sure that he (the user) can drop it only on text box (he can place it in the wrong text box and then he will receive some kind of error message) It will be really helpfully if some one could find some kind of simple example that shows how to d&d a control in run time! god knows that I TRIED and failed!
__________________
NULL is all around me! |
|
|
|
|
|
#12 | ||
|
Caffeinated Neural Net
Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 864
Rep Power: 3
![]() |
Re: Dragging and Dropping
Quote:
Is this for one of those 'match items in column B with those in column A' kinds of things? Quote:
Now, you could play with mouse events and properties in conjunction with this. I've played with it for a few minutes, and it doesn't work yet, but I'm sure if I spent a while on it, I could get it working. However, it would be rather messy. If all you're trying to do is a matching game thing, then there's a much easier alternative. Have your textboxes in one column, and your labels in another. Each label recognizes the Click event, and when clicked, it will change color, and set a flag (you have a flag for each label). You also have a handler for the textbox Click events, and the handler here will simply exit if none of the flags for the labels are set. If a flag is set, it will assign that label's text to the textbox, and do whatever other checking you want. By using arrays and shared handlers, you can keep the amount of code to a minimum. By 'shared handlers', I mean all the labels will use one handler, and all the textboxes another. You can tell which label or textbox invoked a handler by checking the sender parameter that gets passed to the event-handling delegate. Here is a small example: C# Syntax (Toggle Plain Text)
You can also create the labels and textboxes dynamically through code, and initialize their properties in a loop. Assuming you want them aligned in columns or something, this is fairly straightforward; you just loop through setting their positions and sizes. If you're generating your content on the fly, or fetching it from a database, this kind of approach will probably work best.
__________________
A man's knowledge is like an expanding sphere, the surface corresponding to the boundary between the known and the unknown. As the sphere grows, so does its surface; the more a man learns, the more he realizes how much he does not know. Hence, the most ignorant man thinks he knows it all. - L. Sprague de Camp |
||
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|