Smart tags

All topics not related to another forum.

Moderators: Phil Wright, Chris Porter

Smart tags

Postby Anti » Sun Nov 11, 2007 2:53 am

Hi phil,

I have some questions regarding the 'Adding smart tags' tutorial on your blog.

First of all in your example you use the controldesigner to refer to the backcolor property of the _control. But when you use custom properties(that are browsable in the properties windows) do you need to set them in the _control class or the controldesigner class?

Secondly I was wondering how to implement smart tags that changed depending on a property:
I have a bool property UserDraw, when true the class overrides the OnPaint event and creates a gradient/alpha channel background, when false the system draws the BackColor value. I have added this bool property to the smart tags and when checked/unchecked i'm trying to change the visible smart tags.
So when UserDraw = true following smart tags are visible :
-Gradient Color 1
-Gradient Color 2
-Userdraw
-Alpha channel

when false it should show only these smart tags:
-UserDraw
-BackColor

I tried this:

Code: Select all
if (_control.userDraw == true)
            {
                actions.Add(new DesignerActionPropertyItem(....
                           
            }
            else
            {
                actions.Add(new DesignerActionPropertyItem(
                                  ...
            }
return actions;

it works, but only if the smart tags are closed and reopend by leaving the panel and selecting it and when deleting the object from the form i get some huge errors.

Any ideas?
thx, Anti
Anti
 
Posts: 20
Joined: Thu Mar 01, 2007 4:19 am
Location: Belgium

Postby Phil Wright » Sun Nov 11, 2007 2:57 pm

To have the smart tag refresh when you make a change you need to do the following in your DesignerActionList implementation. In the constructor get a reference to the 'DesignerActionUIService'

Code: Select all
DesignerActionUIService _serviceDesignerAction;
_serviceDesignerAction = (DesignerActionUIService)GetService(typeof(DesignerActionUIService));


Then when you make a change that should result in the regeneration of the smart tag you would call...

Code: Select all
_serviceDesignerAction.Refresh(component);


Where 'component' is a reference to the control you are designing.
Phil Wright
Site Admin
 
Posts: 2720
Joined: Thu Apr 13, 2006 2:55 pm
Location: Melbourne, Australia

Postby Anti » Mon Nov 12, 2007 10:27 pm

Ok that works like a charm, thanks.

I have one more problem that nees to be cleared (if you got the the time):
When I add the designer classes to my control (derived from a panel) the panels functionality drops. The panel acts like a user control and fe. it's not possible to drop other controls on the panel in design time.
Is there a difference in approach between a usercontrol and a derived windows component?

thanks for your time...
Anti
 
Posts: 20
Joined: Thu Mar 01, 2007 4:19 am
Location: Belgium

Postby Phil Wright » Tue Nov 13, 2007 8:31 am

You need to derive your designer from ParentControlDesigner which as the name suggest is a designer that is setup to act as parent of other controls.
Phil Wright
Site Admin
 
Posts: 2720
Joined: Thu Apr 13, 2006 2:55 pm
Location: Melbourne, Australia

Postby Anti » Tue Nov 13, 2007 8:35 am

Thank you so much, i have been pulling my hair out all day over this. MSDN was wrong by the way as it used the 'normal' ControlDesigner for a label derived class. I also wanted to thank you for your Excellent article on codeproject about the office 2007 style renderer. Thanks thanks thanks...

anti
Anti
 
Posts: 20
Joined: Thu Mar 01, 2007 4:19 am
Location: Belgium

Postby Phil Wright » Tue Nov 13, 2007 8:40 am

No problem.

Actually the MSDN article is correct. You need the ParentControlDesigner if you want the developer to be able to drag and drop controls from the toolbox onto your control surface. Just like a Panel control.

If your control has children which are fixed then it does not need the ParentControlDesigner because you do not want them to start adding extra controls at design time. So something like a Label does not want to have extra controls added at design time so would indeed want to use the ControlDesigner.
Phil Wright
Site Admin
 
Posts: 2720
Joined: Thu Apr 13, 2006 2:55 pm
Location: Melbourne, Australia

Postby Anti » Tue Nov 13, 2007 8:50 am

oh ok, thanks for the explanation
Anti
 
Posts: 20
Joined: Thu Mar 01, 2007 4:19 am
Location: Belgium


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 0 guests