4 Replies Latest reply on Apr 20, 2012 3:43 PM by hanyong

    Create ActiveView(AxPbd) Component fully programmatically



      Hi Colleagues,

      I spent quite a lot of time and probably somebody can help me with a problem.

      In C# Application Form I need to create an AciveView Component (AxPbd) for showing some trends.

      It works perfect when I just add it from a ToolBar and set the DisplayURL when compile time. I can then add trends programmatically in the predefined on a form Component (AxPbd) with DisplayURL  - hardcoded.

      The problem is that I cannot change the DisplayURL programmatically, in fact I can but after that I cannot add any trends on a display object:

      PBObjLib.Display Trend1Display_Fill;

      Trend1Display_Fill = axPbd1.Display as PBObjLib.Display;

      MyTrend_Fill = (PBSymLib.Trend)Trend1Display_Fill.Symbols.Add(PBObjLib.pbSYMBOLTYPE.pbSymbolTrend);


      It says that the object Trend1Display_Fill not an instance of object (it is just null )

      Can somebody example  C#-code  how to dinamically create this component  and add trends on it as well as change DisplayURL - programmatically.


      The piece of code is beneath.


      Thanks for paying attention to that




      AxHost _pbDisplay = new AxPBDCtrl.AxPbd();


      _pbDisplay.Name = "axPbd1";




      IntPtr forceCreation = _pbDisplay.Handle;


      _pbDisplay.Dock = DockStyle.None;


      AxPBDCtrl.AxPbd axPbd1 = (AxPBDCtrl.AxPbd)_pbDisplay;


      axPbd1.DisplayURL = @"C:\Projects\trend.pdi";


      _pbDisplay.Enabled = true;



        • Re: Create ActiveView(AxPbd) Component fully programmatically

          Hi Oleg,


          Actually you can update the DisplayUrl Property of the ActiveView Control programmatically. But you will need to refresh the control such that it will load the content from the new display that you have set.


          This would take sometime for the display to be loaded in the control and hence you can use the ReadyStateChanged event of the ActiveView control to check that the control is done loading the display, before adding a new trend to it etc. Based on your error, I think you are getting that because you are trying to get the display before the control is done loading it, and hence returning you a null reference.


          We can use a simple form application can illustrate this, with ActiveView control (axPbd1) and button (button1) added to the form. And we use the Button_Click event to trigger the change and adding a trend.


          Here's a code snippet:

          bool Button1_Pressed = false;
          private void button1_Click(object sender, EventArgs e)
               // a static parameter to let us know that the button to change display and add trend is pressed by user
               Button1_Pressed = true;
               // change the display url
               axPbd1.DisplayURL = @"C:\Users\hanyong\Documents\TestISlimFast.PDI";
               // refresh the control to load the new display

           private void axPbd1_ReadyStateChange(object sender, AxPBDCtrl._DPbdEvents_ReadyStateChangeEvent e)
               Display ThisDisplay;
               Trend MyTrend;
               TrendFormat aFormat;
               // if ActiveView control state is done loading (4) and the change in state caused by the button, then add the trend to display.
               if (axPbd1.ReadyState == 4 && Button1_Pressed)
                   // get display object from ActiveView control
                   ThisDisplay = (Display)axPbd1.Display;
                   // add trend to display
                   MyTrend = (Trend)ThisDisplay.Symbols.Add(PBObjLib.pbSYMBOLTYPE.pbSymbolTrend);
                   // add trace to trend
                   // set trend position
                   MyTrend.Top = 100;
                   MyTrend.Left = 100;
                   // get and set trend format
                   aFormat = MyTrend.GetFormat();
                  aFormat.ShowTagName = !aFormat.ShowTagName;
                  aFormat.ShowServerName = !aFormat.ShowServerName;
                   MyTrend.TrendTitle = System.DateTime.Now.ToString();
                   MyTrend.SetStartAndEndTime("*-1h", "*");
                   Button1_Pressed = false;

          Hope this helps

          1 of 1 people found this helpful