Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have created a customized Panel which has a selectable Frame (with different width) and a selectable Caption-Area (with different height).
I have also modified the ParentControlDesigned for my need.
Now my question :
If I move a Control over this container - how can I limit the Drag-Drop-Position ?
In the moment it is possible to put the Control (for example a Button) directly over the Caption - I don't want it ...

What I have tried:

With googeling I found something with overwriting the OnDragOver- and OnDragEnter-Methods of my customized Designer - but all tries without success.
What I need is a useable AND understandable sample to go further. Perhaps someone can point me into the right direction ...

I have a Container-Control like a Panel or a GroupBox - but it is customized. There are areas around this Control to which a dragged Control from outside should not be moved - for example the Caption-area. Actually I can place an incoming Control (like a Button) directly over the caption - but this should be a forbitten area to where an incomming Control should not be placed. To clarify it with the example of the Form itself. Normally it is impossible to move or place a Control over the caption-area. The same I want to have at my Control ...

Additional :
I tried the suggestion of Maciej but it leads to nowhere ... The point is that in DESIGNMODE my Control doesn't ask for the drag-drop. What I tried now was do enable the functions with a customized ControlDesigner - here exists the method GetHitText with which you can activate underlying parts of the Control during DesignMode (for Example open a ComboBox or Switch Tabs of a TabControl and so on - I have a lot experience with that). But that doesn't work ... :-(
So I tried do do the same inside the customized ParentControlDesigner - there are also existing methods for Drag-Drop - but without success. I think this is the right place but I don't have useable Information about that - at this point the Internet AND Microsoft is very very poor.
The only possible Solution I found until now is a combination of a control with a Panel inside. Of course ... I could do it this way and that will work ... but that seams also very poor to me ...
And CodeProject also doesn't help me to get a step foreward ... :-(
Posted
Updated 13-Feb-21 5:16am
v6
Comments
Maciej Los 11-Feb-21 12:57pm    
I'd suggest to disable drop operation by adding handler to below event:
private void control_DragEnter(object sender, DragEventArgs e){  e.Effect = DragDropEffects.None; }

BTW: Control.AllowDrop Property (System.Windows.Forms) | Microsoft Docs[^]
Ralf Meier 11-Feb-21 13:09pm    
Thanks Maciej - I will try that later ...
But in my opinion is a functionality which comes from the ControlDesigner and not from the Control itself.
I can actually drag other Controls inside my Panel - but I can't prevent that at special (or better unwanted) positions ...
Maciej Los 12-Feb-21 2:45am    
What about using MouseHover or MouseMove event(s)? If mouse is over a "Caption" or over the restricted area, reset drag-drop operation.
Maciej Los 12-Feb-21 2:55am    
Another idea is to use DragEventArgs Class (System.Windows) | Microsoft Docs[^] to get cursor coordinates. Then, using Control.PointToScreen(Point) Method (System.Windows.Forms) | Microsoft Docs[^] allow/disallow drag-drop operation.

BTW: Take a look here: Enable Your Windows Forms Applications to Drag-and-Drop Data Objects[^] - table 2, which contains an order of sub-operations to perform drag-and-drop operation.
Ralf Meier 12-Feb-21 3:58am    
That's an idea - of course. I haven't tried it that way until now.
What I don't understand is that there is no information or samples availible for this issue ... :-(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900