jcrcarmo Posted December 14, 2005 Posted December 14, 2005 Hi everybody, Greetings from Brazil. I'm new to C# and would really appreciate it if anyone could please help me translate the VB2005 code below to C#. The following code locks all TextBox and MaskedTextBox controls on a form. Thanks in advance. Best regards, JC :) Public Sub LockForm() On Error Resume Next Dim ctl As Control For Each ctl In Me.Controls If CType(ctl, TextBox).ReadOnly = False And CType(ctl, MaskedTextBox).ReadOnly = False Then CType(ctl, TextBox).ReadOnly = True CType(ctl, TextBox).BackColor = Color.White CType(ctl, MaskedTextBox).ReadOnly = True CType(ctl, MaskedTextBox).BackColor = Color.White End If Next End Sub Quote
Cags Posted December 14, 2005 Posted December 14, 2005 private void LockForm() { foreach(Control ctrlTemp in this.Controls) { if(ctrlTemp is TextBox) { TextBox txtTemp = (TextBox)ctrlTemp; txtTemp.ReadOnly = true; txtTemp.BackColor = Color.White; } /*// handle other types else if(ctrlTemp is CheckBox) { CheckBox chkTemp = (CheckBox)ctrlTemp; // etc... } */ } } Quote Anybody looking for a graduate programmer (Midlands, England)?
jcrcarmo Posted December 15, 2005 Author Posted December 15, 2005 Locking all Controls on a Form - Solved! Your code works really well. Thanks for replying so quickly. JC :) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.