Can't get a simple Extender Provider to work

C

Chris Dunaway

I have created a simple Extender Provider and when I drop it onto a
form, it appears in the component tray, but none of the controls it is
supposed to provide a property for show the property in the
PropertyGrid!

Here is the class. The GlassButton is a custom button control that
derives from button and I just do some custom painting. I am sure I
have just omitted something simple, but I cannot see it.

I am using VS 2005.

//This code from BeepProvider.cs

using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing.Design;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Windows.Forms;

[ProvideProperty("BeepWhenClicked", typeof(GlassButton))]
public partial class BeepProvider : Component, IExtenderProvider
{

Dictionary<GlassButton, bool> _beeps;

public BeepProvider()
{
InitializeComponent();
_beeps = new Dictionary<GlassButton, bool>();
}

public BeepProvider(IContainer container)
: this()
{
container.Add(this);
}

bool IExtenderProvider.CanExtend(object extendee)
{
if ((extendee is GlassButton) && !(extendee is BeepProvider))
return true;
else
return false;
}

public bool GetBeepWhenClicked(GlassButton gb)
{
return _beeps[gb];
} //end method GetBeedWhenClicked

public void SetBeepWhenClicked(GlassButton gb, bool value)
{
_beeps[gb] = value;
if (value)
gb.Click += new EventHandler(OnClick);
else
gb.Click -= new EventHandler(OnClick);
}

private void OnClick(object sender, EventArgs e)
{
System.Console.Beep(1000, 50);
}
}



//This code from BeepProvider.Designer.cs

using System.ComponentModel;
using System.Windows.Forms;

[ProvideProperty("BeepProvider", typeof(GlassButton))]
partial class BeepProvider
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be
disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Component Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}

#endregion
}
 
C

Chris Dunaway

Chris said:
Here is the class. The GlassButton is a custom button control that
derives from button and I just do some custom painting. I am sure I
have just omitted something simple, but I cannot see it.

It wasn't very simple or intuitive, but here is my solution:
[ProvideProperty("BeepWhenClicked", typeof(GlassButton))]
public partial class BeepProvider : Component, IExtenderProvider

In these lines I can't use my custom control class name, it has to be
Control like this:

[ProvideProperty("BeepWhenClicked", typeof(Control))]
public partial class BeepProvider : Component, IExtenderProvider

{

Dictionary<GlassButton, bool> _beeps;

Next, I can not use a generic dictionary but I have to use a Hashtable
like this:

Hashtable _beeps;

public BeepProvider()
{
InitializeComponent();
_beeps = new Dictionary<GlassButton, bool>();

use a Hashtable here as well.

_beeps = new Hashtable();
bool IExtenderProvider.CanExtend(object extendee)
{
if ((extendee is GlassButton) && !(extendee is BeepProvider))
return true;
else
return false;
}

This part is Ok, I can use GlassButton here to restrict what controls
are extended
public bool GetBeepWhenClicked(GlassButton gb)
public void SetBeepWhenClicked(GlassButton gb, bool value)

These two methods had to be changed to Control rather than GlassButton


What I don't understand is why. Does anyone have any insight?

Thanks,

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top