troubleshooting Question

Delegate Class

Avatar of scprogs
scprogsFlag for United States of America asked on
Visual Basic.NET
2 Comments1 Solution287 ViewsLast Modified:
I'm trying to build a delegate class that will avoid cross threading operations.  This class should be able to take most common controls and make changes to them that would result in cross threading errors.  This is the code I have so far.
Public Class Removed_Items

	Private Delegate Sub delChangeControl(ByVal ctrl As Control, ByVal prop As String, ByVal Value As String)

	Dim chk As CheckBox
	Dim txt As TextBox
	Dim rad As RadioButton

	Private Sub ChangeControl(ByVal ctrl As Control, ByVal prop As String, ByVal Value As String)
		If Me.InvokeRequired Then
			Me.Invoke(New delChangeControl(AddressOf ChangeControl), ctrl, prop, Value)
			Exit Sub
		End If

		If TypeOf (ctrl) Is CheckBox Then
			chk = ctrl
			chkBox(prop, Value)
		ElseIf TypeOf (ctrl) Is TextBox Then
			txt = ctrl
			txtBox(prop, Value)
		ElseIf TypeOf (ctrl) Is RadioButton Then
			rad = ctrl
			radButton(prop, Value)
		End If
	End Sub

	Private Sub chkBox(ByVal prop As String, ByVal value As String)
		Select Case prop
			Case "Text"
				chk.Text = value
			Case "Checked"
				chk.Checked = value
			Case "Tag"
				chk.Tag = value
		End Select
	End Sub

	Private Sub txtBox(ByVal prop As String, ByVal value As String)
		Select Case prop
			Case "Text"
				txt.Text = value
			Case "Left"
				txt.Left = value
			Case "Tag"
				txt.Tag = value
		End Select
	End Sub

	Private Sub radButton(ByVal prop As String, ByVal value As String)
		Select Case prop
			Case "Text"
				rad.Text = value
			Case "Checked"
				rad.Checked = value
			Case "Tag"
				rad.Tag = value
		End Select
	End Sub
End Class
I would like to avoid writing a case for each property in a control if possible, would there be an easier way to do this?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros