Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / Design Time / March 2005

Tip: Looking for answers? Try searching our database.

Correctly detecting and handling Drag & Drop on a ParentControlDes

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Robin Sanner - 04 Mar 2005 16:47 GMT
I previously didn't submit this under the MSDN account sign-on.  Here is the
question again.

I have a UserControl that is acting as a container for other controls.  This
UserControl has a custom designer inheriting from ParentControlDesigner.
During design time I want to detect that a control has been dropped on it
and redimension the control based on the parent control size.  In the custom
designer I override the OnDragDrop method like so:

Public Class MyUserControlDesigner
   Inherits ParentControlDesigner
...
Protected Overloads Overrides Sub OnDragDrop(ByVal de as DragEventArgs)
   If de.Data.GetDataPresent(".NET Toolbox Item") then
       MyBase.OnDragDrop(de)
   End If

   Dim selectionService as ISelectionService =
Ctype(Me.GetService(GetType(ISelectionService)), ISelectionService)
   Dim selectedComponents as ICollection =
selectionService.GetSelectedComponents()
   If selectedComponents.Count = 1 Then
       Dim enumerator as IEnumerator = selectedComponents.GetEnumerator()
       If enumerator.MoveNext AndAlso TypeOf enumerator.Current is
MyUserControl Then
           Dim myControl as MyUserControl = CType(enumerator.Current,
MyUserControl)
           If myControl.Parent.Equals(Me.Control) Then
               'Do the redimensioning of myControl
           End If
       End If
   End If
End Sub
End Class

My first issue is a needed clarification.  I found that there are three
different kinds of drag/drop events that happen:
   1) Drag & Drop of a ToolBoxItem
       I found that in order for everything to work correctly, when a
ToolBoxItem is dropped that I need to call MyBase.OnDragDrop otherwise the
currently selected component from ISelectionService is actually Me.Control
NOT the control being dropped.  On the other hand I found that I absolutely
MUST NOT call MyBase.OnDragDrop if the control being dropped is NOT a
ToolBoxItem.  Why is this?  Is there a better way to handle this than what I
did?
   2) Drag & Drop of a control that is currently a child of Me.Control &
NOT a ToolBoxItem
       As long as I don't call MyBase.OnDragDrop this code works fine.  Why
does calling MyBase.OnDragDrop cause ISelectionService to return Me.Control
rather than the control being dropped?
   3) Drag & Drop of a control that is not currently a child of Me.Control
& NOT a ToolBoxItem (Both parent controls are of the same type)
       This I couldn't get to work correctly.  Notice that I specifically
don't do anything if the parent of the dropped control isn't Me.Control.
When I detected this I tried changing the parent of the control using
TypeDescriptor.SetValue to Me.Control and this actually causes the control
to move but after the control is moved it is no longer selectable until I
close and reopen the design surface.  I tried calling the
ControlDesigner.HookChildControls (even though the documentation doesn't
actually say what it does it looked promising) but that didn't help.  What
is the correct way to move a component from one parent control to another
parent control?

Signature

Robin Sanner

Roger - 09 Mar 2005 15:29 GMT
Instead of monitoring the Drag & Drop events to detect when components
have been added, subscribe to the ComponentAdded event of
IComponentChangeService.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.