I've been trying to do something similar to this as well...
I have tried following the above instructions, but I build and get errors saying Form2 is an undeclared identifier... however I am unsure where to declare this. I have created the form and event handlers for the form, but cannot show the form when the menuitem is selected. Suggestions
Yeah, I had already replaced "Form2" with the name of my form, I've just used the name Form2 for ease of discussion. They are indeed in the same namespace.
aboutForm is my secondary form, which I am trying to create an instance of in this event handler in Form1. The error that is stated says aboutForm is an undeclared identifier. Any thoughts
Double-click your button (assuming it's called button1) in the designer (IDE) on form1 so that an event is created. In the event handler that it creates, use the following code:
You can also use the code form2.Show(); instead of form2.ShowDialog(); if you don't want the form that pops up to be modal (ie. can't access form1 again until form2 is closed).
Replace "Form2" with the name of the form you want to show. Note that the form's filename in the Solution Explorer is not necessarily the actual name, although it probably should be. Go to your Form2 in the designer and scroll down and check the Name property. If it matches what you had in the code, then check the namespaces. Go near the top of each form file and make sure they are in the same namespace. If you are still having trouble, please provide more info about what you have done and are trying to do.
Alright problem solved. I needed to use the top level indicator ^ as in...
aboutForm^ about = gcnew aboutForm;
as aboutForm had no intrinsic copy constructor. Although these are in the same namespace, I also needed to include the file at the top of my Form1 header.
how to make a window popup when i press a button i have created
how to make a window popup when i press a button i have created
rougiero
I've been trying to do something similar to this as well...
I have tried following the above instructions, but I build and get errors saying Form2 is an undeclared identifier... however I am unsure where to declare this. I have created the form and event handlers for the form, but cannot show the form when the menuitem is selected. Suggestions
Thanks
pdianne
Yeah, I had already replaced "Form2" with the name of my form, I've just used the name Form2 for ease of discussion. They are indeed in the same namespace.
private
: System::Void aboutToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {aboutForm about = new aboutForm;
}
aboutForm is my secondary form, which I am trying to create an instance of in this event handler in Form1. The error that is stated says aboutForm is an undeclared identifier. Any thoughts
GiulioPetrucci
Assuming that you have two forms:
Double-click your button (assuming it's called button1) in the designer (IDE) on form1 so that an event is created. In the event handler that it creates, use the following code:
private void button1_Click(object sender, System.EventArgs e)
{
Form2 form2 = new Form2();
form2.ShowDialog();
}
You can also use the code form2.Show(); instead of form2.ShowDialog(); if you don't want the form that pops up to be modal (ie. can't access form1 again until form2 is closed).
windypoint
HAMID SHAHID
Alright problem solved. I needed to use the top level indicator ^ as in...
aboutForm^ about = gcnew aboutForm;
as aboutForm had no intrinsic copy constructor. Although these are in the same namespace, I also needed to include the file at the top of my Form1 header.