Results 1 to 3 of 3

Thread: Creating, storing and managing forms dynamically

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2009
    Posts
    19

    Creating, storing and managing forms dynamically

    Hi, I'm making a LAN instant messenger and I'm trying to achieve something similar to how MSN will open a new chatting window when you double click on a friend. My main form has a list of friends, and I want to create a new chat window when they double click on one of those friends. I've created a "template" chat form which I want to generate dynamically, and I've run into some problems I need help with. Lets look at the code I already have.

    The sub for double clicking on the friend listbox:
    Code:
        Private Sub lbFriends_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbFriends.DoubleClick
           Dim fd() As String = Split(My.Settings.Friends.Item(lbFriends.SelectedIndex), "|"c)
            If lbFriends.SelectedIndex >= 0 Then
                If IsInClientList(fd(0)) = False Then
                    Me.Invoke(New del(AddressOf OpenNewChat))
                End If
                'Connection code
            End If
        End Sub
    The sub for creating a new chat window, adding it to a list, and showing it:
    Code:
        Private Sub OpenNewChat()
            Dim NewChatWind As New ClientWind
            CWL.Add(ClientWind)
            CWL.Item(CWL.Count - 1).Show()
        End Sub
    And outside of those subs I have this:
    Code:
        Private Delegate Sub del()
        Dim CWL As New List(Of ClientWind)
    The form will only appear once as far as I can tell, and the chat form has events such as button clicks; an error occurs when I try to change something like the text property of a label for example (eg. clicking a button on the chat form changes the text of a label on the chat form will cause an error to occur). The error I actually get is:

    Cross-thread operation not valid: Control 'ClientWind' accessed from a thread other than the thread it was created on.
    Now, call me a newb if you will, but I really don't know much about threading and all that hocus pocus. Some guidance in the right direction would be great.

    EDIT: ClientWind is the chat form.
    EDIT: That's weird. It doesn't occur with the actual builds.
    Last edited by PSYCHONAUT; Jan 20th, 2011 at 03:56 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width