|
ms
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Easy(?) one about Label.TextI have a Label on a Windows form (Version 1.1.4322) and while I iterate recursively through a method I want to show the name of the current file being copied to another directory. The Label is not visible until the backup begins, at which point I resize the form to show the Label and a ProgressBar. As each file is copied, the Label is updated: foreach(FileInfo file in dir.GetFiles()) { file.CopyTo(fullpath + "\\" + file.Name); lblFileName.Text = "Copying file " + file.FullName; } There is other code in this loop but not relevant (increment the progressbar, decrement a counter for the remaining files, things like that). The problem I have is that nothing appears in the Label. I set the Label's Visible property to false in the Load event handler, and only set it to true after I have resized the form during the backup. Once the backup is complete, I set visible to false again and reset the form to it's original size. I even tried setting it to false in the designer and put some dummy text in to see what it showed. The dummy text didn't appear. The text appeared when I set visible to true in the designer, but it didn't change. Stepping through the code, the Label is definitely showing as visible and the text reflects the current file name, but it refuses to show this on the form. Does anyone have any ideas? On Fri, 06 Apr 2007 10:18:02 -0700, cashdeskmac
<cashdesk***@discussions.microsoft.com> wrote: > I have a Label on a Windows form (Version 1.1.4322) and while I iterate I get the impression that the code doing the work is in the main form's > recursively through a method I want to show the name of the current file > being copied to another directory. > > [...] > The problem I have is that nothing appears in the Label. > > [...] > Stepping through the code, the Label is definitely showing as visible and > the text reflects the current file name, but it refuses to show this on > the form. > > Does anyone have any ideas? thread. If that's true, then you aren't getting to a point where the label is able to redraw itself. Typically, when a control's visual status changes, this is handled by adding a message to the control's message queue telling it to redraw itself. Until the control has a chance to process its messages, it won't redraw. You can address this either by moving the processing into a different thread, which will allow the control's thread to continue to process messages, or you can use the Refresh() method to force the control to redraw after you change the data. IMHO, the former is preferable, but it's also a little more complicated (though not by much...the worst part is that you'll want to look at BeginInvoke for actually changing the label's Text property from the processing thread). In your particular scenario, copying files, I think that using Refresh() is fine. It's hard to imagine a scenario where the disk i/o isn't significantly slower than the video i/o required to update the label. But for other tasks, the overhead updating the label for each iteration could wind up becoming a major component of the total processing and so you wouldn't want to refresh the label each time through the loop. Pete
Convert hex to double in 2.0?
any preformance tips ? Merge word applications Can I abandon the lock on .SyncRoot and lock a collection directly? Less available memory in 2.0? Global Assembly Cache How do I create an xml file and execute in c#... How to create 2 dimensional dynamic array (vb.net or c#) int is out of scope??? how to set the carret to the end of a text box (or automatic scroll) Interfaces |
|||||||||||||||||||||||