Button.Text has no effect?
-
Hi I'm struggling with a strange problem here, I can't set the text of a button in some circumstances. Here's my code:
private void btnGo_Click(object sender, EventArgs e)
{
try
{
btnGo.Text = "Processing..."; // this one doesn't work// blocking operation that might fail
}
catch (...)
finally
{
btnGo.Text = "Start"; // this one works
}
}If I remove btnGo.Text = "Start", then the text "Processing" shows up once the long operation has finished. /edit: I solved it by calling btnGo.Refresh() after btnGo.Text. But why is this necessary, will the button repaint itself only after another Paint-Event occured? Does anyone know what might be causing this strange behaviour? regards
-
Hi I'm struggling with a strange problem here, I can't set the text of a button in some circumstances. Here's my code:
private void btnGo_Click(object sender, EventArgs e)
{
try
{
btnGo.Text = "Processing..."; // this one doesn't work// blocking operation that might fail
}
catch (...)
finally
{
btnGo.Text = "Start"; // this one works
}
}If I remove btnGo.Text = "Start", then the text "Processing" shows up once the long operation has finished. /edit: I solved it by calling btnGo.Refresh() after btnGo.Text. But why is this necessary, will the button repaint itself only after another Paint-Event occured? Does anyone know what might be causing this strange behaviour? regards
You need to use Asynchronous process using threads
Thanks and Regards Sandeep If you want something you never had, do something you have never done!
-
Hi I'm struggling with a strange problem here, I can't set the text of a button in some circumstances. Here's my code:
private void btnGo_Click(object sender, EventArgs e)
{
try
{
btnGo.Text = "Processing..."; // this one doesn't work// blocking operation that might fail
}
catch (...)
finally
{
btnGo.Text = "Start"; // this one works
}
}If I remove btnGo.Text = "Start", then the text "Processing" shows up once the long operation has finished. /edit: I solved it by calling btnGo.Refresh() after btnGo.Text. But why is this necessary, will the button repaint itself only after another Paint-Event occured? Does anyone know what might be causing this strange behaviour? regards
Immediately after settings the button text, just call
Application.DoEvents()
, so your application gets and processes the message to repaint itself.Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
Immediately after settings the button text, just call
Application.DoEvents()
, so your application gets and processes the message to repaint itself.Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007There are many ways to do it if any one want to make user wait untill the process completes he can use asyncronous process as back ground thread . There are n number of articles available on CP . i know it is very tidious but more effective than Application.DoEvents()
Thanks and Regards Sandeep If you want something you never had, do something you have never done!
-
There are many ways to do it if any one want to make user wait untill the process completes he can use asyncronous process as back ground thread . There are n number of articles available on CP . i know it is very tidious but more effective than Application.DoEvents()
Thanks and Regards Sandeep If you want something you never had, do something you have never done!
There are also some people who are not ready to start throwing threads around. There are also situations where threading a process isn't acceptable, or would be too much work to keep the user from waiting for 1 or 2 seconds on a simpler process. He really didn't give any kind of information about what this process was doing. So, to keep his code simple, DoEvents is a very easy fix to the immediate problem. If he wanted to move this process to a background thread, he can ask about that all he wants and we'll help with it.
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
There are also some people who are not ready to start throwing threads around. There are also situations where threading a process isn't acceptable, or would be too much work to keep the user from waiting for 1 or 2 seconds on a simpler process. He really didn't give any kind of information about what this process was doing. So, to keep his code simple, DoEvents is a very easy fix to the immediate problem. If he wanted to move this process to a background thread, he can ask about that all he wants and we'll help with it.
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007I'm absolutely familiar with Threads and right after I posted this question I found the solution myself :) I may switch my app to use threads in the future, but it's just a simple app for myself which querys a small database and displays some data, so
button.Refresh()
will do the job here. regards -
Hi I'm struggling with a strange problem here, I can't set the text of a button in some circumstances. Here's my code:
private void btnGo_Click(object sender, EventArgs e)
{
try
{
btnGo.Text = "Processing..."; // this one doesn't work// blocking operation that might fail
}
catch (...)
finally
{
btnGo.Text = "Start"; // this one works
}
}If I remove btnGo.Text = "Start", then the text "Processing" shows up once the long operation has finished. /edit: I solved it by calling btnGo.Refresh() after btnGo.Text. But why is this necessary, will the button repaint itself only after another Paint-Event occured? Does anyone know what might be causing this strange behaviour? regards
May be the process is too fast, so the processing happens in less than second, and the finally line anyway will make it = "Start".
-
I'm absolutely familiar with Threads and right after I posted this question I found the solution myself :) I may switch my app to use threads in the future, but it's just a simple app for myself which querys a small database and displays some data, so
button.Refresh()
will do the job here. regardsGreeeg wrote:
I'm absolutely familiar with Threads and right after I posted this question I found the solution myself
Great!
Greeeg wrote:
it's just a simple app for myself which querys a small database and displays some data,
Hence, the "simple" suggestion. :laugh:
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
Hi I'm struggling with a strange problem here, I can't set the text of a button in some circumstances. Here's my code:
private void btnGo_Click(object sender, EventArgs e)
{
try
{
btnGo.Text = "Processing..."; // this one doesn't work// blocking operation that might fail
}
catch (...)
finally
{
btnGo.Text = "Start"; // this one works
}
}If I remove btnGo.Text = "Start", then the text "Processing" shows up once the long operation has finished. /edit: I solved it by calling btnGo.Refresh() after btnGo.Text. But why is this necessary, will the button repaint itself only after another Paint-Event occured? Does anyone know what might be causing this strange behaviour? regards
This is not a strange behavior, your should start a new thread to do the time consuming work and on the finish event of the tread set the btnGo.Text = "Start".