IExtenderProvider and WinForms designer file

C# 3.5 Winforms...

So I’ve recently discovered the IExtenderProvider and how it can be used to extend controls with additional properties.

In a prototype project that I setup i put a break point on the ‘set’ method for my extendee property and as the form loads I could see the ‘set’ method executing for every control on the form; which is exactly what I wanted. Following the successful prototype I implemented the extender component into my main project. All the forms in my project inherit from a base form which I’ve added my extender component to. On the base form I set the modifier of the extender component to public so that its accessible by the form inheriting this base form.

Doing the same thing before i added a break point on the ‘set’ method for my extendee property but the method doesn’t execute for the controls in the form (but only for the controls in the base form). HELP!

I should probably add at this point that i’ve source controlled my forms and so most of them are checked-in (ie lock from modification). For the forms that I’ve checked out and modified the provider property; I’ve noticed in the designer file that all controls have an additional statement which calls the ‘set’ method of the provider property.

this.MyProvider1.SetMyProperty(this.txtTextBox1, false);

Am I right in thinking that for the extender component to work it has to physically modify the designer file or should it be able to cope with locked files and therefore call the set method dynamically? I guess if it does have to modify the designer file then this isn’t a problem for new forms or forms that get modified after the extender component was added to the project – but it would be problem when you have 101 forms all locked by source-safe...

I’d appreciate any thoughts...

-------------Problems Reply------------

At what point does the extender provider (IExtenderProvider) extend the 'type' (in my case a winforms control) that the extender was intended for; at design time or at run time?

The designer is responsible for showing you the properties of the extender in the property editor
Method bool CanExtend(object) from the IExtenderProvider interface

Am I right in thinking that for the extender component to work it has to physically modify the designer file or should it be able to cope with locked files and therefore call the set method dynamically?

It has to physically modify the designer file, and write the extended properties there

I guess if it does have to modify the designer file then this isn’t a problem for new forms or forms that get modified after the extender component was added to the project – but it would be problem when you have 101 forms all locked by source-safe...

This is is not a problem for new forms, and not for old forms.
If you want to set some extended properties, open the old form and set the extended properties (a check out of the file is necessary)

This really does confirm my suspicions, many thanks. But this does leave a problem in that the components are only extended if some physical change is made to the old form.

I was trying to hijack the Set property method to also add and remove an event handler to the component (if the component was a control). Image the property is a Boolean and when set to false it adds the event handle and therefore the default behaviour (setting to true doesn’t add and event handler)

To cut a long story short the controls which were part of newly added forms automatically have an event handler added even without me explicitly setting the property to false but the designer file of the old forms never modifier so the event handler wasn’t added.

As some background, I was trying to add a global event handler for all controls

The theme here is to add context help to my forms here’s example of the extender ( the event handler is added as part of the end initialiser)

public partial class HelpProvider : Component, IExtenderProvider, ISupportInitialize

... other code of the extender omitted ...

#region ISupportInitialize Members

public void BeginInit()
// do nothing

public void EndInit()
if (DesignMode)

foreach (Component item in _disableOnlineHelp)
if (item == null)

if (GetDisableOnlineHelp(item)) // developer has decide to set property to TRUE

Control control = item as Control;

if (control != null)

control.HelpRequested += new HelpEventHandler(HelpProvider_HelpRequested);
_toolTip.SetToolTip(control, GetHelpText(control));


#region DisableOnlineHelp Provider Property

public virtual bool GetDisableOnlineHelp(Component component)
object flag = _disableOnlineHelp[component];

if (flag == null)
return false;

return (bool)flag;

public virtual void SetDisableOnlineHelp(Component component, bool value)
_disableOnlineHelp[component] = value;


One issue might be the foreach loop in the EndInit method:

Control control = item as Control;

if (control != null)

If the item is, in fact, a Control, you get out of the loop before executing this code:

control.HelpRequested += new HelpEventHandle(HelpProvider_HelpRequested);
_toolTip.SetToolTip(control, GetHelpText(control));

so you never add the Event Handler or the ToolTip, to any Control. Oops :)

Thanks, John

Category:c# Views:0 Time:2009-04-24
Tags: .net c# winforms

