Lock Text Boxes (VB 2005)

I have a set of text boxes on a form that I want to be able to lock/unlock at well (ie. user cannot edit text unless permitted).
In VB6 I would simply set the Locked property to True and be done.
In VB 2005, the Locked property is for design time only, and prevents controls from being moved accidentally during form design. Then I found the ReadOnly property and thought it should work.
Here's what I've tried to lock the TextBoxes, but it's not working:

    Private Sub LockFields(ByVal Lock As Boolean)
        For Each ctrl As Control In Me.Controls
            If TypeOf ctrl Is TextBox Then
                ctrl.ReadOnly = True
            End If
        Next
    End Sub

It fails with this error in the Error List.
'readonly' is not a member of 'System.Windows.Forms.Control'.
bhlangAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Carl TawnSystems and Integration DeveloperCommented:
Thats because ctrl is type Control rather than TextBox, so you need to cast it first:

        For Each ctrl As Control In Me.Controls
            If TypeOf ctrl Is TextBox Then
                CType(ctrl, TextBox).ReadOnly = True
            End If
        Next

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bhlangAuthor Commented:
Thanks. Knew it was something simple, but couldn't figure out what.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.