5. Switching to a another forms
• Let’s consider that we want to have two forms and we want
to switch between them
– #1: First of all we add a new “second” form to out project
• Add > new item > form
– #2: include its header in first form header file
– ( “Form1.h” file )
#include "Form2.h"
– #3: pointing to the other form
Form2 ^f= gcnew Form2;
– #4: and start playing with it :D
f->Show();
6. Switching Back to Form1
• In “Form2.h”
namespace MyTestPro {
ref class Form1;
public: Form1 ^FPtr;
Form2(Form1 ^f)
{
InitializeComponent();
FPtr= f;
}
7. Switching Back to Form1
• In “Form2.cpp”
#include "StdAfx.h"
#include "Form2.h"
#include "Form1.h”
namespace MyTestPro {
System::Void Form2::Form2_Load(System::Object^
System::EventArgs^ e)
{
FPtr->Text= “New Form1 Text!";
}
}
sender,
37. ProgressBar
• Increment the progressBar and perform the “performStep()”
• What will happen when pressing the button?
private: System::Void button1_Click_4(System::Object^
System::EventArgs^ e)
{
progressBar1->PerformStep();
}
sender,
38. ProgressBar
• What will happen now when pressing the button, repeatedly?
private: System::Void button1_Click_4(System::Object^ sender,
System::EventArgs^ e)
{
progressBar1->PerformStep();
textBox1->Text= progressBar1->Value.ToString();
}
40. ProgressBar
• Another example:
– The following code example uses a ProgressBar control to display the
progress of a file copy operation. The example uses
the Minimum and Maximum properties to specify a range for
the ProgressBar that is equivalent to the number of files to copy. The
code also uses the Step property with the PerformStep method to
increment the value of theProgressBar as a file is copied. This example
requires that you have a ProgressBar control created called pBar1 that
is created within a Form and that there is a method created
called CopyFile (that returns a Boolean value indicating the file copy
operation was completed successfully) that performs the file copy
operation. The code also requires that an array of strings containing
the files to copy is created and passed to
the CopyWithProgress method defined in the example and that the
method is called from another method or event in the Form.
41. private:
void CopyWithProgress( array<String^>^filenames )
{
// Display the ProgressBar control.
pBar1->Visible= true;
// Set Minimum to 1 to represent the first file being copied.
pBar1->Minimum= 1;
// Set Maximum to the total number of files to copy.
pBar1->Maximum= filenames->Length;
// Set the initial value of the ProgressBar.
pBar1->Value= 1;
// Set the Step property to a value of 1 to represent each file being
copied.
pBar1->Step= 1;
// Loop through all files to copy.
for ( int x= 1; x <= filenames->Length; x++ )
{
// Copy the file and increment the ProgressBar if successful.
if ( CopyFile( filenames[ x - 1 ] )== true )
{
// Perform the increment on the ProgressBar.
pBar1->PerformStep();
}
}
}
46. NumericUpDown - coding
• As always, we can change anything at runtime
private: System::Void textBox1_TextChanged(System::Object^
System::EventArgs^ e)
{
numericUpDown1->Value=
}
int::Parse(textBox1->Text);
sender,
47. NumericUpDown - coding
• As always, we can change anything at runtime
private: System::Void textBox1_TextChanged(System::Object^
System::EventArgs^ e)
sender,
{
int i =int::TryParse(textBox1->Text, numericUpDown1->Value);
}
48. NumericUpDown - coding
• As always, we can change anything at runtime
private: System::Void textBox1_TextChanged(System::Object^
System::EventArgs^ e)
{
numericUpDown1->Text=
}
textBox1->Text;
sender,