Results 1 to 3 of 3

Thread: Which: Lost Focus or Leave?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Location
    Three Rivers, MI
    Posts
    354

    Which: Lost Focus or Leave?

    Is there any difference in using the lost focus or leave for evaluating text entered into a text box?

    I have been using lost focus but have noticed that most of the sample codes I see use the leave.

    Is there any difference or advantage of one over the other?

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    First ,
    MSDN Help

    -Control.LostFocus Event : Occurs when the control loses focus.
    If the CausesValidation property is set to false, the Validating and Validated events are suppressed.

    If the Cancel property of the CancelEventArgs object is set to true in the Validating event delegate, all events that would normally occur after the Validating event are suppressed.

    Note The GotFocus and LostFocus events are low-level focus events that are tied to the WM_KILLFOCUS and WM_SETFOCUS Windows messages. Typically, the GotFocus and LostFocus events are only used when updating UICues. The Enter and Leave events should be used for all controls except the Form class, which uses the Activated and Deactivate events. For more information about the GotFocus and LostFocus events, see the WM_SETFOCUS and WM_KILLFOCUS topics in the Keyboard Input Reference section of the Platform SDK Documentation in the MSDN Library.
    CAUTION Do not attempt to set focus from within the LostFocus event handler. Doing so can cause your application or the operating system to stop responding. For more information about the LostFocus event, see the WM_KILLFOCUS topic in the Keyboard Input Reference section, and the Message Deadlocks topic in the Messages and Message Queues section of the Platform SDK Documentation in the MSDN Library.



    -Control.Leave Event : Occurs when the input focus leaves the control.
    If the CausesValidation property is set to false, the Validating and Validated events are suppressed.

    Note The Enter and Leave events are suppressed by the Form class. The equivalent events in the Form class are the Activated and Deactivate events. The Enter and Leave events are hierarchical and will cascade up and down the parent chain until the appropriate control is reached. For example, assume you have a Form with two GroupBox controls, and each GroupBox control has one TextBox control. When the caret is moved from one TextBox to the other, the Leave event is raised for the TextBox and GroupBox, and the Enter event is raised for the other GroupBox and TextBox.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Location
    Three Rivers, MI
    Posts
    354
    Hey Pirate thanks. You helped me out and made your point all at the same time.

    I usually do a search before posting, although I have a hard time getting what I want out of MSDN anyway, I didn't this time because I thought developers experience would be more valuable then the Help file would (in this case anyway).

    However after reading what you posted I would say that clears it up pretty well.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width