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 / January 2005

Tip: Looking for answers? Try searching our database.

detecting position of control added to CustomControl

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nadav - 14 Jan 2005 06:55 GMT
I've created a GridLayout control that derives from Panel.
The control works perfectly.
Now I want to allow an option to set some properties of an added control
based on where in the GridLayout control it is added (when dragged from the
toolbox).
I tried testing the Location of the control in the OnControlAdded()
protected method but for some reason the Location of the controls does not
match the location where it is dropped.
I tried creating a simple Control that derives from Panel and testing the
Location of the added controls in OnControlAdded(), and in that control
Location of the controls do match the location the control is dropped.
I can't understand why with my GridLayout control I have this problem.
The GridLayout control has a CustomDesigner. Can It interfere with the
location of the controls?

Thanks
Nadav
"Jeffrey Tan[MSFT]" - 14 Jan 2005 08:45 GMT
Hi Nadav,

Thanks for your posting!

If you think the CustomDesigner may affect your Panel control, I think you
may just commented out the line of attaching CustomDesigner to your
control, then if the problem still exists.

For this issue, I suggest you paste some code snippet or a sample project
without the irrespective code to help us reproduce out your issue, then we
can help you better.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nadav - 14 Jan 2005 09:41 GMT
Thanks for replying so fast!

> If you think the CustomDesigner may affect your Panel control, I think you
> may just commented out the line of attaching CustomDesigner to your
> control, then if the problem still exists.
Tried to remove the Designer attribute, still got this problem.
I found a work around:
the GridLayout OnControlAdded() method stores a reference to the added control
and then in the designer OnDragDrop() I update the Controller using the X,Y
properties of the dragdrop event.
Now, I'm trying to support moving the controls on the GridLayout with drag
and drop
but I can't figure out how to get the control being moved from the
DragEventArgs
object.

Thanks
Nadav
jer_m - 14 Jan 2005 17:59 GMT
> Thanks for replying so fast!
>
> > If you think the CustomDesigner may affect your Panel control, I think you
> > may just commented out the line of attaching CustomDesigner to your

> > control, then if the problem still exists.
> Tried to remove the Designer attribute, still got this problem.
[quoted text clipped - 10 lines]
> Thanks
> Nadav

Hi Nadav,

> but I can't figure out how to get the control being moved from the
> DragEventArgs

I've run into this before, what I ended up doing was using the
ISelectionService to get the selected control.  I hope this helps.
Kind Regards,
Jerron
Nadav - 16 Jan 2005 07:37 GMT
Hi Jerron,
Thanks for answering.

> I've run into this before, what I ended up doing was using the
> ISelectionService to get the selected control.  I hope this helps.
> Kind Regards,
> Jerron

I've used the ISelectionService to get the selected control.
It works, but it seems like ....
Well, It just does not seem like the right way to do it...
If you use drag&drop, then you should be able to get the dragged object from
the Drag&Drop event.

Any way, thanks for your suggestions.

Nadav
"Jeffrey Tan[MSFT]" - 17 Jan 2005 05:59 GMT
Hi Nadav,

Thanks for your posting!

Does your "Drag&Drop event" refer to ControlDesigner's OnDrag*** methods?
Or you implement some way yourself?

I agree with Jerron that at design-time, the standard way of getting the
selected object is using ISelectionService.

Also, do you still have any concern on this issue? Please feel free to tell
me, thanks.
=========================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nadav - 17 Jan 2005 07:05 GMT
Hi Jeffrey,

Thanks for your posting!

> Does your "Drag&Drop event" refer to ControlDesigner's OnDrag*** methods?
> Or you implement some way yourself?
I override void OnDragDrop(DragEventArgs de) in the custom designer.
if I move a control on my GridLayout control,
Then de.Effect==DragDropEffects.Move and de.Data should (as I understand it)
contain the Control being dragged.

> I agree with Jerron that at design-time, the standard way of getting the
> selected object is using ISelectionService.
It just seems odd to me to have to go and make changes to the custom control
in order to get the selected controls from it,
instead of using the DrapEventArgs, that should have the information needed.
But I can't get the information from the de.Data.
No matter what parameter I pass to de.Data.GetData() it returns null.

> Also, do you still have any concern on this issue? Please feel free to tell
> me, thanks.
I've implemented it using ISelectionService, and it works.
It's just seems strange to do it like this...

Thanks,
Nadav
jer_m - 17 Jan 2005 18:26 GMT
Hi Nadav,

I agree, it does seem a little odd to use ISelectionService and it
would be nice to have some type of reference passed in DrapEventArgs.
>From what it looks like to me the drag and drop events are designed
more for dragging things like text into a text box rather then a
control onto another control.  That's the only reason I can figure it's
not there.  However, after using ISelectionService I found it really
accomplishes the same thing.  Further more its a better fit when you
consider what happens when you select multiple controls and drop them
all on the parent at once.

You mentioned having to make changes to the custom control to implement
this.  Are you just getting a reference to the ISelectionService in
your OnDragDrop function then calling getselectedcomponents or
primaryselection?

I'm happy you were able to get this working.

Kind Regards,
Jerron

> Hi Jeffrey,
>
[quoted text clipped - 22 lines]
> Thanks,
> Nadav
"Jeffrey Tan[MSFT]" - 18 Jan 2005 09:21 GMT
Hi Nadav,

Based on your feedback, it seems that you already got the workaround for
this issue. But do you still have concern on this issue? If you still feel
uncomfortable on this issue and need more information on it, I suggest you
provide a simple project and get rid of the un-related code to help me
reproduce out this issue. Then I can help you better.

Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


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.