473,795 Members | 2,812 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Label text display

How come when I put the label text setting here:

/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run (new Form1());
}
private void LoadInfo()
{
label1.Text = DateTime.Now.To String();
}

The form comes up but no text is displayed?

If I put the label text setting here:

namespace Viewer1
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows. Forms.Form
{
private System.Windows. Forms.Label label1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();
label1.Text = DateTime.Now.To String();

Then it works fine.

What do I need to learn?

Bill

Nov 17 '05 #1
8 2485
"BillZondlo " <Bi********@dis cussions.micros oft.com> wrote in message
news:47******** *************** ***********@mic rosoft.com...
If I put the label text setting here:
InitializeCompo nent();
label1.Text = DateTime.Now.To String();

Then it works fine.

What do I need to learn?


Hi. If you open up the region that VS.NET creates for you called "Windows
Form Designer generated code", then you will see all of the initialization
of the controls that needs to take place BEFORE your loading of the text.
InitializeCompo nent() in your Form contstructor will do this needed
initialization. You need to do your own property setting of the controls
AFTER InitializeCompo nent().

-- Alan
Nov 17 '05 #2
Hi,
I recommend you two places where to put your controls customizations:

1- Right after the InitializateCom ponent () call in the constructor
2- the Form_Load event.

DO NOT MODIFY THE InitializateCom ponent () method, never touch it.

Pd:
In your first example when you call LoadInfo() ?

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"BillZondlo " <Bi********@dis cussions.micros oft.com> wrote in message
news:47******** *************** ***********@mic rosoft.com...
How come when I put the label text setting here:

/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run (new Form1());
}
private void LoadInfo()
{
label1.Text = DateTime.Now.To String();
}

The form comes up but no text is displayed?

If I put the label text setting here:

