0

here I'm talking about Double Agent (a windows7/8 version of MS Agent, the same as office 2007 I suppose).

I'm sorry I'm talking about a full product but i'm really being mad to catch an event( the bundled sample does not help for this)...

In the sample i have a similar handle:

public MsaWithDa()
{
    InitializeComponent();

    mDaControl = new DoubleAgent.Control.Control ();
    mDaControl.Show += new DoubleAgent.Control.ShowEventHandler (mDaControl_Show);
}

and this:

private void mDaControl_Show(string CharacterID, DoubleAgent.Control.VisibilityCauseType Cause)
{
    SetDaControlButtons();
}

Now I need to handle a different event (when the user select a command from the menu of the Agent).. and I have this

private void mainAgent_Command(object sender, AgentObjects.IAgentCtlCommand e) 
{
        mDaControlChar.Play("Wave");
        mDaControlChar.Speak("Hello!");
}

It's based on the user manual of the product:

Double Agent sends this event when your application is input-active and the user chooses a command from the character's pop-up menu, or by spoken input.

public event CtlCommandEventHandler CtlCommand

I added this to the main form:

mDaControl.Command += new DoubleAgent.Control.Command(mDaControl_Command);

but something is missing and I have to pass the two values to be able to test.

Sorry, I understand this is a stupid question and sure super-basic but this is the first time I need to use Event Handlers in c#

Hope someone should help, thanks a lot

EDIT: Based on this article: Understanding events and event handlers in C#

I now coded this:

public delegate void MyEventHandler(object sender, AgentObjects.IAgentCtlCommand e);
public event MyEventHandler AgentObjects;

and this:

    private void InitializeAgent()
    {
          mDaControl.Command += new MyEventHandler(HandleSomethingHappened);
    }

    private void HandleSomethingHappened(object sender, AgentObjects.IAgentCtlCommand e) 
{
        mDaControlChar.Play("Wave");
        mDaControlChar.Speak("Hello!");
}

BUT i have an error here:

new MyEventHandler(HandleSomethingHappened)

Error 1 Cannot implicitly convert type 'XCopyPro.Main.MyEventHandler' to 'DoubleAgent.Control.CommandEventHandler' C:\Users\Shawn\Documents\Visual Studio 2013\Projects\XCopyPro\XCopyPro\FormMain.cs 159 37 XCopyPro

Community
  • 1
  • 1
WizardingStudios
  • 554
  • 2
  • 7
  • 22

2 Answers2

0

You should be able to do a new DoubleAgent.Control.CommandEventHandler instead of a new MyEventHandler. As long as your method has the same signature as the DoubleAgent event handler it should work.

Sean O'Brien
  • 183
  • 7
  • This: mDaControl.Command += new DoubleAgent.Control.CommandEventHandler(HandleSomethingHappened); Produce Error 1 No overload for 'HandleSomethingHappened' matches delegate 'DoubleAgent.Control.CommandEventHandler' C:\Users\Shawn\Documents\Visual Studio 2013\Projects\XCopyPro\XCopyPro\FormMain.cs 159 37 XCopyPro – WizardingStudios May 09 '15 at 15:52
0

Sorry, i'm a newbie in C#! You should not help me without docs...

I solved myself following the manual...

The code is pretty simple, somewhere this:

mDaControl.Command += new DoubleAgent.Control.CommandEventHandler(mDaControl_Commands);

And this:

private void mDaControl_Commands(DoubleAgent.Control.UserInput e)
{
    mDaControlChar.Play("Wave");
    mDaControlChar.Speak("Hello!");
}
WizardingStudios
  • 554
  • 2
  • 7
  • 22