all groups > dotnet windows forms designtime > january 2005 >
You're in the

dotnet windows forms designtime

group:

detecting position of control added to CustomControl


detecting position of control added to CustomControl Nadav
1/13/2005 10:55:02 PM
dotnet windows forms designtime: 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
RE: detecting position of control added to CustomControl Nadav
1/14/2005 1:41:03 AM
Thanks for replying so fast!

[quoted text, click to view]
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
RE: detecting position of control added to CustomControl v-jetan NO[at]SPAM online.microsoft.com (
1/14/2005 8:45:04 AM
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
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
Re: detecting position of control added to CustomControl jer_m
1/14/2005 9:59:44 AM

[quoted text, click to view]

Hi Nadav,

[quoted text, click to view]

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
Re: detecting position of control added to CustomControl Nadav
1/15/2005 11:37:01 PM
Hi Jerron,
Thanks for answering.

[quoted text, click to view]

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

Re: detecting position of control added to CustomControl Nadav
1/16/2005 11:05:01 PM
Hi Jeffrey,

Thanks for your posting!

[quoted text, click to view]
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.

[quoted text, click to view]
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.

[quoted text, click to view]
I've implemented it using ISelectionService, and it works.
It's just seems strange to do it like this...

Thanks,
Re: detecting position of control added to CustomControl v-jetan NO[at]SPAM online.microsoft.com (
1/17/2005 5:59:38 AM
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
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
Re: detecting position of control added to CustomControl jer_m
1/17/2005 10:26:33 AM
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.
[quoted text, click to view]
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

[quoted text, click to view]
Re: detecting position of control added to CustomControl v-jetan NO[at]SPAM online.microsoft.com (
1/18/2005 9:21:22 AM
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
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
AddThis Social Bookmark Button