i have a main form with a thread running in that where i receive continous text which i need to update the text in a text box on the child form.(already open).
tnx for any help regarding this..
i tried all with the delegates and passing the value through constructor the text is not visible in the textbox
Loading
paramesh medaPosted Dec 15, 2006, 12:05 AM
tnx for u response, the actual problem here is im opening a new win form on a running thread( ReceiveChat which is a thread)
void ReceiveChat()as i was opening a win form it is opening in a non responsive mode ..
private
{
bool keepalive = true; while (keepalive){
try{
Byte[] buffer = new Byte[2048];ns.Read(buffer, 0, buffer.Length);
string chatter = System.Text.Encoding.ASCII.GetString(buffer); string[] tokens = chatter.Split(new Char[] { '|' }); if (tokens[0] == "CHAT"){
voidupdateTB(tokens[1]);
//richTextBox1.BeginInvoke(delegate {richTextBox1.Text = tokens[1]; }); //this.richtextBox1.AppendText( tokens[1]); if (logging)logwriter.WriteLine(tokens[1]);
}
if (tokens[0] == "PRIV"){
//frmprivate pp = new frmprivate(); //pp.Show(); //this.backgroundWorker1.RunWorkerAsync();here is where i need to open a window form frmprivate
frmprivate pp = new frmprivate(tokens[1].Trim() + tokens[2] + "\r\n");
// MethodInvoker mi=new MethodInvoker(opennewwindow); // mi.BeginInvoke(null, null); //voidupdatepritb(); // pp.txtMessages.Text += tokens[1].Trim() + tokens[2] + "\r\n"; // pp.Show(this); //pp.txtMessages.Text = tokens[1].Trim() + tokens[2] + "\r\n"; // pp.updatetextbox(tokens[1].Trim() + tokens[2] + "\r\n"); }catch (Exception e)
{
Console.WriteLine(e.Message.ToString());}
}
}
public frmprivate(string st)Constructor of the frmprivate
where i am assigning the text to show in the text box, But the form which is opening in a non-responsive mode may be this is becoz of the thread still in running mode
how i could make the window open in responsive mode.And assign the text which i receive on running thread..
{
InitializeComponent();
frmprivate pp = new frmprivate();pp.txtMessages.Text = st;
pp.Show();
// string newValue = st; // ValueUpdatedEventArgs valueArgs = new ValueUpdatedEventArgs(newValue); // this.txtMessages.Text = valueArgs.NewValue; //ValueUpdated(this, valueArgs); //txtMessages.Text = st;}
tnx
paramesh
MartinPosted Dec 14, 2006, 12:54 PM
But to answer your question, I usually make the child form an object within the class declaration instead of declaring it locally within a method, causing you to not be able to call it outside the method. If you decide to not declare it locally within your method, make an event on formClosing with:
e.Cancel = true;
this.Hide();
paramesh medaPosted Dec 11, 2006, 5:26 AM
im new to network programming ..
this is about a chat application , where i have 2 forms one is main form where i receive the text from the server through asyn call by a method name receivechat..
receive chat is an thread
private void ReceiveChat()
{
bool keepalive = true; while (keepalive){
try{
Byte[] buffer = new Byte[2048];ns.Read(buffer, 0, buffer.Length);
string chatter = System.Text.Encoding.ASCII.GetString(buffer); string[] tokens = chatter.Split(new Char[] { '|' }); if (tokens[0] == "CHAT"){
voidupdateTB(tokens[1]); // the text which iam receiving here is successfully assigned to textbox
//richTextBox1.BeginInvoke(delegate {richTextBox1.Text = tokens[1]; }); //this.richtextBox1.AppendText( tokens[1]); if (logging)through the delegate called on the textbox control by invoke method.the textbox is in the same form
logwriter.WriteLine(tokens[1]);
}
if (tokens[0] == "PRIV"){
frmprivate pp = new frmprivate();voidupdatepritb(tokens[1].Trim() + tokens[2] +
"\r\n");//how can i assign the text to the text box which is in another form of name frmprivate .
well i receive an error object reference is set any instance every time
//pp.txtMessages.Text = tokens[1].Trim() + tokens[2] + "\r\n"; // pp.updatetextbox(tokens[1].Trim() + tokens[2] + "\r\n"); if (logging){
logwriter.Write(
"Private from ");logwriter.Write(tokens[1].Trim());
logwriter.WriteLine(tokens[2] +
"\r\n");}
}
private delegate void UpdateTestbox(string msg);void voidupdatepritb(string st1)
{
UpdateTestbox1 ulb1 = new UpdateTestbox1(this.OnUpdate); // here is the textbox where i need to update the text which i receive therepp.txtMessages.Invoke(ulb1,
new object[] { st1 }); /// error}
private void OnUpdate(string msg){
pp.txtMessages .Text += msg;
}
void voidupdateTB(string st){
UpdateTestbox ulb = new UpdateTestbox(this.OnUpdate1);richTextBox1.Invoke(ulb,
new object[] { st });}
private void OnUpdate1(string msg){
richTextBox1.Text += msg;
}
thnx
paramesh
Mahesh ChandPosted Dec 10, 2006, 12:43 PM