c# - Listening for events only under certain circumstance -
i'm after opinions / advice i'm rather new event-driven programming , c# having come web development origins.
i'm making programme in c# / winforms, series of splitcontainer
controls on main form. want allow user able select grouping of them, 3 out of 8 (not limited that). start selecting them, user click button , programme go selecting mode, , @ time, if user clicks on control, color of alter indicating selected.
at stage, have made work fine, sense it's not efficient in detection of mousemove events. i've bound mousemove event splitcontainer, , within event, programme detects whether we're in selecting mode. if so, , user clicks, alter color. if not in selecting mode, wont anything.
my worry every time user moves cursor on control, event fired , detects whether selecting mode enabled. sense should other way around, is; in selecting mode such event listened to.
here cut-outs explain i've got @ moment.
public bool selectingmode = false; public form(){ splitcontainer split = new splitcontainer(); split.mousemove += new mouseeventhandler(mousemoved); this.controls.add(split); } void mousemoved(object sender, mouseeventargs e){ if(selectingmode){ //change color of split } }
as mentioned, mousemoved() method triggered every time user moves cursor on control, , actions if it's in selectingmode. there way reverse this? trigger event if in selectingmode?
if i'm worrying doesn't matter, able explain why? seems poor practice , using scheme resources (however little), considering vast bulk of time using programme spent cursor within box.
i appreciate , input, thanks! sean
implement selectingmode
property , set in setter split.mousemove += new mouseeventhandler(mousemoved);
or split.mousemove -= new mouseeventhandler(mousemoved);
depending on true or false.
besides don't think alter necessary performance reasons.
c# winforms visual-studio
No comments:
Post a Comment