Opening other forms

  • Thread starter Thread starter Daniel Moth
  • Start date Start date
D

Daniel Moth

Silly question: you do have a frmScreening defined in the same namespace,
right?

What is the compiler error?

Cheers
Daniel
 
What's the deal here. If I leave the default form name, this code works for
launching another form:

Form1 screen = new Form1();

However, if I change the name of the form like this:

frmScreening screen = new frmScreening();

it doesn't work...just throws a compiler error! Why can't I rename a form
and then call it in code as I'm doing, this is just plain silly!!!

Thanks
 
I left out the screen.Show(); since this is understood for actually doing
the opening...
 
But what's the error? Did you change the ctor (and dtor if you have one)
name as well as the class name?
 
The type or namespace name 'frmScreening' could not be found (are you
missing a using directive or an assembly reference?)

How should I include this or what am I doing wrong. All I do is add a form,
then in another form's code, simply put the previously mentioned code and it
throws the error. Is there something more I have to do to insure it is
usable for the entire project?
 
So it is not defined. Looking though Class View rather than Solution
Explorer would have also verified that.

When you add a form you give it a name right? Let's say it is Form1 residing
in Form1.cs. Search in that file for all occurrences of Form1 (usually it is
just the class name and the constructor).

If you wish to replicate its functionality in another form called
frmScreening, you should make sure that wherever it previously read Form1,
it now reads frmScreening. Also check that the namespace name is the same
(or import it at the top).

In other words, just changing the file name is not enough.

Cheers
Daniel
 
I've done a search several times and nowhere is there any reference to the
old name...I was pretty thorough when I went through and changed the name,
but still nothing...here's the class nonetheless.

public class frmScreening : System.Windows.Forms.Form

{

private System.Windows.Forms.Label label2;

private System.Windows.Forms.Button btnDone;

private System.Windows.Forms.Button btnGender;

private System.Windows.Forms.Button btnSite;

private System.Windows.Forms.Label label1;


public frmScreening()

{

//

// Required for Windows Form Designer support

//

InitializeComponent();

//

// TODO: Add any constructor code after InitializeComponent call

//

}

/// <summary>

/// Clean up any resources being used.

/// </summary>

protected override void Dispose( bool disposing )

{

base.Dispose( disposing );

}

#region Windows Form Designer generated code

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.btnGender = new System.Windows.Forms.Button();

this.label2 = new System.Windows.Forms.Label();

this.label1 = new System.Windows.Forms.Label();

this.btnSite = new System.Windows.Forms.Button();

this.btnDone = new System.Windows.Forms.Button();

//

// btnGender

//

this.btnGender.Font = new System.Drawing.Font("Tahoma", 9F,
System.Drawing.FontStyle.Regular);

this.btnGender.Location = new System.Drawing.Point(50, 118);

this.btnGender.Size = new System.Drawing.Size(140, 24);

this.btnGender.Text = "Gender and Age";

//

// label2

//

this.label2.Font = new System.Drawing.Font("Tahoma", 9F,
System.Drawing.FontStyle.Regular);

this.label2.Location = new System.Drawing.Point(8, 32);

this.label2.Size = new System.Drawing.Size(232, 32);

this.label2.Text = "Tap one of the two buttons below to access screening
recommendations.";

//

// label1

//

this.label1.Font = new System.Drawing.Font("Tahoma", 9.75F,
System.Drawing.FontStyle.Bold);

this.label1.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)),
((System.Byte)(0)), ((System.Byte)(192)));

this.label1.Location = new System.Drawing.Point(8, 8);

this.label1.Size = new System.Drawing.Size(224, 16);

this.label1.Text = "Screening Guidelines";

//

// btnSite

//

this.btnSite.Font = new System.Drawing.Font("Tahoma", 9F,
System.Drawing.FontStyle.Regular);

this.btnSite.Location = new System.Drawing.Point(50, 149);

this.btnSite.Size = new System.Drawing.Size(140, 24);

this.btnSite.Text = "Site";

//

// btnDone

//

this.btnDone.Font = new System.Drawing.Font("Tahoma", 9F,
System.Drawing.FontStyle.Regular);

this.btnDone.Location = new System.Drawing.Point(8, 235);

this.btnDone.Size = new System.Drawing.Size(48, 24);

this.btnDone.Text = "Done";

//

// frmScreening

//

this.Controls.Add(this.btnDone);

this.Controls.Add(this.btnSite);

this.Controls.Add(this.btnGender);

this.Controls.Add(this.label2);

this.Controls.Add(this.label1);

this.Font = new System.Drawing.Font("Tahoma", 9F,
System.Drawing.FontStyle.Regular);

}

#endregion

}

}
 
Well, if you can see it in Class View and it lives under the *same*
namespace as the calling code then I'd have to have a look at the project.
Can you zip it up and send it?

Cheers
Daniel
 
For info:
Turns out this was a namespace issue after all (Aaron sent me the project).
A using statement at the top solved it

Cheers
Daniel
 
Back
Top