Properties of windows control objects do not change inside event handlers

K

Krupa

Hi All,

I am working on a CF 2.0 C# application for a Windows CE 5.0 device. I
am trying to change the visible and text properties of buttons and
labels from within a button click event handler. Please find the code
below.

<code>
private void button1_Click(object sender, EventArgs e)
{
button1.Visible = false;
button2.Visible = false;
Label1.Visible = true;
Label1.Text = "Setting POI 1 ...";

//Get the current location
recordCurrentLocation("1");

button1.Visible = true;
button2.Visible = true;

}

private void recordCurrentLocation(string s)
{
progressBar1.Visible = true;
progressBar1.Maximum = 6;
progressBar1.Minimum = 0;
progressBar1.Value = 0;

for (int i = 0; i < 3; i++)
{
lati = currentLocation.Latitude.Radian;
longi = currentLocation.Longitude.Radian;
progressBar1.Value += 1;
Thread.Sleep(1000);
progressBar1.Value += 1;
Thread.Sleep(1000);
}

if (progressBar1.Value == progressBar1.Maximum)
{
progressBar1.Visible = false;
label3.Visible = false;
}

}

</code>

The visible property of the buttons and label and the text property of
the text doesn't change until the function button1_Click exits.
However, it is interesting to note that the progress bar is visible
after it's value property is changed in the for loop in function
recordCurrentLocation().

This makes me think that the previous change is visible ony when there
is another change in the property of the control object. Am I right? Is
there any workaround for this?

Thanks,
Krupa
 
K

Krupa

Thanks Chris! I used Control.Update() after I changed the property and
it worked fine.

-Krupa

Call Application.DoEvents right after you change the property.

-Chris


Krupa said:
Hi All,

I am working on a CF 2.0 C# application for a Windows CE 5.0 device. I
am trying to change the visible and text properties of buttons and
labels from within a button click event handler. Please find the code
below.

<code>
private void button1_Click(object sender, EventArgs e)
{
button1.Visible = false;
button2.Visible = false;
Label1.Visible = true;
Label1.Text = "Setting POI 1 ...";

//Get the current location
recordCurrentLocation("1");

button1.Visible = true;
button2.Visible = true;

}

private void recordCurrentLocation(string s)
{
progressBar1.Visible = true;
progressBar1.Maximum = 6;
progressBar1.Minimum = 0;
progressBar1.Value = 0;

for (int i = 0; i < 3; i++)
{
lati = currentLocation.Latitude.Radian;
longi = currentLocation.Longitude.Radian;
progressBar1.Value += 1;
Thread.Sleep(1000);
progressBar1.Value += 1;
Thread.Sleep(1000);
}

if (progressBar1.Value == progressBar1.Maximum)
{
progressBar1.Visible = false;
label3.Visible = false;
}

}

</code>

The visible property of the buttons and label and the text property of
the text doesn't change until the function button1_Click exits.
However, it is interesting to note that the progress bar is visible
after it's value property is changed in the for loop in function
recordCurrentLocation().

This makes me think that the previous change is visible ony when there
is another change in the property of the control object. Am I right? Is
there any workaround for this?

Thanks,
Krupa
 

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