Form_Load (how to focus a control ?)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Cybertof

    Form_Load (how to focus a control ?)

    Hello,

    I would like to focus on a special control on my form during Form_Load
    inialisation. The focused control may change according to internal
    parameter value (so it's not always the same control).

    How to do it ?

    Example :
    tbName.Focus();

    My problem is that within the FormLoad, setting focus on a control does
    not seem to have effect.


    Regards,
    Cybertof.
  • Juan Gabriel Del Cid

    #2
    Re: Form_Load (how to focus a control ?)

    The control with the smallest (by this I mean a is smaller than b if a < b)
    TabIndex is focused on startup automatically. Change this property of the
    control you want to have the initial focus.

    Hope that helps,
    -JG


    Comment

    • Eric Cadwell

      #3
      Re: Form_Load (how to focus a control ?)

      I use a timer object to set the focus after the Form loads.

      Drop a Timer control on the form set it to Enable = true, Interval = 1. Then
      register the Tick event.

      In the handler for that event set the focus to the desired control. That
      allows you to keep your tab order in tact.

      HTH;
      Eric Cadwell



      Comment

      • Morten Wennevik

        #4
        Re: Form_Load (how to focus a control ?)

        If you use groupboxes, you may need to set focus to the groupbox before
        setting focus to a control within it. Same with panels, or any controls
        that can contain other controls.

        --
        Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

        Comment

        • Cybertof

          #5
          Re: Form_Load (how to focus a control ?)

          Thanks all.

          I have found another method : setting the focus in the activate event,
          so i'm sure all the controls are visible when focusing on them.

          Unfortunately, i have to deal with a status boolean flag saying so my
          focusing operates only the first time it activates (after the load).

          The TabIndex is good if the control to have focus does not change
          according to custom settings.
          In my cas, i had to do it programmaticaly .
          Bad luck that it cannot be done in the form_load event.


          Regards,
          Cybertof.

          Comment

          Working...