1 Reply Latest reply on Jun 1, 2016 1:58 PM by Nocodes79

    ProcessBook Add-in to fit-all on display activation/open

    Nocodes79

      Hi evrybody,

       

      I am experiencing the same glitch as mentioned in an old post:

      FitAll AddIn Glitch

       

      I have developed an add-in thet, when a display is activated, sets zoom to fit all.

      When the display is open in background, there is no problem, but, when I open it from scratch, it sets the zoom to 38% or 13% depending on the physical screen resolution.

       

      PI ProcessBook version is 2015.

       

      Any hint about it?

        • Re: ProcessBook Add-in to fit-all on display activation/open
          Nocodes79

          I am doing autosupport again:

           

          The problem was that I applied the fit all on processbook application open or activate event.

          In this way it does not work, I think because  when a display is opened, the viewport and display dimensions are not computed yet.

           

          The solution is capturing the Display.Open event and applying the fit all:

          • First capture the Processbook app open display event at add-in initalization
                  /// <summary>
                  /// Get ProcessBook app and start listening display activation / deactivation
                  /// </summary>
                  /// <param name="pbApp">Calling ProcessBook</param>
                  public PB_Manipulator(PBObjLib.Application pbApp)
                  {
                      pb = pbApp;
                      pb.DisplayActivate += new EApplication_DisplayActivateEventHandler(pbDisplayActivate);
                      pb.OpenDisplay += new EApplication_OpenDisplayEventHandler(onPBOpenDisplay);
                      pb.DisplayDeactivate += new EApplication_DisplayDeactivateEventHandler(pbDisplayDeActivate);
                  }
          

           

          • then when capturing the processbook open display start capturing the Display.Open event
                  private void onPBOpenDisplay(Display aDisplay)
                  {
                      //get the display
                      this.actDisplay = aDisplay;
                      this.actDisplay.Open += new EDisplay_OpenEventHandler(onThisDisplayOpen);
                  }
          
          • then use this event to apply fitall
                  private void onThisDisplayOpen()
                  {
                      fitAllDisplay(this.actDisplay);
                  }
          
                  /// <summary>
                  /// Fit all a display
                  /// </summary>
                  /// <param name="aDisplay">Display to fit all</param>
                  private void fitAllDisplay(Display aDisplay)
                  {
                      aDisplay.Zoom = "FitAll";
                  }