Event Processing

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am attempting to handle an event when the Text changes in a
ToolStripComboBox. I'm just not quite there yet, and hope you can help.
Here's what I have:

namespace Flash
{
class MyComboBox : ToolStripComboBox
{
private MyComboBox()
{
// Code to initialize dropdown list
}

}

class RespondToChange
{
public void Update(object source, ToolStripItemEventArgs e)
{
// My code
}
}

private void Form1_Load(object sender, EventArgs e)
{
MyComboBox myComboBox = new MyComboBox();
RespondToChange doChange = new RespondToChange();

// Note that I am relying on members in the inherited
ToolStripComboBox to accomplish this
// I receive the following error: Cannot implicitly convert type
'System.Windows.Forms.ToolStripItemEventHandler' to 'System.EventHandler'
myComboBox.TextUpdate += new ToolStripItemEventHandler(doChange.Update);
}
}

I have read everything I can find on event handlers, but they never seem to
deal with inherited classes, so I am a bit confused.

Thanks in advance.
 
Hi,


First you dont need to create a new class derived from ToolStripComboBox ,
you just create the instance in the form.

The same apply to RespondToChange class, the Update method can be a method
of the form where the control is created

This does not apply of course if you do not post all the code and you
decided to do it that way for some other reasons you do not explain.

The error you are getting is cause TextUpdate event is of type EventHandler,
not ToolStripItemEventHandler

Check your doc or take a look in the object browser to see the declaration
of it.


cheers,
 
You are correct, I did not post all the code. I am attempting to create a
ComboBox that, once instantiated, is already filled with font names that are
available on the current system. I have this part working properly.

My goal is to retrieve the font name from the combobox as soon as the user
selects a new font. I can then change the font in a separate textbox that is
located on the main form of the application.

As for the TextUpdate event, I have not been able to find the correlating
event handler in the ToolStripComboBox. This item seems to be part of .NET
2.0 and .NET 1.1 SDK documentation is still posted on the web. I have browsed
the objects, and find that TextUpdate is indeed an element of
ToolStripComboBox, and as you say, it is of type System.EventHandler. My
question then is how do I resolve this?

Sorry for my ignorance. I am returning to programming after many years in
tech support.
 
Hi,


As for the TextUpdate event, I have not been able to find the correlating
event handler in the ToolStripComboBox. This item seems to be part of .NET
2.0 and .NET 1.1 SDK documentation is still posted on the web. I have
browsed
the objects, and find that TextUpdate is indeed an element of
ToolStripComboBox, and as you say, it is of type System.EventHandler. My
question then is how do I resolve this?


Simple, first you do not need to derive ToolStripComboBox , just create a
new instance of it, then change the Update method to have the EventHandler
signature. Then handle the SelectedIndexChanged of the combobox there you
can know the selected item and just do the appropiate to change the TextBox
with the font selected.




cheers,
 
Back
Top