namespace Viewer1
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows. Forms.Form
{
private System.Windows. Forms.Label label1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();
label1.Text = DateTime.Now.To String();

Then it works fine.

What do I need to learn?

Bill

Nov 17 '05 #3
I understand what you say. I thought the same.
But, in an earlier program that I wrote, I have set labels to text values
right after the MAIN () {Application.Ru n(new form1())}

i.e.

[STAThread]
static void Main(string[] args)
{
Application.Run (new Form1());
}
private string folderName1, fileName1 ;

public void button1_Click(o bject sender, System.EventArg s e) //open folder
selection.
{
DialogResult result = folderBrowserDi alog1.ShowDialo g();
if(result == DialogResult.OK ) //folder selected
{
folderName1 = folderBrowserDi alog1.SelectedP ath;
label1.Text = folderName1 ;

Or is this different in some way?

TIA

Bill

"Alan Pretre" wrote:
"BillZondlo " <Bi********@dis cussions.micros oft.com> wrote in message
news:47******** *************** ***********@mic rosoft.com...
If I put the label text setting here:
InitializeCompo nent();
label1.Text = DateTime.Now.To String();

Then it works fine.

What do I need to learn?


Hi. If you open up the region that VS.NET creates for you called "Windows
Form Designer generated code", then you will see all of the initialization
of the controls that needs to take place BEFORE your loading of the text.
InitializeCompo nent() in your Form contstructor will do this needed
initialization. You need to do your own property setting of the controls
AFTER InitializeCompo nent().

-- Alan

Nov 17 '05 #4
BillZondlo wrote:
How come when I put the label text setting here:

/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run (new Form1());
}
private void LoadInfo()
{
label1.Text = DateTime.Now.To String();
}

The form comes up but no text is displayed?

If I put the label text setting here:

namespace Viewer1
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows. Forms.Form
{
private System.Windows. Forms.Label label1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();
label1.Text = DateTime.Now.To String();

Then it works fine.

What do I need to learn?


In the first example your function LoadInfo() would do what you want - but it is
never called! In the second your label initialization is done in the form's
constructor, which does get called when the app starts. A combination which
would also work would be:

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();
LoadInfo();
. . . etc.

HTH,
-rick-
Nov 17 '05 #5
Thank you for that information.

Good advice.

Bill
"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,
I recommend you two places where to put your controls customizations:

1- Right after the InitializateCom ponent () call in the constructor
2- the Form_Load event.

DO NOT MODIFY THE InitializateCom ponent () method, never touch it.

Pd:
In your first example when you call LoadInfo() ?

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"BillZondlo " <Bi********@dis cussions.micros oft.com> wrote in message
news:47******** *************** ***********@mic rosoft.com...
How come when I put the label text setting here:

/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run (new Form1());
}
private void LoadInfo()
{
label1.Text = DateTime.Now.To String();
}

The form comes up but no text is displayed?

If I put the label text setting here:

namespace Viewer1
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows. Forms.Form
{
private System.Windows. Forms.Label label1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();
label1.Text = DateTime.Now.To String();

Then it works fine.

What do I need to learn?

Bill


Nov 17 '05 #6
Thank you.

What you added helped me understand more of what Ignacio said.

Now I'll know to call my methods. :-)

I'm not real clear on my second example but I assume the button_click in the
"windows form designer generated code" does the calling after initialization.

Bill

"Rick Lones" wrote:
BillZondlo wrote:
How come when I put the label text setting here:

/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run (new Form1());
}
private void LoadInfo()
{
label1.Text = DateTime.Now.To String();
}

The form comes up but no text is displayed?

If I put the label text setting here:

namespace Viewer1
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows. Forms.Form
{
private System.Windows. Forms.Label label1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();
label1.Text = DateTime.Now.To String();

Then it works fine.

What do I need to learn?


In the first example your function LoadInfo() would do what you want - but it is
never called! In the second your label initialization is done in the form's
constructor, which does get called when the app starts. A combination which
would also work would be:

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();
LoadInfo();
. . . etc.

HTH,
-rick-

Nov 17 '05 #7
"BillZondlo " <Bi********@dis cussions.micros oft.com> wrote in message
news:0C******** *************** ***********@mic rosoft.com...
Or is this different in some way?


Yes, this snippet that you show is setting the label text in a button click
event handler. The InitializeCompo nent() had already been called earlier in
your Form1 constructor. (The constructor is called in the Run(new
Form1())).

-- Alan
Nov 17 '05 #8
In your second example, the button_click is an event handler, and so is
called when a button is clicked on the form ...

you will have the following in the code for your second example ...

public class Form1 : System.Windows. Forms.Form
{
private Button button1;
/* other declarations omitted for berevity */

private void InitializeCompo nent()
{
button1 = new System.Windows. Forms.Button();
button1.Click += new System.EventHan dler(this.butto n1_clicked);
/* other initialisations omitted for berevity */
}
/* other members omitted for berevity */
}

"BillZondlo " wrote:
Thank you.

What you added helped me understand more of what Ignacio said.

Now I'll know to call my methods. :-)

I'm not real clear on my second example but I assume the button_click in the
"windows form designer generated code" does the calling after initialization.

Bill

"Rick Lones" wrote:
BillZondlo wrote:
How come when I put the label text setting here:

/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run (new Form1());
}
private void LoadInfo()
{
label1.Text = DateTime.Now.To String();
}

The form comes up but no text is displayed?

If I put the label text setting here:

namespace Viewer1
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows. Forms.Form
{
private System.Windows. Forms.Label label1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();
label1.Text = DateTime.Now.To String();

Then it works fine.

What do I need to learn?


In the first example your function LoadInfo() would do what you want - but it is
never called! In the second your label initialization is done in the form's
constructor, which does get called when the app starts. A combination which
would also work would be:

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();
LoadInfo();
. . . etc.

HTH,
-rick-

Nov 17 '05 #9

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

Similar topics

2
30036
by: Xerxes | last post by:
Hi, can you tell me how I can make a <label> hidden? I have hidden the field after the label: var M_Hide = isNS4?'hide':'hidden'; var M_Show = isNS4?'show':'visible'; ..... <label id="uid">UserID: </label> <input name="UserID" type="text" value="" size="20"> <script language="Javascript1.2" type="text/javascript1.2">
2
1691
by: john young | last post by:
when settingup a label report in access using the wizard the resulting previw and print out is not as it should be .... example is using Avery labels(or any other). 24 to page ...3col by 8 rows... only 7 rows display.... Q. 1.. how can this be overcome to display correct number of rows..... and 2.. if one edits the report/label to change to custom .the latter rows of address labels 'creep' up the page so last row is printed on row...
2
4541
by: MrNobody | last post by:
is there any way I can adjust the behavior of a Label when text overflows it's boundaries? I have a specific size Label which can show 2 lines of text, but on some occassions the text I insert may be longer. On such occassion, you can see the top of a third line of text just above the bottom border of the Label (the text is cut off by the boundary of the LAbel) I would rather have it not display this third line at all (stop printing...
7
6753
by: jez123456 | last post by:
Hi, I have the following method where I need to display which database is being processed, however, the label lblDatabase dosn't seem to work until the end. private void AddPathAndCallCompactDB(string dbFolder, string systemDB, string UserID, string Pwd, string dbFileName) { FileInfo dbFileInfo = new FileInfo(dbFolder + dbFileName); this.lblDatabase.Text = dbFileInfo.Name; if (dbFileInfo.Exists)
7
8989
by: Ed West | last post by:
Hello, I have a simple form with some input boxes. After validation if one fails, then I would like to at the top of the page say something like "The following fields in red are required" and then change the label in front of the textbox or dropdown list to red... is this possible with asp.net? It seems you can only put a RequiredFieldValidator on the page, and if it fails validation then that text is displayed... ? Thanks
1
1906
by: Venki | last post by:
I have a textbox to enter an email address followed by a telephone textbox. The email has a regularexpressionvalidator and a requiredfieldvalidator. The ReqField works fine, but if I put in an invalid email addy then click in the telephone field below, something very odd happens. The telephone label & textbox (and all controls below) shift down one line, and rather than having my cursor in the telephone textbox. The cursor is in the...
2
1600
by: tshad | last post by:
Is there another way to put labels on a page other than asp:label? I have been building a page where I use a label to display the calculated result of some imput. I do it using Javascript. But since the asp:label equates to a <span> I have to create nodes to display the new text. The problem is that as soon as I change pages (whether by post or just using a back button), I lose whatever changes I made. I don't have that problem with...
7
4624
by: Sandy | last post by:
Hello - I have a form that when submitted checks the database and if the username is already taken, a label shows indicating same. I need to make that label NOT visible after the user clicks in the username textbox to change the name. Any help will be greatly appreciated!
2
3856
by: rn5a | last post by:
Consider the following code: <script runat="server"> Sub ShowData(obj As Object, ea As EventArgs) lblDate.Text = DateTime.Now.ToString("d") lblDate.DataBind() End Sub </script> <form runat="server"> <asp:Label ID="lblDate" OnDataBinding="ShowData" runat="server"/>
5
11810
by: BobLaughland | last post by:
Hi There, I am trying to get some fields to align on a web page, like this, To: From: Subject: Each of the fields above have a corresponding asp:Textbox control next to it that I cannot get to lign up. I have this code,
0
9673
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
9522
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
10443
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10216
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...
0
10002
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9044
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
7543
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
6783
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
5565
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.