Event Processing

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • wschlichtman

    #1

    Event Processing

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

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

    }

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

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

    // Note that I am relying on members in the inherited
    ToolStripComboB ox to accomplish this
    // I receive the following error: Cannot implicitly convert type
    'System.Windows .Forms.ToolStri pItemEventHandl er' to 'System.EventHa ndler'
    myComboBox.Text Update += new ToolStripItemEv entHandler(doCh ange.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.
  • Ignacio Machin \( .NET/ C# MVP \)

    #2
    Re: Event Processing

    Hi,


    First you dont need to create a new class derived from ToolStripComboB ox ,
    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 ToolStripItemEv entHandler

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


    cheers,

    --
    Ignacio Machin,
    ignacio.machin AT dot.state.fl.us
    Florida Department Of Transportation



    "wschlichtm an" <wschlichtman@d iscussions.micr osoft.com> wrote in message
    news:D1AA444D-CDF1-446B-8EE0-DC6E82791979@mi crosoft.com...[color=blue]
    >I am attempting to handle an event when the Text changes in a
    > ToolStripComboB ox. I'm just not quite there yet, and hope you can help.
    > Here's what I have:
    >
    > namespace Flash
    > {
    > class MyComboBox : ToolStripComboB ox
    > {
    > private MyComboBox()
    > {
    > // Code to initialize dropdown list
    > }
    >
    > }
    >
    > class RespondToChange
    > {
    > public void Update(object source, ToolStripItemEv entArgs e)
    > {
    > // My code
    > }
    > }
    >
    > private void Form1_Load(obje ct sender, EventArgs e)
    > {
    > MyComboBox myComboBox = new MyComboBox();
    > RespondToChange doChange = new RespondToChange ();
    >
    > // Note that I am relying on members in the inherited
    > ToolStripComboB ox to accomplish this
    > // I receive the following error: Cannot implicitly convert type
    > 'System.Windows .Forms.ToolStri pItemEventHandl er' to 'System.EventHa ndler'
    > myComboBox.Text Update += new
    > ToolStripItemEv entHandler(doCh ange.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.[/color]


    Comment

    • wschlichtman

      #3
      Re: Event Processing

      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 ToolStripComboB ox. 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
      ToolStripComboB ox, and as you say, it is of type System.EventHan dler. My
      question then is how do I resolve this?

      Sorry for my ignorance. I am returning to programming after many years in
      tech support.
      [color=blue]
      > 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 ToolStripItemEv entHandler[/color]

      Comment

      • Ignacio Machin \( .NET/ C# MVP \)

        #4
        Re: Event Processing

        Hi,


        [color=blue]
        > As for the TextUpdate event, I have not been able to find the correlating
        > event handler in the ToolStripComboB ox. 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
        > ToolStripComboB ox, and as you say, it is of type System.EventHan dler. My
        > question then is how do I resolve this?[/color]


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




        cheers,

        --
        Ignacio Machin,
        ignacio.machin AT dot.state.fl.us
        Florida Department Of Transportation


        Comment

        Working...