Related post

  • Is it OK to change a winforms designer file? 2009-07-14

    I have created a class that is simply THIS Class UserControlBase Inherits UserControl End Class Then I changed the Inherits clause in each of my UserControls designer file to Inherits UserControlBase I know that generally you shouldn't manually mod t

  • Convert Visual Studio 2003 forms to Visual Studio 2005/2008 forms using partial classes and Designer files 2010-02-01

    After migrating my Visual Studio 2003 projects to VS2005 (or VS2008) my forms would still be inside a single file. New forms on VS2005 and VS2008 are created using partial classes where all code generated by the editor is kept in the Designer.cs file

  • How do I stop the winform designer putting the version of custom controls in a .resx file? 2011-05-31

    We are getting issues with both the merging of .resx files and the winform designer not being able to open form/controls due to the designer putting the version of custom controls in .resx files. I would like it to always put in Version= This

  • Are custom Winforms control auto generated designer files needed? 2009-11-18

    Visual Studio creates code similar to this: namespace MyCustomControls { partial class MyCustomControl { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null; /// <summ

  • VS 2005 winforms designer makes unrelated changes to source and resource files 2010-10-04

    The Visual Studio 2005 Forms Designer automatically reorders statements in it's generated form.cs.designer file. This makes code reviews and svn logs quite useless for UI issues as a little change is lost in the countless auto-generated ones. Same go

  • Visual Studio WinForms designer does not instantiate object 2009-02-04

    I created a class derived from System.Windows.Forms.ContextMenuStrip class, not as a user control, just a plain .cs class with a constructor and one event handler. When I drag this class from the Toolbox onto the designer, it creates a private member

  • Using C# WinForms Designer on Panel instead of Form? 2009-03-16

    Warning: I'm new to GUI building in C# (come from a long history in Java with Swing and SWT.) Using VS2008, When I create a new class, and extend System.Windows.Forms.Form, the WinForms Designer works really nicely. However; when I create a new class

  • VS2005 Winforms Designer Exception Screen and IE8 2009-04-17

    It seems since I installed Internet Explorer V8 that my Winforms Designer Exception screen (WSOD) is broken. Where before I would get red text with the error described, today I get this: Can anyone suggest to me a way to recover the text view of this

  • Visual studio winform designer shows design errors as text rather than html 2010-03-29

    Possible Duplicate: VS2005 Winforms Designer Exception Screen and IE8 All of the sudden, visual studio displays designer errors as plain html text, for example: <DIV id="div1" class="ErrorStyle" width="100%"><span style="font-weight: 600"

  • How to stop DataGridView from polluting my Designer file with column controls? 2010-04-23

    I'm sure you know the problem, as soon as a BindingSource is connected to a DataGridView the DataGridView generates columns for each Property found in the Type of the BindingSource's DataSource and adds that crap to the Form.Designer.cs file. We only

  • Event Handlers automatically created by WinForms Designer 2010-06-18

    I just moved from VB.NET to C#. In VB, to connect an Event Handler to a Sub we use the Handles clause. From what it seems, this do not exist in C#. After creating a simple application with a button I realize that Window Forms Designer automatically c

  • WinForm Design Error: Why am I seeing this page? 2011-04-12

    Object of type 'System.Collections.Generic.List`1[Jud.Itd.Cmis.BusinessObjects.AddressType]' cannot be converted to type 'System.Collections.Generic.IList`1[Jud.Itd.Cmis.BusinessObjects.AddressType]'. Closing Visual Studio and reopening and recompili

  • Automatic regenerate designer files 2011-05-31

    Recently I've been making some improvements to a lot of the controls we use, for example give properties default values and making buttons private instead of protected. By making this kind of adjustments you need to regenerate the designer files of t

  • Convert WinForms design to XML 2011-09-13

    I'm building a generic survey engine where end users can generate and design their own surveys (including UI design). I'm interested in building (or perhaps even buying) a custom WinForms designer which would be able to output design in XML format. I

  • Why does WinForm Designer display message "Value cannot be null. Parameter name: context"? 2011-11-24

    I have a c# Windows Forms application, using .NET 3.5. My machine environment is as follows: Visual Studio 2010 Premium, SP1 Windows 7 Professional, SP1 32-bit processor I have a UserControl-derived custom control that contains a few other UserContro

  • Is there an easier way to merge Windows Forms .Designer files? 2012-03-16

    We just recently switched from TFS to Mercurial for our small team. The main project that 3 people work on is a Windows Forms application in C#. Every time you use the designer, even for simple changes, it does a whole lot of rearranging and changing

  • What is the purpose of the designer files in Visual Studio 2008 Web application projects? 2008-08-26

    There is a conversion process that is needed when migrating Visual Studio 2005 web site to Visual Studio 2008 web application projects. It looks like VS2008 is creating a .designer. file for every aspx when you right click on a file or the project it

  • generation of designer file failed 2008-08-28

    Every few days VS2008 decides to get mad at me and fails to generate a designer file claiming it cannot find the file specified and that it's missing an assembly. Here's the scenario: The aspx page has a reference to a custom user control (inheriting

  • How do you force Visual Studio to regenerate the .designer files for aspx/ascx files? 2008-09-05

    Sometimes when I'm editing page or control the .designer files stop being updated with the new controls I'm putting on the page. I'm not sure what's causing this to happen, but I'm wondering if there's any way of forcing Visual Studio to regenerate t

Copyright (C), All Rights Reserved.

processed in 0.082 (s). 11 q(s)