Simpel TextBox Question

Z

Zach Maslin

I am a little embarrassed to have to ask this question
but the fact of the matter is that I need to solve it.
I need to display messages on a display a couple
of seconds apart. I wanted to separate them with
sleep(). I came up against the problem that a text
box will not display strings subsequently as in the
sample code below.


MessageBox.Show("1");
textBox1.Text = "Enee";



MessageBox.Show("2");
textBox1.text = "Manee";


MessageBox.Show("3");
textBox1.Text = "Moo";


The text box will only show
Moo. What is the way around this?


Zach.
 
J

Jeff Gaines

The text box will only show Moo. What is the way around this?

try:
textBox1.Refresh();
after you change the text.
You will need some sort of delay loop between the text changes.
 
Z

Zach Maslin

----- Original Message -----
From: "Peter Duniho" <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.csharp
Sent: Thursday, June 16, 2011 3:58 AM
Subject: Re: Simpel TextBox Question

You need to separate your updates so that the message pump gets to run
between updates. Calling the Refresh() method is a hack, solving only
your update problem, but not the host of other issues that come up when
you block the message pump.
Pete,
Thank you for your help. It enabled me to solve the
problem.
Zach.

I did it like so. Hope you approve:

Timer timer = new Timer();
timer.Tick += new EventHandler(Show);
timer.Interval = (10000) ;
timer.Enabled = true;
timer.Start();
}

void Show(object sender, EventArgs e)
{
textBox1.Text = messages[counter++].ToString();
}
 
Z

Zach Maslin

Jeff Gaines said:
try:
textBox1.Refresh();
after you change the text.
You will need some sort of delay loop between the text changes.

Hi,

Thanks, but it didn't do the trick.
Please refer to my post in response to Pete's.

Zach.
 
Z

Zach Maslin

----- Original Message -----
From: "Peter Duniho" <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.csharp
Sent: Thursday, June 16, 2011 4:19 PM
Subject: Re: Simpel TextBox Question

[...]
I did it like so. Hope you approve:

Not that you should need my approval, but since you asked…
Timer timer = new Timer();
timer.Tick += new EventHandler(Show);

This can be "timer.Tick += Show;"

Simpler syntax, same effect.
timer.Interval = (10000) ;
timer.Enabled = true;
timer.Start();

Setting "Enabled" and calling "Start()" is redundant. Do one or the
other, not both.
void Show(object sender, EventArgs e)
{
textBox1.Text = messages[counter++].ToString();

What type is "messages"? It seems odd that something named "messages"
would require you do call ToString() on the elements, since one would
expect the elements to be string instances already.

You did not show any code to disable the timer or otherwise ensure that
you do not index beyond the bounds of the "messages" object. If you have
such code, then that should be fine. If not, you need to fix it.

Pete

Pete,
messages is an ArrayList
number is the limit ex file
I am showing the messages at random
I have removed the double code

Thank you for uour help,
Zach

Timer timer = new Timer();
timer.Tick += Show;

timer.Interval = (10000) ;
timer.Start();
}

void Show(object sender, EventArgs e)
{
Random random = new Random();
int arg = random.Next(Convert.ToInt16(number));
textBox1.Text = messages[arg].ToString();
}
 
Z

Zach Maslin

Jeff Johnson said:
Dump ArrayLists; they're yesterday's technology. Look into generic Lists
instead.
Yes, I am aware of generic Lists. I have used them.
OK I'll consider dropping ArrayLists. Thank you for
your alert.

Zach
 

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