Control Focus Problem - a Bug? or..
-
Hi, i would like to create a simple control for smart phone (cf2.0) that changes its background color depending upon whether it is focused or not. i have the following code. class mylabel:Control{ protected override void OnGotFocus(EventArgs e){ base.OnGotFocus(e); this.BackColor = Color.Red;} protected override void OnLostFocus(EventArgs e){ base.OnLostFocus(e); this.BackColor = Color.White;} } The problem is it can get focus (and changes its bg color) but it seems it does not loose focus. if i inherit LinkLabel instead of Control then it works fine. What could be wrong? i would really appreciate. regards, rnv
-
Hi, i would like to create a simple control for smart phone (cf2.0) that changes its background color depending upon whether it is focused or not. i have the following code. class mylabel:Control{ protected override void OnGotFocus(EventArgs e){ base.OnGotFocus(e); this.BackColor = Color.Red;} protected override void OnLostFocus(EventArgs e){ base.OnLostFocus(e); this.BackColor = Color.White;} } The problem is it can get focus (and changes its bg color) but it seems it does not loose focus. if i inherit LinkLabel instead of Control then it works fine. What could be wrong? i would really appreciate. regards, rnv
Well, I've never programmed for CF, but the recommended way to determine when a control gets focus AFAIK are the
Enter
andLeave
events. However, why are you deriving fromControl
? Unless you are creating a new control from scratch, if you want to add this functionality to existing controls (text boxes, buttons, and so on) I would rather subscribe to the events for the controls. You could write a little class that given the control reference in the constructor, it would subscribe and handle the events. Then you could apply it to any control with just one line of code.Luis Alonso Ramos Intelectix Chihuahua, Mexico
Not much here: My CP Blog!