hello guys i make a simple calculator in window form application and i want to add it with a scientific calculator form how can i connect these two forms

Dani AI

Generated

Short practical notes for connecting two Windows Forms in a C++/CLI project (builds on 's suggestion).

If you want the scientific form to appear when a button on Form1 is clicked, create the click handler (double-click the button in the designer or add the event hookup). Then instantiate the second form and show it. Example patterns:

#include "Form2.h"

private: System::Void buttonScientific_Click(System::Object^ sender, System::EventArgs^ e)
{
    // modal: blocks Form1 until Form2 closes
    Form2^ f2 = gcnew Form2();
    f2->ShowDialog(this);
    delete f2;   // disposes unmanaged resources

    // non-modal alternative:
    // Form2^ f2 = gcnew Form2();
    // f2->Owner = this;
    // f2->Show();
}

To pass data (for example the current display value), add a public property on Form2 and set it before showing:

Form2^ f2 = gcnew Form2();
f2->StartValue = this->textBoxDisplay->Text;
f2->ShowDialog(this);
delete f2;

Troubleshooting and cautions:

  • If the compiler cannot find Form2, add #include "Form2.h" to the top of Form1.h (or forward-declare ref class Form2; and include the header in the .cpp to avoid circular includes).
  • Use ShowDialog for modal flow (common for modal calculators). Use Show for modeless windows but remember to keep a reference if you need to reuse or delete it later.
  • Avoid calling this->Close() on the startup/main form unless you want the app to exit. Use this->Hide() if you want Form1 hidden while Form2 is shown.
  • In C++/CLI call delete on forms created with gcnew when finished to ensure proper disposal of unmanaged resources.

This covers the common ways to "go to second form", how to pass values, and pitfalls to watch for when connecting the two forms.

Recommended Answers

All 9 Replies

If you are using Visual Studio, in solution explorer window, right click your solution,-->Add-->New Item-->Windows Form.
Call this from your button click handler.

thankx alot #ddanbe

i made another form but i need your help @ ddanbe to connect second form. how to make a handle that when i click scintific button on form 1 it goes to second form

on't know exactly what you mean by "goes to second form"
Perhaps this video may give you some further ideas.

i mean when i click on the button on form1 it goes to second form

got it thankx again @ ddanbe

will your calculator be able to convert Dec <-> Binary <-> Hex <-> Oct ?
How many decimal places will it print 22/7 or pi?

its not a convertor

double pi=3.14159265;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.