Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Container.SetFocus() issue
Message
De
15/10/2013 16:43:19
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01585520
Message ID:
01585530
Vues:
41
>>>I find it strange that when I set focus to a container object which has user controls on it, the focus goes to any of the controls on the container, but not the one that is set TabStop = 1.
>>>
>>>So when I call THISFORM.cntMyContainer.SetFocus(), it sets the focus to some control, like the third or fourth in the tab order on that container. When I TAB into the container, it does move first to the first control etc, so there is a difference between setting the focus with TAB or by calling SetFocus().
>>>
>>>It is quite annoying, because the behavior is nothing what the user would expect. I was wondering if somebody has a workaround for this, other than overwriting the SetFocus() of the container or create a custom method that does the focus thing, because that would be quite an overhead in the application.
>>
>>I have never seen what you describe. But as a workaround, you could use THISFORM.cntMyContainer.myControl.SetFocus()
>
>The problem is that the code is generic, so I don't know the name of the control.
>
>To go into further detail I made a class definition that shows what is the problem. If you run the form and press the button you can see what is happening, it sets the focus to the second control in the container object, although it has TabIndex = 2.
>
>In the Container I added two textboxes. First I add the "second" one and then the "first" one.
>I give the TabIndex = 1 to the first textbox, which I added after the second.
>
>So the tab index is ignored and instead the order of instantiation is taken into account when the focus is set to the container.
>Now in the class definition it would be easy to "switch" the instantiation of the controls, but in visual classes you don't have so much control. So what I need to figure out is how to force the first object to be instantiated on the container in a visual class.
>
>
>LOCAL loForm
>loForm = CREATEOBJECT("TestForm")
>loForm.Show(1)
>*
>DEFINE CLASS TestForm AS Form
>*
>AUTOCENTER = .T.
>*
>ADD OBJECT txt AS Textbox WITH ;
>		Left = 60, ;
>		Top = 60, ;
>		Width = 80, ;
>		Height = 24, ;
>		Value = "Test", ;
>		TabIndex = 1, ;
>		Visible = .T.
>ADD OBJECT cmd AS CommandButton WITH ;
>		LEFT = 146, ;
>		Top = 60, ;
>		Width = 90, ;
>		Caption = "SetFocus", ;
>		Tooltiptext = "Set focus to container", ;
>		Height = 24, ;
>		TabIndex = 2, ;
>		Visible = .T.
>ADD OBJECT cnt AS Container WITH ;
>		Left = 60, ;
>		Top = 120, ;
>		Width = 180, ;
>		Height = 120, ;
>		TabIndex = 3
>		Visible = .T.
>PROCEDURE INIT
>	*
>	THIS.cnt.AddObject("txt2","TEXTBOX")
>	WITH THIS.cnt.txt2
>		.LEFT = 30
>		.Top = 70
>		.Width = 120
>		.TabIndex = 2
>		.Visible = .T.
>		.Value = "TabIndex = 2"
>	ENDWITH
>	*
>	THIS.cnt.AddObject("txt1","TEXTBOX")
>	WITH THIS.cnt.txt1
>		.LEFT = 30
>		.Top = 30
>		.Width = 120
>		.TabIndex = 1
>		.Visible = .T.
>		.Value = "TabIndex = 1"
>	ENDWITH
>	*
>ENDPROC
>PROCEDURE cmd.Click
>	THISFORM.cnt.SetFocus()
>ENDPROC
>*
>ENDDEFINE
>
Christian,

I leave for Phoenix in just a few hours, since I will attend SWFox this years. I will check your code when I arrive there. It's sad that you won't be there, though.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform