By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,089 Members | 1,361 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,089 IT Pros & Developers. It's quick & easy.

Controls created on one thread cannot be parented to a control on a different thread

P: 17
Hello Guys,
I am trying to mark locations on a map (x,y pixels are derived from a DB)
This is the code that i am using

Expand|Select|Wrap|Line Numbers
  1. Private Sub DisplayOnSoftMap()
  2. SqlQuey = "Select * FROM SoftwareMap WHERE SoftwareMap.SMSID =myRndTrip.CurrentSwitch.SID & "'"
  3. tmpSoftMapCol = tmpSoftMapCol.GetAllSoftwareMap(SqlQuey)
  4. For Each tmpSoftMap In tmpSoftMapCol
  6. DrowLabel(tmpSoftMap.XMap, tmpSoftMap.YMap, tmpSoftMap.LablName)
  8. next
  10. Private Sub DrowLabel(ByVal X As Long, ByVal Y As Long, ByVal lblText As String)
  12. Dim LIndex, Lcount As Integer
  13. Try
  14. If Lbl Is Nothing Then
  15. ReDim Preserve Lbl(0)
  16. Lcount = 1
  17. LIndex = 0
  18. Else
  19. Lcount = Lbl.Length
  20. ReDim Preserve Lbl(Lcount)
  21. LIndex = Lcount
  22. End If
  23. Lbl(LIndex) = New LinkLabel
  24. Control.CheckForIllegalCrossThreadCalls = False
  25. Lbl(LIndex).Location = New System.Drawing.Point(X, Y)
  26. Lbl(LIndex).Text = lblText
  28. Lbl(LIndex).Visible = True
  29. Lbl(LIndex).AutoSize = True
  30. Control.CheckForIllegalCrossThreadCalls = False
  31. Me.Controls.Add(Lbl(LIndex))
  32. AddHandler Lbl(LIndex).Click, AddressOf Label_Click
  33. Catch ex As Exception
  34. Throw ex
  35. End Try
  36. End Sub
And this is the Error that Occurs

System.ArgumentException was caught
Message="Controls created on one thread cannot be parented to a control on a different thread."
at System.Windows.Forms.Control.ControlCollection.Add (Control value)
at System.Windows.Forms.Form.ControlCollection.Add(Co ntrol value)
at RoundTrip.frmRoundTrip.DrowLabel(Int64 X, Int64 Y, String lblText)


The purpose of this code is to mark locations on a map,
I would be glad: if you help me finding the solution or any other solution which fits my needs

Feb 17 '07 #1
Share this Question
Share on Google+
1 Reply

Post your reply

Sign in to post your reply or Sign up for a free account.