[C#] Weird RTB Problem

Custom Title Activated
Loyal Member
Joined
May 18, 2006
Messages
2,064
Reaction score
14
I have a problem. This worked for me all the time, but not this time I really don't know why. I tried experimenting with it and no luck.

Code:
public void AddLine(Font font, Color color, string text, bool Timestamp)
        {
            logbox.SelectionColor = color;
            logbox.SelectionFont = font;
            string timestamp = "";
            if (Timestamp)
                timestamp = "[" + DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString() + ":" + DateTime.Now.Second.ToString() + ":" + DateTime.Now.Millisecond.ToString() + "] ";
            logbox.AppendText(timestamp + text);
            logbox.SelectionColor = Color.Black;
            logbox.SelectionFont = enhance;
        }

That's my log code for a richtextbox. It works, but I can't make it work when it's called outside of a class. I even tried using static, and putting in Form1 frm = new Form1(); and replaced logbox with frm.logbox

It doesn't even append any text to the rtb. I even tried changing the rtb's modifier to public.

No error messages are produced and do anyone know why?
 
Did I delete your msn ? :p

Anyway, you have to supply more code, as in:

Full class
Class it's called from
Threading information (if any)

And define precisely what is NOT working.
 
Provide more code. What you have given is not enough to get an answer.

If you have

Code:
public class Foo
{
  private object logbox;

  // Some code here (logbox can't be null when AddLine is called)

  public void AddLine(Font font, Color color, string text, bool Timestamp)
  {
    // Some code here that uses logbox
  }
}
Then you should be able to call
Code:
Foo foo = new Foo( ... );
foo.AddLine(somefont, somecolor, "Some Text", true);
And it should do something.

Make sure you are not swallowing up any exceptions thrown with an empty catch block.
 
Back