Hi Dave. DoDragDrop() and the GiveFeedback event apply to a particular
control, in unison. If you're calling DoDragDrop() on your Form control, the
GiveFeedback handler needs to be linked to the form (instead or as well).
You're linking the GiveFeedback handler to the each of the buttons. Since
you're not calling DoDragDrop on one of the buttons, it will not have the
opportunity to provide feedback on that drag-drop operation. i.e. since a
button hasn't performed the drag-drop it can't provide feedback.
Alternatively, in your MouseDown handler you could get the button to which
the event applies by casting the sender object to a Button object (e.g.
Button button = sender As Button) and calling DoDragDrop for the button
object (e.g. button.DoDragDrop(this, DragDropEffects.Move) or
button.DoDragDrop(sender, DragDropEffects.Move))
--
http://www.peterRitchie.com/
:
OK. Here goes. I'll try and keep it brief while hopefully including
everything important. I'm actually using drag and drop to implement a bar
control (as a UserControl) that can be picked up at either end and shortened
or lengthened. Thre is a set of bars, each bar is made up of a row of
buttons, the whole being implemnted as a 2-dim array of Button objects.
Because of the way it works the DragDrop event is not required. There are
also no DragOver or DragQueryContinue events implemented. I want to use
GiveFeedback in order to set a two-headed arrow cursor.
So:
// FormLoad event creates the buttons in ButtonArray:
ButtonArray = new Button[Rows, Columns];
for (int row = 0; row < Rows; row++)
{
for (int col = 0; col < Columns; col++)
{
ButtonArray[row, col] = new Button();
// Stuff to set up the button, size location etc. Omitted.
ButtonArray[row, col].MouseDown +=
new MouseEventHandler(Button_MouseDown);
ButtonArray[row, col].DragEnter +=
new DragEventHandler(Button_DragEnter);
ButtonArray[row, col].GiveFeedback +=
new GiveFeedbackEventHandler(Button_GiveFeedback);
ButtonArray[row, col].AllowDrop = true;
Controls.Add(ButtonArray[row, col]);
}
}
//Drag and drop starts in the MouseDown event:
private void Button_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
// Stuff to check the cursor is at the end of a row, etc. Omitted.
DoDragDrop(sender, DragDropEffects.Move);
// DragDrop effect is irrelevant for my purpose, but I have tried
various values.
// I can change which of the standard cursors is displayed, but not
get it to call
// GiveFeedback
}
}
private void Button_DragEnter(object sender, DragEventArgs e)
{
// Check that the cursor is still in the same row
if (GetRow((Button)sender) ==
GetRow((Button)e.Data.GetData(typeof(Button))))
{
// Stuff to work out which direction the cursor is moving and change
the colour
// of the buttons. Omitted.
e.Effect = e.AllowedEffect; // Allows whatever effect I set in
MouseDown
}
else
{
e.Effect = DragDropEffects.None; // Shows a No Entry cursor
}
}
private void Button_GiveFeedback(object sender, GiveFeedbackEventArgs e)
{
bool setBreakpointHere = true; // Never reached
}