I am trying to implement drag and drop in a C# app, but for some reason I
can't get it to call the GiveFeedback event. I have done everything by the
book as far as I can tell, but a breakpoint in the GiveFeedback event is
simply never reached. I know that's not much to go on, but if anyone can
suggest what I might have missed I'd be very grateful.
--
Dave 6 11065
Dave, maybe you can show us some sample code that exemplifies the problem?
e.g. the call(s) to DoDragDrop(), definition of your event handler and how
you're adding the delegate to the event?
-- http://www.peterRitchie.com/
"Dave" wrote: I am trying to implement drag and drop in a C# app, but for some reason I can't get it to call the GiveFeedback event. I have done everything by the book as far as I can tell, but a breakpoint in the GiveFeedback event is simply never reached. I know that's not much to go on, but if anyone can suggest what I might have missed I'd be very grateful.
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 DragQueryContin ue 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 MouseEventHandl er(Button_Mouse Down);
ButtonArray[row, col].DragEnter +=
new DragEventHandle r(Button_DragEn ter);
ButtonArray[row, col].GiveFeedback +=
new GiveFeedbackEve ntHandler(Butto n_GiveFeedback) ;
ButtonArray[row, col].AllowDrop = true;
Controls.Add(Bu ttonArray[row, col]);
}
}
//Drag and drop starts in the MouseDown event:
private void Button_MouseDow n(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Le ft)
{
// Stuff to check the cursor is at the end of a row, etc. Omitted.
DoDragDrop(send er, 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_DragEnte r(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_GiveFeed back(object sender, GiveFeedbackEve ntArgs e)
{
bool setBreakpointHe re = true; // Never reached
}
Hope that helps. Thanks for taking a look.
--
Dave
"Peter Ritchie" wrote: Dave, maybe you can show us some sample code that exemplifies the problem? e.g. the call(s) to DoDragDrop(), definition of your event handler and how you're adding the delegate to the event?
-- http://www.peterRitchie.com/
"Dave" wrote:
I am trying to implement drag and drop in a C# app, but for some reason I can't get it to call the GiveFeedback event. I have done everything by the book as far as I can tell, but a breakpoint in the GiveFeedback event is simply never reached. I know that's not much to go on, but if anyone can suggest what I might have missed I'd be very grateful.
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.DoDragDr op(this, DragDropEffects .Move) or
button.DoDragDr op(sender, DragDropEffects .Move))
-- http://www.peterRitchie.com/
"Dave" wrote: 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 DragQueryContin ue 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 MouseEventHandl er(Button_Mouse Down); ButtonArray[row, col].DragEnter += new DragEventHandle r(Button_DragEn ter); ButtonArray[row, col].GiveFeedback += new GiveFeedbackEve ntHandler(Butto n_GiveFeedback) ; ButtonArray[row, col].AllowDrop = true; Controls.Add(Bu ttonArray[row, col]); } }
//Drag and drop starts in the MouseDown event: private void Button_MouseDow n(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Le ft) { // Stuff to check the cursor is at the end of a row, etc. Omitted. DoDragDrop(send er, 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_DragEnte r(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_GiveFeed back(object sender, GiveFeedbackEve ntArgs e) { bool setBreakpointHe re = true; // Never reached }
Wow. I never would have figured that out (the way the example in the help is
put together I don't think that point is really illustrated, or maybe I just
missed it.) Big thanks. I'll give it a go.
I can't see any particular reason to do it one way rather than the other
(call and event both in the control or both in the button), can you?
--
Dave
"Peter Ritchie" wrote: 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.DoDragDr op(this, DragDropEffects .Move) or button.DoDragDr op(sender, DragDropEffects .Move))
-- http://www.peterRitchie.com/
"Dave" wrote:
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 DragQueryContin ue 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 MouseEventHandl er(Button_Mouse Down); ButtonArray[row, col].DragEnter += new DragEventHandle r(Button_DragEn ter); ButtonArray[row, col].GiveFeedback += new GiveFeedbackEve ntHandler(Butto n_GiveFeedback) ; ButtonArray[row, col].AllowDrop = true; Controls.Add(Bu ttonArray[row, col]); } }
//Drag and drop starts in the MouseDown event: private void Button_MouseDow n(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Le ft) { // Stuff to check the cursor is at the end of a row, etc. Omitted. DoDragDrop(send er, 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_DragEnte r(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_GiveFeed back(object sender, GiveFeedbackEve ntArgs e) { bool setBreakpointHe re = true; // Never reached }
Hi Dave. Yes, it's not clear from the documentation; it took me more than
one try...
If I were subclassing a control, I may be inclined to have the control deal
with the drag-drop (in that case you should be dealing with overrides and not
events). Since you're not subclassing Button, I would suggest just letting
the Form-based class deal with the drag-drop. e.g continue with DoDragDrop()
from the Form's Button_MouseDow n() but link the GiveFeedback event handler to
your Form class. I'm assuming the parent of the buttons is a Form-based
class...
-- http://www.peterRitchie.com/
"Dave" wrote: Wow. I never would have figured that out (the way the example in the help is put together I don't think that point is really illustrated, or maybe I just missed it.) Big thanks. I'll give it a go. I can't see any particular reason to do it one way rather than the other (call and event both in the control or both in the button), can you? -- Dave
"Peter Ritchie" wrote:
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.DoDragDr op(this, DragDropEffects .Move) or button.DoDragDr op(sender, DragDropEffects .Move))
-- http://www.peterRitchie.com/
"Dave" wrote:
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 DragQueryContin ue 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 MouseEventHandl er(Button_Mouse Down); ButtonArray[row, col].DragEnter += new DragEventHandle r(Button_DragEn ter); ButtonArray[row, col].GiveFeedback += new GiveFeedbackEve ntHandler(Butto n_GiveFeedback) ; ButtonArray[row, col].AllowDrop = true; Controls.Add(Bu ttonArray[row, col]); } }
//Drag and drop starts in the MouseDown event: private void Button_MouseDow n(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Le ft) { // Stuff to check the cursor is at the end of a row, etc. Omitted. DoDragDrop(send er, 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_DragEnte r(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_GiveFeed back(object sender, GiveFeedbackEve ntArgs e) { bool setBreakpointHe re = true; // Never reached }
That's what I've done, and it seeme to work fine. Many thanks
--
Dave
"Peter Ritchie" wrote: Hi Dave. Yes, it's not clear from the documentation; it took me more than one try...
If I were subclassing a control, I may be inclined to have the control deal with the drag-drop (in that case you should be dealing with overrides and not events). Since you're not subclassing Button, I would suggest just letting the Form-based class deal with the drag-drop. e.g continue with DoDragDrop() from the Form's Button_MouseDow n() but link the GiveFeedback event handler to your Form class. I'm assuming the parent of the buttons is a Form-based class...
-- http://www.peterRitchie.com/
"Dave" wrote:
Wow. I never would have figured that out (the way the example in the help is put together I don't think that point is really illustrated, or maybe I just missed it.) Big thanks. I'll give it a go. I can't see any particular reason to do it one way rather than the other (call and event both in the control or both in the button), can you? -- Dave
"Peter Ritchie" wrote:
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.DoDragDr op(this, DragDropEffects .Move) or button.DoDragDr op(sender, DragDropEffects .Move))
-- http://www.peterRitchie.com/
"Dave" wrote:
> 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 DragQueryContin ue 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 MouseEventHandl er(Button_Mouse Down); > ButtonArray[row, col].DragEnter += > new DragEventHandle r(Button_DragEn ter); > ButtonArray[row, col].GiveFeedback += > new GiveFeedbackEve ntHandler(Butto n_GiveFeedback) ; > ButtonArray[row, col].AllowDrop = true; > Controls.Add(Bu ttonArray[row, col]); > } > } > > //Drag and drop starts in the MouseDown event: > private void Button_MouseDow n(object sender, MouseEventArgs e) > { > if (e.Button == MouseButtons.Le ft) > { > // Stuff to check the cursor is at the end of a row, etc. Omitted. > DoDragDrop(send er, 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_DragEnte r(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_GiveFeed back(object sender, GiveFeedbackEve ntArgs e) > { > bool setBreakpointHe re = true; // Never reached > } This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: VR |
last post by:
I am trying to use a custom cursor during drag-drop
operation between 2 ListViews. So, I have a code that at
the time GiveFeedback() is called creates a new cursor
based on the icon and text of the dragged item:
private void listView2_GiveFeedback
(
object sender,
System.Windows.Forms.GiveFeedbackEventArgs e
)
|
by: Ajay Krishnan Thampi |
last post by:
I have a slight problem implementing 'drag and drop' from a datagrid
to a tree-view. I have pasted my code below. Someone please advice me
on what to do...pretty blur right now.
==code==
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
|
by: Sam Martin |
last post by:
hi all
i have a user control which consumes the doubleclick event.
when i use this control and implement drag and drop functionality, i.e. on
mousedown check that the left button has been pressed, the DoDragDrop(...
Problem is, because DoDragDrop is always called when the left Mouse button
is pressed, the double click in the user control isn't being fired?
any ideas?
|
by: benkial |
last post by:
I am writing a small GUI tool in C#, and I want to experiment some
fancy trick as follows: when the user click on a "OK" button, the code
will initiate a "Drag and Drop" operation in the GUI itself to itself
(i.e. drag some fake object and drop to the tool itself).
I am new to .Net programming, but from my reading can I achieve this
using SendMessage() or PostMessage() to force a "Drag and Drop"
operation?
Thanks in advance,
|
by: RHSFSS |
last post by:
Hi, I have a Drag and Drop registration problem (See http://www.thescripts.com/forum/thread434707.html for similar problem post), can anyone out thereadvise on the best solution?
I have a .NET 2.0 application (actually in C#) called from a third party piece of software via VBScript. The VB script passes an object as a parameter which my application applies changes to.
My C# application dynamically creates a form, which includes controls...
| |
by: auad |
last post by:
hi, I'm writing an application like windows explorer and I want to know
how to implement that kind of "file shadow" that appears when you drag
items in a listview. I read that I have to implement the IDropTarget
and IDropSource interfaces and the GiveFeedback event of the listview
but I really don't know how to do it, can anyone help me?
Thanks,
|
by: auad |
last post by:
hi, I'm writing an application like windows explorer and I want to know
how to implement that kind of "file shadow" that appears under the
mouse cursor when you drag items in a listview. I read that I have to
implement the IDropTarget
and IDropSource interfaces and the GiveFeedback event of the listview
but I really don't know how to do it, can anyone help me?
Thanks,
|
by: empiresolutions |
last post by:
Hello Fellow Developers,
I am using the awesome drag and drop script found at http://script.aculo.us/. I have also added a modification that interacts to a db for reordering upon release of a dragable item. Within each dragable is a input checkbox. This checkbox holds a DB id value that is sent on submit. This process works fine in IE, but in FF the checkbox values dont get sent via GET, or POST. How do i get FF to react as i think it...
|
by: Romulo NF |
last post by:
Greetings,
I´m back here to show the new version of the drag & drop table columns (original script ). I´ve found some issues with the old script, specially when trying to use 2 tables with drag&drop on the same page (which was not possible). Now i´ve a new concept of the script, more object oriented.
I´ve also commented the whole code so you guys can easier understand it engine.
What exactly we need when trying to make a column drag &...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |