6 Replies Latest reply on Jun 27, 2013 1:22 PM by dhollebeek

    How to hook into the Application.DisplayOpen event


      I have a C# application the creates a PI Application using the PI Processbook Type Library.  I want to have my own event handler that fires when the Application.DisplayOpen event fires.


       This is what I have so far:

      public delegate void DisplayOpenHandler(object sender, EventArgs e);
      public void DisplayOpenMessage(object sender, EventArgs e)
          MessageBox.Show("Caught Display Open!");

       I set it with: 

      m_oPIApp.OpenDisplay += new DisplayOpenHandler(DisplayOpenMessage);

      where m_oPIApp is a PBObjLib.Application object.


      Unfortunately, this gives me a compile error:
      Cannot implicitly convert type 'PI_Display_Manager.PI_Application_Handler.DisplayOpenHandler' to 'PBObjLib.EApplication_OpenDisplayEventHandler'


      Can someone give me a steer on what I need to do here?



        • Re: How to hook into the Application.DisplayOpen event

          OK - I've figured that it should be:

          m_oPIApp.OpenDisplay +=new EApplication_OpenDisplayEventHandler(m_oPIApp_OpenDisplay);

           Now I need to know what the parameters for m_oPIApp_OpenDisplay need to be.  I tried to use System.Reflection to get them, but:

          PBObjLib.Application oPIApplication =  new PBObjLib.Application();
          Type PIApplicationType = oPIApplication.GetType();
          EventInfo OpenDisplayInfo = PIApplicationType.GetEvent("OpenDisplay");
          Type tOpenDisplay = OpenDisplayInfo.EventHandlerType;

           GetEvent("OpenDisplay") returns null.  So I tried:

           EventInfo[] PIAppEvents = PIApplicationType.GetEvents();
          for (int i = 0; i < PIAppEvents.Length; i++)
              Debug.WriteLine(PIAppEvents[ i].Name);

           And the array also returns no events (Length == 0).


          I wondered if it was because I am using the application interface, rather than the ApplicationClass object, but I get a compiler message that I can't embed the ApplicationClass


          Where to from here?  Can someone provide me with the parameters?


          I figured they would be "PBObjLib.Application App" (for sender) and "bool Convert" for the event args, but it doesn't like that.