Events using Generics Used in Custom Control prevents appearance in IDE properties window

Jan 11 2008 2:02 AM

Hi all,

In VS2005, I've created a Custom control which derives from TextBox, and it has an Event Property which extends EventArgs using Generics:

public class EventArgs<T> : EventArgs

{

private T value1;

public EventArgs(T value1)

{

this.value1 = value1;

}

public T Value1

{

get

{

return value1;

}

}

}

The custom control code is as follows:

namespace TempCustomControls

{

[ToolboxItem(true)]

public class BrowseBox : TextBox

{

public event EventHandler<EventArgs<string>> BrowseRequestEvent;

public BrowseBox()

{

KeyDown += new KeyEventHandler(ProcessKeyDownEvent);

}

private void ProcessKeyDownEvent(object o, KeyEventArgs e)

{

if(e.Alt && e.KeyCode == Keys.E)

{

if (BrowseRequestEvent != null)

{

BrowseRequestEvent(this, new EventArgs<string>("Alt-E pressed"));

}

}

}

}

}

I can get the control into the Toolbox and can therefore drag it onto a windows form, I can also attach a method to the event in code, and it works, the winform code is as follows:

namespace WindowsApplication3

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

browseBox1.BrowseRequestEvent += ProcessBrowseRequestEvent;

}

private void ProcessBrowseRequestEvent<T>(object sender, EventArgs<T> e)

{

MessageBox.Show((string)(object)e.Value1);

}

}

}

The problem is that the BrowseRequestEvent does not appear in the IDE properties window.  If I just use EventArgs instead of the 'Custom' EventArgs for the event it does appear, so it is seems clear there is some problem with the 'Custom' EventArgs.

Anybody got any bright ideas please?

Any help gratefully received

Cheers

Colin

 

 


Answers (1)