Newbie asks: How to append to TextBox?

G

Guest

I'm new to CF and Microsoft programming in general -- been doing java.

I'm porting a simple console-based output-only program to the Pocket PC.
There is no console available for me to output text to, it seems
(System.out in java-talk).

So I'm using a TextBox as my output "console" and have created a
TextWriter that writes to it (see below). The problem is that the
display is slower and flickery. I suspect that's because I'm appending
to the Text propert whenever a new line of info is printed. Is there
some other way to append text to the end of a TextBox but avoid that
flicker?

Thanks!


class TextBoxWriter: System.IO.TextWriter
{
private TextBox box;

// Constructor
public TextBoxWriter(TextBox textBox)
{
box = textBox;
}

// Implement Encoding() method from TextWriter
public override Encoding Encoding
{
get
{
return(Encoding.Unicode);
}
}

public override string NewLine
{
get
{
return "\r\n";
}
}

public override void Write(string message)
{
box.Text += message;
}

public override void WriteLine(string message)
{
box.Text += message + NewLine;
}
}
 
J

Jon Skeet [C# MVP]

@ *SPAM* yahoo_com <"@ *SPAM* yahoo_com" <""jlindwall*NO*\"@ *SPAM*
yahoo_com"> said:
I'm new to CF and Microsoft programming in general -- been doing java.

I'm porting a simple console-based output-only program to the Pocket PC.
There is no console available for me to output text to, it seems
(System.out in java-talk).

Actually, there are ways round that. You can get a console for PPC, and
write to it from the CF. I can't remember offhand where I got them from
though...
So I'm using a TextBox as my output "console" and have created a
TextWriter that writes to it (see below). The problem is that the
display is slower and flickery. I suspect that's because I'm appending
to the Text propert whenever a new line of info is printed. Is there
some other way to append text to the end of a TextBox but avoid that
flicker?

You might want to consider only updating the text box on a call to
Flush(), keeping a StringBuilder for your current state. You might also
want to trim it to only have a certain buffer size, so that stuff
effectively scrolls off after a while.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top