Monday, 15 August 2011

c# - How to avoid Child form button click event to call parent form handler -



c# - How to avoid Child form button click event to call parent form handler -

i working on windows mobile ce. have below question.

i have parent form bookform displays book info in table book number, author etc. have button on screen says "ok", acts button.

i have kid form paidbookform display same info in same ui layout. have button btnsubmit on screen says "buy", takes user screen user can purchase book.

public partial class paidbookform : bookform { }

i have event handler assigned btnsubmit in parent form

this.btnsubmit.click += new system.eventhandler(this.btnback_click);

i have event handler assigned btnsubmit in kid form

this.btnsubmit.click += new system.eventhandler(this.btnbuy_click);

the problem is:

when purchase clicked in kid form, btnback_click called first , btnbuy_click called. how avoid btnback_click called ?

first thing maintain in mind "child form" is also "parent form". not 2 different objects. kid form instance of parent form, additional functionality.

in case, seems polymorphism might way go. instead of current event handler subscriptions, this:

class bookform : form { protected virtual void subscribebutton() { this.btnsubmit.click += new system.eventhandler(this.btnback_click); } public bookform() { initializecomponent(); subscribebutton(); } } class paidbookform : form { protected override void subscribebutton() { this.btnsubmit.click += new system.eventhandler(this.btnbuy_click); } }

if not appropriate needs, need post code example.

c# .net windows-mobile-6.5

No comments:

Post a Comment