G
Guest
I am writing a multi-threaded program with a worker thread. I want the rich text box to auto scroll down as the text is added.
Here is what I want to happen:
From the worker thread:
1. Add the text to a richtextbox named txtMessageBody.
2. Make sure that the scroll is to the bottom of the box.
3. Put the focus back on the box where the user enters text
This is from a basic messenger I am writing.
The problem only occurs when trying to do this from the worker thread. Please help!
Here is a section of my code:
this.txtMessageBody.Invoke(new workerFillMessages(this.updateMessageBox),new object [] {s1});
this.txtMessage.Invoke(new workerFocusTxtMessage(this.focusTxtMessage),new object [] {});
}
}
this.tvContacts.Invoke(new workerFillContacts(this.fillContacts));
}
}
//worker thread functions
public delegate void workerFillContacts();
public delegate void workerFillMessages(string s);
public delegate void workerSwitchTabs(int i);
public delegate void workerFillMembers();
public delegate void workerFocusTxtMessage();
//the functions
public void updateMessageBox(string s)
{
this.txtMessageBody.Focus();
this.txtMessageBody.Text += s;
this.txtMessageBody.ScrollToCaret();
}
private void focusTxtMessage()
{
this.txtMessage.Focus();
}
Here is what I want to happen:
From the worker thread:
1. Add the text to a richtextbox named txtMessageBody.
2. Make sure that the scroll is to the bottom of the box.
3. Put the focus back on the box where the user enters text
This is from a basic messenger I am writing.
The problem only occurs when trying to do this from the worker thread. Please help!
Here is a section of my code:
this.txtMessageBody.Invoke(new workerFillMessages(this.updateMessageBox),new object [] {s1});
this.txtMessage.Invoke(new workerFocusTxtMessage(this.focusTxtMessage),new object [] {});
}
}
this.tvContacts.Invoke(new workerFillContacts(this.fillContacts));
}
}
//worker thread functions
public delegate void workerFillContacts();
public delegate void workerFillMessages(string s);
public delegate void workerSwitchTabs(int i);
public delegate void workerFillMembers();
public delegate void workerFocusTxtMessage();
//the functions
public void updateMessageBox(string s)
{
this.txtMessageBody.Focus();
this.txtMessageBody.Text += s;
this.txtMessageBody.ScrollToCaret();
}
private void focusTxtMessage()
{
this.txtMessage.Focus();
}