473,385 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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.ToString();
}

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.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
label1.Text = DateTime.Now.ToString();

Then it works fine.

What do I need to learn?

Bill

Nov 17 '05 #1
8 2464
"BillZondlo" <Bi********@discussions.microsoft.com> wrote in message
news:47**********************************@microsof t.com...
If I put the label text setting here:
InitializeComponent();
label1.Text = DateTime.Now.ToString();

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.
InitializeComponent() in your Form contstructor will do this needed
initialization. You need to do your own property setting of the controls
AFTER InitializeComponent().

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

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

DO NOT MODIFY THE InitializateComponent () 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********@discussions.microsoft.com> wrote in message
news:47**********************************@microsof t.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.ToString();
}

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.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
label1.Text = DateTime.Now.ToString();

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.Run(new form1())}

i.e.

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

public void button1_Click(object sender, System.EventArgs e) //open folder
selection.
{
DialogResult result = folderBrowserDialog1.ShowDialog();
if(result == DialogResult.OK ) //folder selected
{
folderName1 = folderBrowserDialog1.SelectedPath;
label1.Text = folderName1 ;

Or is this different in some way?

TIA

Bill

"Alan Pretre" wrote:
"BillZondlo" <Bi********@discussions.microsoft.com> wrote in message
news:47**********************************@microsof t.com...
If I put the label text setting here:
InitializeComponent();
label1.Text = DateTime.Now.ToString();

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.
InitializeComponent() in your Form contstructor will do this needed
initialization. You need to do your own property setting of the controls
AFTER InitializeComponent().

-- 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.ToString();
}

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.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
label1.Text = DateTime.Now.ToString();

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
//
InitializeComponent();
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 InitializateComponent () call in the constructor
2- the Form_Load event.

DO NOT MODIFY THE InitializateComponent () 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********@discussions.microsoft.com> wrote in message
news:47**********************************@microsof t.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.ToString();
}

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.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
label1.Text = DateTime.Now.ToString();

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.ToString();
}

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.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
label1.Text = DateTime.Now.ToString();

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
//
InitializeComponent();
LoadInfo();
. . . etc.

HTH,
-rick-

Nov 17 '05 #7
"BillZondlo" <Bi********@discussions.microsoft.com> wrote in message
news:0C**********************************@microsof t.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 InitializeComponent() 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 InitializeComponent()
{
button1 = new System.Windows.Forms.Button();
button1.Click += new System.EventHandler(this.button1_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.ToString();
}

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.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
label1.Text = DateTime.Now.ToString();

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
//
InitializeComponent();
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
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...
2
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......
2
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...
7
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...
7
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...
1
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...
2
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...
7
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...
2
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...
5
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.