Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Control Focus Problem - a Bug? or..

Control Focus Problem - a Bug? or..

Scheduled Pinned Locked Moved C#
helpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rnvrnv
    wrote on last edited by
    #1

    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

    L 1 Reply Last reply
    0
    • R rnvrnv

      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

      L Offline
      L Offline
      Luis Alonso Ramos
      wrote on last edited by
      #2

      Well, I've never programmed for CF, but the recommended way to determine when a control gets focus AFAIK are the Enter and Leave events. However, why are you deriving from Control? 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!

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups