Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted
		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...	
			}
			*/		
		}
	}

Anybody looking for a graduate programmer (Midlands, England)?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...