Print Page | Close Window

Set focus to control inside docking pane

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Docking Pane
Forum Description: Topics Related to Codejock Docking Pane
URL: http://forum.codejock.com/forum_posts.asp?TID=15149
Printed Date: 03 May 2024 at 7:43pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Set focus to control inside docking pane
Posted By: tobi
Subject: Set focus to control inside docking pane
Date Posted: 10 September 2009 at 12:46pm
I have a VB6 SDI app with one docking pane !
At application startup I want to set the focus to the textbox inside the pane, but at the end of FORM_LOAD I receive error !

I think at this moment the docking pane isn't yet ready ?

Does anyone have idea when and where I can set focus to the textbox inside the pane?






Replies:
Posted By: jpbro
Date Posted: 10 September 2009 at 4:16pm
I don't think that this is a DockingPane limitation. You can never call SetFocus methods inside the Form_Load event because the control must be visible otherwise an error will be raised (you can try this on a regular VB6 form). You can set the focus inside the Form_Activate event though (because the form is visible at this point). If you only want this to happen once, you can use a Static variable...something like:


Private Sub Form_Activate()
   Static s_Activated As Boolean

   If Not s_Activated Then
      s_Activated = True

      Me.Text1.SetFocus
   End If
End Sub




-------------
Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6



Posted By: chrisABC
Date Posted: 05 November 2009 at 12:52pm
I used to get this error seemingly at random on different PCs. The problem is when the control (eg TextBox) you want to set Focus to is not visible when you try to set focus -- this gives error.  In my apps, I think timing caused the problem to only happen sometimes (eg maybe sometimes the control is visible, sometimes it is not quite ready).

I solved this by adding a Timer to each form that needs this.  Set the Timer to give a delay of 200 mSec or so, and in the Form_Activate (or other) event, set a module level variable to indicate which control is to get Focus. 
The Form is displayed, and then the Timer fires and sets Focus to that control. (And then set the Timer off).

This can be more useful. If you have several Forms (or Panes) on screen, you can remember which control in each one had focus and set focus to it again when user returns to that form.


-------------
Chris (Manchester, UK) -- www.abc6.co.uk ---- Using CodeJock ActiveX Suite 13.1.0 with Windows8, VB6 SP6



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net