Question Panel Focus

Mica77

Member
Joined
Jan 14, 2009
Messages
5
Programming Experience
1-3
Hi, I have 2 problems I am having trouble getting around.

1. I am running an sql with a large amount of records
for each record im writing to a label and doing a label refresh so that
the results are streaming into my page. The label is located inside a panel.

as the label grows and the scrollbars become active I want the scrollbar to always keep the focus at the bottom of the Panel.

2. While the script is running the application will lock up if the user tries to close or open up another tab panel page.
How do I handle this? Can my script be run in a background worker or can i pause the sqlscript temporarily?

Thankyou for any assistance

Michael
 
1. There's no easy way to do that that I'm aware of. If you use a ReadOnly TextBox instead of a Label in a Panel then you can add the text by calling AppendText and it will scroll down by itself.

2. You can do certain processing in secondary threads but any updates to the UI must be done in the main thread. We'd have to see what you're currently doing to know the best way to achieve the same result in multiple threads.
 
Re : Threads

Hi, Thankyou for the reply... that worked perfectly for the Textbox.

Here is a cut back of a scenerio I would like to work in that background worker or at least get some recommendation on what approach should be taken.

It is actually a data reader that I am using but the below with the Sleep Latency will give indication of the process time.

textbox1 is inside a panel in a usercontrol.
button1 is pressed and calls the below

For I as Integer = 1 to 5000
System.Threading.Thread.Sleep(100)
do something eg) Textbox1.AppendText("Hello")
Textbox1.Refresh()
Next

I have a few usercontrols inside TabPages in a TabControl on Form1

While this process is running my user may open another tab page but at the moment nothing can be done until this process is finished. How can I make this process run on another thread but still post back to the textbox if that is what you meant by communicating with the ui and still allow the user to open another tabpage

Thanks Again
Michael
 
One option is to do your work in the DoWork event handler of a BackgroundWorker. You can then call ReportProgress when you have some data that needs to be displayed in the UI. You might like to read this for a start.
 
Back
Top