C++ Windows Forms L03 - Controls P2
-
Upload
mohammad-shaker -
Category
Technology
-
view
333 -
download
4
description
Transcript of C++ Windows Forms L03 - Controls P2
![Page 1: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/1.jpg)
Mohammad Shakermohammadshakergtr.wordpress.com
C++.NET Windows Forms Course@ZGTRShaker
C++.NET Windows Forms Course
L03 – Controls Part 2
![Page 2: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/2.jpg)
Switching Between Forms
![Page 3: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/3.jpg)
It’s another form..
![Page 4: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/4.jpg)
Switching between forms
![Page 5: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/5.jpg)
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 )
– #3: pointing to the other form
– #4: and start playing with it :D
#include "Form2.h"
Form2 ^f= gcnew Form2;
f->Show();
![Page 6: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/6.jpg)
Switching Back to Form1
• In “Form2.h”
public: Form1 ^FPtr;
namespace MyTestPro {
ref class Form1;
Form2(Form1 ^f)
{
InitializeComponent();
FPtr= f;
}
![Page 7: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/7.jpg)
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^ sender,
System::EventArgs^ e)
{
FPtr->Text= “New Form1 Text!";
}
}
![Page 8: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/8.jpg)
Peak on Drawing ClassPoint & Size
![Page 9: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/9.jpg)
Peak on Drawing::Point
• What will happen now?
private: System::Void button1_Click(System::Object^
sender, System::EventArgs^ e)
{
button1->Location= 30,120;
}
![Page 10: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/10.jpg)
Peak on Drawing::Point
![Page 11: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/11.jpg)
Peak on Drawing::Point
• What will happen now?
private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e)
{
Drawing::Point P;
P.X= 2;
P.Y= 23;
button1->Location= P;
}
![Page 12: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/12.jpg)
Drawing::Point
![Page 13: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/13.jpg)
Helpers
![Page 14: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/14.jpg)
Helpers
So, what should we do?
![Page 15: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/15.jpg)
Point and Size
• Can we do this? Yes!private: System::Void button1_Click_1(System::Object^ sender,
System::EventArgs^ e)
{
Drawing::Size S;
S.Height= 200;
S.Width= 300;
this->Size= S;
}
![Page 16: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/16.jpg)
Point and Size
• Can we do this? private: System::Void button1_Click_1(System::Object^ sender,
System::EventArgs^ e)
{
Drawing::Size ^S;
S->Height= 200;
S->Width= 300;
this->Size= S;
}
Compile error
Error 1 error C2664: 'void
System::Windows::Forms::Control::Size::set(System::Drawing::Size)':
cannot convert parameter 1 from 'System::Drawing::Size ^' to
'System::Drawing::Size' c:\users\zgtr\documents\visual studio
2008\projects\dotnet4\dotnet4\Form1.h 129 dotNet4
![Page 17: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/17.jpg)
Helpers
![Page 18: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/18.jpg)
Point and Size
private: System::Void button1_Click_1(System::Object^
sender, System::EventArgs^ e)
{
this->Size= Drawing::Size(200,300);
}
Works!
![Page 19: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/19.jpg)
Helpers
![Page 20: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/20.jpg)
Point and Size
![Page 21: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/21.jpg)
Label
![Page 22: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/22.jpg)
Label
• Properties:Name, Text, Font, image, Location, Size, TabStop, TabIndex, Visible, BackColor
• Event:MouseClick, MouseDown, MouseLeave, Resize, SizeChange, TextChanged, VisibleChanged, KeyUp, KeyDown, DragDrop
![Page 23: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/23.jpg)
TextBox
![Page 24: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/24.jpg)
TextBox
• Properties:Name, Text, Font, image, Location, Size, TabStop, TabIndex, Visible, BackColor, MultiLine, ScrollBar
• Event:MouseClick, MouseDown, MouseLeave, Resize, SizeChange, TextChanged, VisibleChanged, KeyUp, KeyDown, DragDrop
![Page 25: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/25.jpg)
Panel
![Page 26: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/26.jpg)
Panel
• Properties:Name, Text, Font, image, Location, Size, TabStop, TabIndex, Visible, BackColor, Border Style, AutoSize
• Event:MouseClick, MouseDown, MouseLeave, Resize, SizeChange, TextChanged, VisibleChanged, KeyUp, KeyDown, DragDrop
![Page 27: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/27.jpg)
TrackBar
![Page 28: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/28.jpg)
TrackBar
![Page 29: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/29.jpg)
TrackBar
![Page 30: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/30.jpg)
TrackBar
Keyboard keys (Arrows)
position
Number of ticks between tick marks
![Page 31: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/31.jpg)
TrackBar
• What will happen now?
private: System::Void trackBar1_Scroll(System::Object^ sender,
System::EventArgs^ e)
{
textBox1->Text= trackBar1->Value.ToString();
}
![Page 32: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/32.jpg)
TrackBar
![Page 33: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/33.jpg)
ProgressBar
![Page 34: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/34.jpg)
ProgressBar
![Page 35: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/35.jpg)
ProgressBar
![Page 36: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/36.jpg)
ProgressBar
![Page 37: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/37.jpg)
ProgressBar
• Increment the progressBar and perform the “performStep()” • What will happen when pressing the button?
private: System::Void button1_Click_4(System::Object^ sender,
System::EventArgs^ e)
{
progressBar1->PerformStep();
}
![Page 38: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/38.jpg)
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();
}
![Page 39: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/39.jpg)
ProgressBar After clicking button1 for 1st time
After clicking button1 for 2nd time
Before clicking button1
![Page 40: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/40.jpg)
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.
![Page 41: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/41.jpg)
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();
}}
}
![Page 42: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/42.jpg)
NumericUpDown
![Page 43: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/43.jpg)
NumericUpDown properties
The interval
Starting value
![Page 44: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/44.jpg)
NumericUpDown - coding
• Text property
private: System::Void button1_Click_1(System::Object^ sender,
System::EventArgs^ e)
{
textBox1->Text= numericUpDown1->Text;
}
![Page 45: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/45.jpg)
NumericUpDown - coding
• Everything ok?
private: System::Void textBox1_TextChanged(System::Object^ sender,
System::EventArgs^ e)
{
numericUpDown1->Value= textBox1->Text;
}
Compiler error. String assigned to int
![Page 46: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/46.jpg)
NumericUpDown - coding
• As always, we can change anything at runtime
private: System::Void textBox1_TextChanged(System::Object^ sender,
System::EventArgs^ e)
{
numericUpDown1->Value= int::Parse(textBox1->Text);
}
![Page 47: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/47.jpg)
NumericUpDown - coding
• As always, we can change anything at runtime
private: System::Void textBox1_TextChanged(System::Object^ sender,
System::EventArgs^ e)
{
int i =int::TryParse(textBox1->Text, numericUpDown1->Value);
}
![Page 48: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/48.jpg)
NumericUpDown - coding
• As always, we can change anything at runtime
private: System::Void textBox1_TextChanged(System::Object^ sender,
System::EventArgs^ e)
{
numericUpDown1->Text= textBox1->Text;
}
![Page 49: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/49.jpg)
PictureBox
![Page 50: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/50.jpg)
PictureBox
• Very important for drawing!
![Page 51: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/51.jpg)
PictureBox
![Page 52: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/52.jpg)
PictureBox
![Page 53: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/53.jpg)
PictureBox
![Page 54: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/54.jpg)
PictureBox
![Page 55: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/55.jpg)
PictureBox
![Page 56: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/56.jpg)
PictureBox .gif
![Page 57: C++ Windows Forms L03 - Controls P2](https://reader034.fdocuments.in/reader034/viewer/2022042503/549cb191b47959b7318b4805/html5/thumbnails/57.jpg)
That’s it for today!