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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Previously focused control

Previously focused control

Scheduled Pinned Locked Moved C#
3 Posts 2 Posters 1 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.
  • H Offline
    H Offline
    HJo
    wrote on last edited by
    #1

    Hi all, I wonder if there is some way to find out which control had input focus previously to an other... I.e. from a btn_Click(...) event handler, I want to know which control had focus before the user clicked the button. Thanks in advance, /Henrik J.

    C 1 Reply Last reply
    0
    • H HJo

      Hi all, I wonder if there is some way to find out which control had input focus previously to an other... I.e. from a btn_Click(...) event handler, I want to know which control had focus before the user clicked the button. Thanks in advance, /Henrik J.

      C Offline
      C Offline
      Corinna John
      wrote on last edited by
      #2

      You can save the last focused control in the Leave event method: private Control lastControl; private void allControls_Leave(object sender, EventArgs e){ lastControl = (Control)sender; }

      H 1 Reply Last reply
      0
      • C Corinna John

        You can save the last focused control in the Leave event method: private Control lastControl; private void allControls_Leave(object sender, EventArgs e){ lastControl = (Control)sender; }

        H Offline
        H Offline
        HJo
        wrote on last edited by
        #3

        That should do the trick! But how do I add the Leave event to all controls? Do I have to loop through all controls and add it one by one, or is is possible to add an event to a collection? (Doesn't seem to be possible with ControlsCollection) Thanks! /Henrik

        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