473,769 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Easy(?) one about Label.Text

Hi,

I 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(FileInf o file in dir.GetFiles())
{
file.CopyTo(ful lpath + "\\" + file.Name);
lblFileName.Tex t = "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?

Apr 6 '07 #1
2 2602
On Fri, 06 Apr 2007 10:18:02 -0700, cashdeskmac
<ca*********@di scussions.micro soft.comwrote:
I 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 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?
I get the impression that the code doing the work is in the main form's
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
Apr 6 '07 #2
Many thanks Peter,

refresh did the trick.
Apr 6 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3655
by: Tim Mulholland | last post by:
I'm writing an app in C# that requires labels to scale as the size of the window grows/shrinks. Getting the actual label itself to scale is very easy using the anchor property. But i need to get the text inside the label to change fontsize based on the size of the label. I know it is possible (with the autosize property) to have the label take the size of the text, but is it possible to make the text "fill" the label? Any suggestions?
6
6935
by: Joe | last post by:
I know that the Literal control will not render a <span> tag so I can not format its text. Other than this, what is the difference betwen the Literal control and the LiteralControl Control? How about a LiteralControl and a Label? Other than the lack of being able to format the Literal control's text, I don't see much of a difference in the documentation. TIA, --
1
1337
by: Antonio Policelli | last post by:
hi, i have a datareader returning a 2 column recordset with multiple rows what i want to display in a textbox. here is my code. only the last line shows up in the text box but all gets written to the console, so i know they are there. I have tried controlchars.crlf, chr(13), vbcrlf, none worked. what did i do wrong? it is definitely a multiline text box because at runtime i can type in multiple lines.. Do While drReader.Read...
1
1493
by: mouac01 | last post by:
How do I get a label to be on top of a text field? <label>Login:<input type="text" name="login"></label> <label>Password:<input type="password" name="password"></label> generates this... Login:textbox Password:textbox I want...
1
1809
by: Groove | last post by:
I have a typical Repeater that contains a Template (html table). The repeater / template lists many records and in the footer, I'd like to simply SUM up the $$ amounts from all the records in the repeater. Easy enough. So I tried to place a Label control in the footer and fill the Text of the label from code. I get the label is not declared error. So how can I go about doing this? I tried writing a helper function in the code-behind...
3
1411
by: Dominique | last post by:
Hello, I tried: <aw:HyperLink runat="server" id="hlQueuedCount" labelposition="top" labelwidth="30" command="runQuery" /> as if I use the parameter width it just affect the result of the query displayed by hlQueuedCount I wanted to try on the Label itself... with a parameter labelwidth but it does not seems to do anything... Any idea what will be the parameter for the hyperlink label which is
12
13274
by: vbnewbie | last post by:
I am having problems accessing properties of dynamically generated objects in VB2005. Can someone please help? In a nutshell: My app creates an equal number of checkboxes and labels that share the same Tag number. (I thought it might help) The checkboxes name is a concatenation of "chkCancel" and a number that represents the order in which they were created: chkCancel0 (Tag = 0) chkCancel1 (Tag = 1)
4
2040
by: stevewy | last post by:
If I am using srcElement (or "target" for non-IE models) to return various properties of an object I have clicked on, can I access for "label for" value in any way? I'm thinking, for example, of an input text box like this: <label for="fred">Username:</label> <input type="text" name="hello" id="hello1" size="10"> Now, once a function has:
8
1610
by: Allen Maki | last post by:
I wonder if you could help. The event handler code below, will allow the user to change the phone number and write it on a label of a message box. I want to replace the message box with a dialog box. Can anybody help me replace the message box below to a dialog box. In other words. I want to write the new phone number on a label (named "labe1")of a dialog box (named "dialog2),instead of writing the new phone number on the label of a...
0
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9422
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10035
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8863
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7403
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5293
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.