More on Winforms and the GUI Controls

I must admit, I'm having fun using PB11 with C#.

I've found a way to add my own event handling in PB Winforms simply by using a .NET Assembly. Some events are not available to us in the IDE. Some events that we use to use have been "filtered" out and become unsupported. There is a way to execute these events with a couple function calls.

There were 2 events in my case that I needed to trap. Neither of which were available in the IDE. They were the Paint and MouseLeave event. In the past I would have used the pbm_paint event id for the Paint event and the Other event for the MouseLeave event. PB11 filters these events out so they are no longer options.

To get around this I created a .NET assembly in C#. This new class had 1 public function and accepted one arguements ("object pbObj"). The function did the following:

namespace PBEvent
{
    public class PBEventHandler
    {
        private object pbObject;
        
        private void PBTriggerEvent(string eventId)
        {
            Sybase.PowerBuilder.Win.PBUserObject pbUO = (Sybase.PowerBuilder.Win.PBUserObject)pbObject;
            pbUO.TriggerEvent(eventId);
        }

        public void PBRegisterObject(object pbObj)
        {
            pbObject = pbObj;

            pbObj.Paint += delegate { PBTriggerEvent("ue_Paint"); };
            pbObj.MouseLeave += delegate { PBTriggerEvent("ue_MouseLeave"); };
        }

    }
}

And calling it was even simpler:

PB Code:

//Declare instance Variable
#if defined PBDOTNET then
    PBEvent.PBEventHandler i_PBEventHandler
#end if

//Register events - Constructor event

#if defined PBDOTNET then
    i_PBEventHandler = CREATE PBEvent.PBEventHandler

    i_PBEventHandler.PBRegisterObject(THIS)
#end if
 

Brad 

January 15, 2008 08:43 by bradwery
E-mail | Permalink | Comments (5) | Comment RSSRSS comment feed

Comments

January 23. 2008 14:10

Wow, now this is interesting! Have you tried being able to pass in parameters to th triggered events?

yeyi

February 17. 2008 15:44

Yeyi,

I haven't tried passing paramaters. I bet it's possible. I'll have to look at the PB assemblies.

Brad

bradwery

February 17. 2008 17:44

Sorry,

the correct way is:

string ( Message.LongParm, "address" )

regards

Levi

Levi

February 17. 2008 18:26

Hi Yevi,

I used this in my application

C#:
_mainControl.TriggerEvent("ue_expand", 0, "test"Wink;

PB(ue_exande);
STRING ls_param
ls_param = string ( Message.StringParm, "address" )

regards

Levi


Levi

February 18. 2008 11:57

Correct. I tried it yesterday and found that passing arguments back to a PB event is easy (just as you described).

I created a new .NET compatible canvas object and I use this technique to pass back parameters for the paint event and any mouse related events.

Brad

bradwery