954,504 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

.NET Multiple form controls

Hey, I was just wondering how I can get it so when I click a button it opens my second form. But sets some of the labels to a specific thing, so I don't end up making 170+ forms for my periodic table application. Just like so when I click "H" it opens the "Form2" and sets the label "atomname" to "Hydrogen"?

Here's my buttonclick so far.

private: System::Void hydrogen_Click(System::Object^  sender, System::EventArgs^  e) {
				 Form2^ newform2 = gcnew Form2;
				 newform2->ShowDialog();
valestrom
Junior Poster in Training
54 posts since Mar 2011
Reputation Points: 27
Solved Threads: 0
 

Define your own constructor for Form2 that accepts this information and sets control values accordingly. For example:

Form2^ frm = gcnew Form2("Hydrogen");

frm->ShowDialog();
Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

Define your own constructor for Form2 that accepts this information and sets control values accordingly. For example:

Form2^ frm = gcnew Form2("Hydrogen");

frm->ShowDialog();


This didn't work. Upon entering this exactly I got:

1>c:\users\blackmethod\documents\visual studio 2010\projects\valestrom's periodic table\valestrom's periodic table\Form1.h(2086): error C3673: 'ValestromsPeriodicTable::Form2' : class does not have a copy-constructor


Help on what's wrong here?

valestrom
Junior Poster in Training
54 posts since Mar 2011
Reputation Points: 27
Solved Threads: 0
 
Help on what's wrong here?


You didn't provide any code, so I can only guess that you failed to actually write the constructor.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 
You didn't provide any code, so I can only guess that you failed to actually write the constructor.


I copied your exact code.

valestrom
Junior Poster in Training
54 posts since Mar 2011
Reputation Points: 27
Solved Threads: 0
 

My exact code was incomplete. So if you didn't also add a corresponding constructor, my guess was correct.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 
My exact code was incomplete. So if you didn't also add a corresponding constructor, my guess was correct.


I was in a hurry, I got your reply and tried it right off, sorry. What part of it is incomplete.

valestrom
Junior Poster in Training
54 posts since Mar 2011
Reputation Points: 27
Solved Threads: 0
 
What part of it is incomplete.


How many times do I have to repeat myself?You must write the constructor that is being called.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 
How many times do I have to repeat myself? You must write the constructor that is being called.

Still have no idea about how to do it, but you gave me enough info that google should be my friend.

valestrom
Junior Poster in Training
54 posts since Mar 2011
Reputation Points: 27
Solved Threads: 0
 
<include FormName.h>

Form1::Visible = false;
FormName ^ Form2 = gcnew FormName();
Form2->ShowDialog();


That should be more than enough.. It's what I use.. If u made your form2 in the same project as Form1.h then just include the Form2.h file in the first form.. that way u don't need to make a constructor & destructor.

triumphost
Posting Whiz
390 posts since Oct 2009
Reputation Points: 57
Solved Threads: 36
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: