Event when Controls in a PictureBox get Focus
Is there any event that triggers when any control in a picturebox receives focus.
I have around 10 Controls in a picturebox, and i want to do something if any of does receive focus (Like setting a command buttom as default depending which group of controls have focus.)
So is there a easy way or i need to code it in each control?
Re: Event when Controls in a PictureBox get Focus
Hi,
I think you do not need to code everysingle ctrl..because you can create an array of ctrls when you copy and paste them (VB creates a new button called cmdbutton(1)..cmdbutton(2) and then you can use their index to recognize them as follows:
sub myctrl_GotFocus(index as.....)
dosomething
end sub
sub dosomething(indx....)
msgbox indx
...
...
end sub
I'm leaving..bye
Cheers
Re: Event when Controls in a PictureBox get Focus
What kind of controls are in the container - each control will get its own gotfocus event.
Re: Event when Controls in a PictureBox get Focus
You can group controls of the same type in control arrays, so there is only a single got focus event for each group.
Re: Event when Controls in a PictureBox get Focus
But its a few type of controls. Combo's text, datepickers etc etc.
Does anyone know of a easy way?
Re: Event when Controls in a PictureBox get Focus
But its a few type of controls. Combo's text, datepickers etc etc.
Does anyone know of a easy way?
The same way the Option Button knows when its in a single picturbox.
Re: Event when Controls in a PictureBox get Focus
No easy way.
You could in theory intercept the Windows message queue, but it would probably be less work to check each control's got focus event. How many controls are we talking about here?
Could you put the picture box on its own form and check the activate event instead?
Re: Event when Controls in a PictureBox get Focus
in this form how do the option boxes know if they are in the same picturebox?
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 7635
ClientLeft = 60
ClientTop = 450
ClientWidth = 10110
LinkTopic = "Form1"
ScaleHeight = 7635
ScaleWidth = 10110
StartUpPosition = 3 'Windows Default
Begin VB.PictureBox Picture2
Height = 2970
Left = 5685
ScaleHeight = 2910
ScaleWidth = 3630
TabIndex = 4
Top = 1785
Width = 3690
Begin VB.OptionButton Option6
Caption = "Option6"
Height = 270
Left = 1185
TabIndex = 7
Top = 1965
Width = 1275
End
Begin VB.OptionButton Option5
Caption = "Option5"
Height = 420
Left = 1035
TabIndex = 6
Top = 1320
Width = 1785
End
Begin VB.OptionButton Option4
Caption = "Option4"
Height = 465
Left = 975
TabIndex = 5
Top = 495
Width = 1965
End
End
Begin VB.PictureBox Picture1
Height = 3045
Left = 1155
ScaleHeight = 2985
ScaleWidth = 3210
TabIndex = 0
Top = 1815
Width = 3270
Begin VB.OptionButton Option3
Caption = "Option3"
Height = 480
Left = 330
TabIndex = 3
Top = 2085
Width = 2070
End
Begin VB.OptionButton Option2
Caption = "Option2"
Height = 525
Left = 450
TabIndex = 2
Top = 1260
Width = 1590
End
Begin VB.OptionButton Option1
Caption = "Option1"
Height = 510
Left = 540
TabIndex = 1
Top = 675
Width = 1410
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Re: Event when Controls in a PictureBox get Focus
Because the underlying form code shows the option buttons in a heirarchy under their respective pictureboxes. BTW, it would be easier for us if you attached the form rather than the underlying code.
Re: Event when Controls in a PictureBox get Focus
If you are willing to use a timer then here is a way to dectect when a control in a particular picturebox gets focus.
VB Code:
Private Sub Timer1_Timer()
Static strOld As String
If Screen.ActiveControl.Container.Name <> strOld Then
Select Case Screen.ActiveControl.Container.Name
Case "Picture1"
MsgBox "A control in Picture1 has focus"
Case "Picture2"
MsgBox "A control in Picture2 has focus"
End Select
strOld = Screen.ActiveControl.Container.Name
End If
End Sub
Re: Event when Controls in a PictureBox get Focus
Thanks MartinLiss Maybe i will use this option.
Do you the OptionBox internly also uses the same mechanism?
Re: Event when Controls in a PictureBox get Focus
With an option box control when any one of them is clicked it enumerates through all others in its container and sets their value to False.
To answer your question, the easy way is to use a control array and then you can just have one event handler for each control in the array. However seeing as you have different types of controls you wouldn't be able to do that.
There is probably a way of doing it using an array of classes and an interface. If you are willing to use that sort of coding then I will see if I can knock up an example (that's if it works).