winforms - Adding Event Handler in VB.NET Custom Control -


i have scenario in have implement usercontrol , on clicking button "process" background worker works.

i want trigger function/method of parent form going add usercontrol upon "runworkercompleted" event.

private sub btngo_click(byval sender system.object, byval e system.eventargs) handles btngo.click     try                     bgwfetchgiftcard.runworkerasync()     catch ex exception         writelog(ex)     end try end sub  private sub bgwfetchcard_dowork(byval sender system.object, byval e system.componentmodel.doworkeventargs) handles bgwfetchcard.dowork     try         ds = new dataset()         'call api service denomination         ds = apicall()     catch ex exception         writelog(ex)     end try end sub  private sub bgwfetchcard_runworkercompleted(byval sender system.object, byval e system.componentmodel.runworkercompletedeventargs) handles bgwfetchcard.runworkercompleted     if ds isnot nothing         result = true            'at point want raise event                   'raiseevent      else         'showmessage("fail")     end if end sub 

how may achieve this?anybody kindly suggest

assuming code shown in usercontrol, need declare event , raise (there nothing special regarding usercontrol):

public event somethingisdone (sender object, e eventargs)  ... private sub bgwfetchcard_runworkercompleted(sender object,            e runworkercompletedeventargs) handles bgwfetchcard.runworkercompleted     if ds isnot nothing         result = true              raiseevent somethingisdone(me, new eventsargs())       else         'showmessage("fail")     end if end sub 

in cases need pass information in event, define custom eventargs class inherits eventargs add properties need:

public class somethingdoneeventargs     inherits eventargs      public property somethingname string      ' convenience:     public sub new(name string)         somethingname = name     end sub end class 

then pass instance of class rather the generic eventargs:

... raiseevent somethingisdone(me,             new somethingdoneeventargs("foo"))  

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -