I have a question about a C# windows forms application.... Im aware of the mouseEnter event and the Click events, but i cant seem to combine them, maybe i could get some insight on this problem =) What i want is to be able to have a matrix of components and to click one and drag, activating them as i drag my click above them

Thanks in advance for the answer =)

When you are dragging (i.e. moving the mouse while clicked on an object) the MouseEnter event does not fire for the objects you pass over.
Instead, the object first clicked receives MouseMove events, with the appropriate x,y coordinates and mouse button status.

It might be possible to do what you want using the DragDrop features. These are started by calling DoDragDrop in the click event of the object first clicked.
This starts a series of drag and drop events, DragDrop, DragEnter, DragLeave, DragOver, GiveFeedback and QureyDar (not necessarily in that order).
These will mostly occur on the original object but might occur on the object passes over (can quite remember at the moment).

Be aware that DragDrop is a complex operation that usually involves the clipboard to pass data from one process to another (e.g. dragging text from Wordpad to a Word Doc). This might make thing more complex than you require.

It might be just as easy to implement what you want by testing for object hits in the appropriate MouseMove events.

hey nick, thanks for the response i really appreciate it =D

i have two questions:

what do you mean by complex? do you mean to implement, or complex in efficiency?
what do you mean by testing for object hits in the MouseMove events?

Drag and drop is a user interaction thing and starts of a series of events that are not normally fired during normal mouse operations, so it might have an impact to code execution; depending upon what you do during those events.

As for complex, I was referring to putting stuff on the clipboard for drag-drop to use on drop and providing appropriate user feedback and other user interaction stuff that can gets quite involved for something that looks quite simple to the end-user.

From your posts it is not clear what visual effect you are trying to achieve.

As for a hit test you could do something like

private void button2_MouseMove(object sender, MouseEventArgs e)
        {
            // test if mouse is inside button1
            if (button1.Bounds.Contains(e.Location))
            { 
                // do something
            }
        }

Not sure if the Location property alone is what you need. If the clicked object and the test object are not in the same container then you might have to adjust the mouse coordinates to suit.

maybe ill give a little background to my issue, im trying to program a neural network that recognizes letters written on a grid by a person, and for usability i want the person to be able to draw on the grid as if it was Paint...

my button matrix is 30x30, so the code snippet you gave me is a bit difficult to implement :S dunno if you have any other ideas

thanks a lot dude, youve been a lot of help =D

anyone has any ideas? =(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.