Link to home
Start Free TrialLog in
Avatar of dwe0608
dwe0608Flag for Australia

asked on

URGENT: Textboxes on a Picture Box

Hi All,

If I have 10 textboxes on a form as well as two pictureboxes

3 are located in  picturebox1, 3 are located in picturebox2

4 are outside of the pictureboxes and are just on the form

How can I enable and disable the textboxes inside picturebox1 using a for ... next loop ?

MTIA

Darrin
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Hi dwe0608,

Private Sub Command1_Click()
    EnableDisableTextboxes False, Picture1
End Sub

Private Sub EnableDisableTextboxes(ByVal Status As Boolean, ByRef ContainedIn As PictureBox)
    Dim txt As Control
    For Each txt In Me.Controls
        If txt.Container Is ContainedIn Then txt.Enabled = False
    Next
End Sub

For example, just call as EnableDisableTextBoxes True,Picture1  to enable and ... False,Picture1 to disable

For example

Tim Cottee
Avatar of dwe0608

ASKER

And if I wanted to enable all textboxes - the following code marked by  ?? would be helpful

Private Sub EnableDisableTextboxes(ByVal Status As Boolean, optional ByRef ContainedIn As PictureBox = nothing)
    Dim txt As Control
    For Each txt In Me.Controls
       if not Ismissing(ContainedIn) and ?? not containedin is nothing ?? then
           If txt.Container Is ContainedIn Then txt.Enabled = False
       else
           txt.Enabled = False
       end if
    Next
End Sub


MTIA

Darrin
Tim already give you the solution, the only thing he should use status to set the enabled flag

ie.


Private Sub EnableDisableTextboxes(ByVal Status As Boolean, Optional ByRef ContainedIn As PictureBox = Nothing)
    Dim txt As Control
    For Each txt In Me.Controls
       If Not IsMissing(ContainedIn) And Not ContainedIn Is Nothing Then
           If txt.Container Is ContainedIn Then txt.Enabled = Status
       End If
    Next
End Sub
ASKER CERTIFIED SOLUTION
Avatar of Dany Balian
Dany Balian
Flag of Lebanon image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial