Groups | Blog | Home
all groups > dotnet windows forms designtime > september 2004 >

dotnet windows forms designtime : How can I add toolbox controls to myPanel in DesignMode


Joeri
9/20/2004 6:04:44 PM
Hi,

I am trying to write a designer for control derived from
System.Windows.Forms.Panel.
I hooked up a handler for IComponentChangeService.ComponentAdded event
OnComponentAdded ( object sender, ComponentEventArgs e )
where I try to add contols (e.g., Button), dragged from toolbox onto
myControl, to Contols collection of myContol

myPanel designedControl = (myPanel) this.Control;
Control addedContol = (System.Windows.Forms.Control) e.Component;
designedControl.Controls.Add( addedContol );

And if I later check the Controls collection, newly added Button appears
there, but that does not affect button's behavior. When I drag away myPanel,
button remains where it was dropped.

(When I checked the Bounds property of the button, top left corner was at
0,0 , what I found a bit strange since the button was not at this location
on the form or myControl.)

Can someone please point out to me what I'm doing wrong (or not doing
properly).
Thanks in advance.

v-jetan NO[at]SPAM online.microsoft.com (
9/21/2004 8:07:47 AM
Hi Joeri,

Based on my understanding, you want to add child controls to the customized
Panel control.

First, does your designer mean ControlDesigner for panel? Can you show me
why you want to add child controls to the Panel in ComponentAdded event?

I think you may use usercontrol, then place the panel control to fill the
entire usercontrol. Then we may add the child controls at design-time
through IDE designer(Because usercontrol inherit from ContainerControl, it
can have designer view in IDE). This enable us get more good UI design.
Does this meet your need?

Another choice for doing this is adding the controls programmatically in
Panel's constructor.

Are these 2 options a better solution for your issue? If you have any other
concern, 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.
Joeri
9/21/2004 1:07:24 PM
Hi Jeffrey,

Thanks for your prompt response.

My first description of what I try to do was a bit simplified for the sake
of clarity. Perhapse I need to tell a more complete story. I write the
control similar to standard TabControl with the class at the top of the
hiararchy that serves as container (it has its own designer) and pages
similar to TabPages (derived from Panel). Pages have designer (derived from
ParentControlDesigner) which, I expected, would take care of adding child
controls automatically. However, when I drop child control on the page, it
is added to the form, not even to TabControl. So I tried to add it manually
in ComponentAdded with pretty much the same result. (I also tried to specify
standard PanelDesigner in DesignerAttribute for page class, but behavior was
the same.) If I drag my TabControl away, the added contol stays on the form.

I am not sure at the moment but I'll think if I could place the panel to
fill my entire TabContol. The problem is that some areas of the control are
not suppose to accept child controls, so I'll need to do some computation
anyway to decide if that particular contol can be dropped at that location.
By the way, what is a good place to do checks like these? Is it event
handlers of IComponentChangeService events?

Adding controls programmaticaly is not that attractive, since the whole
reason why I got into programming of designers is to have design-time
support for my control.

I have yet another question. If I have several pages, each "runs" an
instance of page designer. When the child control is dropped, each designer
receives event notification and handler OnComponentAdded gets called. If I
check the Location property of the added control it is 0,0 . Can you tell me
at what moment location is getting set and, perhaps, what event fires at
that.

Thanks again for all your suggestions

Joeri



v-jetan NO[at]SPAM online.microsoft.com (
9/22/2004 9:40:55 AM
Hi Joeri,

Thanks very much for your feedback.

I will spend some time on your issue, and update you sometime later, thanks
for your understanding.

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.
v-jetan NO[at]SPAM online.microsoft.com (
9/23/2004 9:32:10 AM
Hi Joeri,

Sorry for letting you wait for so long.

Based on my understanding, you want to make a TabControl, TabPage relation
like control in Winform, the customized page inherit from Panel control,
but it seems that the page can not parent any other controls.

Panel control can host other controls in its interface, so I am not sure
why your inherited page can not host other controls. Can you show me some
code snippet to help me to reproduce this issue?

Also, to control whether or not to parent or be parent by other controls,
we may use ControlDesigner.CanBeParentedTo and ControlDesigner.CanParent
property. For more information, please refer to:
http://www.syncfusion.com/FAQ/WinForms/FAQ_c80c.asp#q796q

==================================================
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.
v-jetan NO[at]SPAM online.microsoft.com (
9/27/2004 2:10:42 AM
Hi Joeri,

Have you viewed my reply? Is your problem resolved? If you still have
anything unclear, please feel free to tell me, 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.
Joeri
9/27/2004 1:38:31 PM
Hi Jeffrey,

My apologies for not answering earlier (something has come up).

Now I am back to my problem.
I am making few changes:
- use of standard PanelDesigner for TabPages instead of custom
- I'll try to rely on that designer handles serializarion, and not to do any
handling in ComponentChangeService's events.
- TabControlDesigner's base class is ParentControlDesigner

And so far it looks good. As I see it right now, my initial confusion
stemmed from what I saw when I checked DesignMode of the added TabPages (the
value was "false") and also what I read in "Knowledge Base Article - 839202
: The DesignMode property of a nested user control is always set to False in
Visual Studio .NET"
(http://support.microsoft.com/default.aspx?scid=kb;en-us;839202). (Perhaps,
constructor is not a good place to check that property in the first place.)
So my asssumption was that I need to add Pages to TabControl manually in
ComponentAdded event hanlder. Looks like it was unnecessary complicated
approach.

I am not yet through with all that and there could be some troubles down the
road, but thank you for all your suggestions.

Joeri



[quoted text, click to view]

v-jetan NO[at]SPAM online.microsoft.com (
9/28/2004 6:53:51 AM
Hi Joeri,

Thanks very much for your feedback.

Yes, in usercontrol's constructor the DesignMode property will always be
false. Anyway, I am glad you got what you want, if you still have any
concern, please feel free to tell me, I will help you. 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.
v-jetan NO[at]SPAM online.microsoft.com (
10/1/2004 2:21:40 AM
Hi Joeri,

Do you still have concern on this issue? If you still need help, please
feel free to tell me. 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