6 Replies Latest reply on May 22, 2015 4:17 PM by bshang

    C# axPbd Do not work!

    Nikolay

      Hi!


      Why do not work this code?

        • Re: C# axPbd Do not work!
          dng

          Hi Nikolay,

           

          The reason the code gets a NullReferenceException is because axPbd1.Display is null the time you assign it to MyDisplay. After the DisplayURL is displayed, it takes some time for the PB display to get loaded to your axPbd1 control. If you execute the two lines:

          MyDisplay = (PBObjLib.Display)axPbd1.Display;
          MyDisplay.BeforeDoubleClick += new EDisplay_BeforeDoubleClickEventHandler(MyDisplay_BeforeDoubleClick);
          

           

          after the display is loaded, you will not get the error. One thing you can try is to run this at the axPbd1_ReadyStateChange event. Please let me know if this helps. Thanks.

          • Re: C# axPbd Do not work!
            Nikolay

            I have done so.

             

            private void axPbd1_ReadyStateChange(object sender, AxPBDCtrl._DPbdEvents_ReadyStateChangeEvent e)

            {

                MyDisplay = (PBObjLib.Display)axPbd1.Display;

                MyDisplay.Click+= new EDisplay_BeforeDoubleClickEventHandler(MyDisplay_Click);

            }

             

            void MyDisplay_Click(int lvarX, int lvarY)

            {

                 Text="Click";

            }

             

            Error is gone, but the event is not working.I used the Click method to Display. Launch the app and cashing in on the mnemonic, the Click event does not fire.

              • Re: C# axPbd Do not work!
                dng

                Hi Nikolay,

                 

                First of all, you will want to use EDisplay_ClickEventHandler instead of EDisplay_BeforeDoubleClickEventHandler for your click event. I tested your code and changed a few things, but was unable to get the click event within the display working so far. Can you let us know what you are trying to achieve when the user clicks on the display? Will an event handler on the actual windows form itself suffice? Alternatively, if you want to affect something within the display, you can build VBA code within the PDI file to handle the click event.

                 

                Can you explain what you meant by "launch the app and cashing in on the mnemonic"?

                 

                EDIT: I did get it to work eventually. Here is my code in C#:

                 

                        public Form1()
                        {
                            InitializeComponent();
                        }
                
                        private void axPbd1_ReadyStateChange(object sender, AxPBDCtrl._DPbdEvents_ReadyStateChangeEvent e)
                        {
                            label1.Text = "Ready";
                            PBObjLib.Display disp = (PBObjLib.Display) axPbd1.Display;
                            disp.Click += new EDisplay_ClickEventHandler(disp_Click);
                        }
                
                        void disp_Click(int lvarX, int lvarY)
                        {
                            MessageBox.Show("message");
                        }
                
              • Re: C# axPbd Do not work!
                Nikolay

                HI.

                In your example, when you press Display, the following message appears MessageBox.Show("message"); ???

                • Re: C# axPbd Do not work!
                  bshang

                  Hi Nikolay,

                   

                  We'd like to follow up on this thread. Did you get your questions answered and if so, could you mark one of Daphne's posts as correct?