Creating a Label at runtime from another form

S

Soren-a

Hi

I have a problem in a C#.NET CF program that I am working on at it is
driving me nuts!

I have two form "StatusBarForm" and "LoginForm".

In the "StatusBarForm" I declear a Panel ("pnlStatus1") and a Label
("lblLoginNavn") like this:

public class StatusBarForm : System.Windows.Forms.Form
{
public System.Windows.Forms.Panel pnlStatus1;

public Label lblLoginNavn = new Label();

public StatusBarForm()
{
InitializeComponent();
}

protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}

Windows Form Designer generated code

}
}

The idea now is to create the "lblLoginNavn" label in a click event on
the "LoginForm" form. I do it like this:

First I decleare a new instanse of the "StatusBarForm", and then I
create the "lblLoginNavn" label on the "StatusBarForm" and add it to
the "pnlStatus1" panel.

I do it like this:

public class LoginForm : System.Windows.Forms.Form
{
StatusBarForm StatusBaren = new StatusBarForm();
 
L

Luis Cabrera

Things to check:

1. Do you have the event handler connected to your button event. You
probably do, but I don't see it in the snippet of code provided.
2. Have you tried putting a breapoint in the event handler and debugging?
That would give you more information as to what is going on.

Luis Cabrera [[email protected]]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top