Sunday, December 18, 2011

2-Tutorial 2: Windows Basic Form Controls in C++ and Their Properties Using Visual C++.NET 2010, 2008

Tutorial 2: Windows Basic Form Controls in C++ and Their Properties Using Visual C++.NET 2010, 2008
        This program will show how to transfer an image to a pictureBox and do conversions from Strings to numerical values and numbers to String. Click here for the source code to the Basic Tools and Conversions Program in Visual C++.NET for the 2010 version or here to download the 2008 version. Set up a form that looks like this:    
Basic Controls in a Microsoft Visual C++ Program
        Set picturebox1 to a sizemode of stretchImage. Then within your project add a file called "heads.jpg" having a picture of a penny to your folder containing your .cpp source file and then add the following lines of code to the appropriate buttons functions:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
       {
         textBox1->Text="hi";
       }
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e)
     {
       label1->Text=textBox1->Text;
     }
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e)
     {
       pictureBox1->Image=Image::FromFile("heads.jpg");
     }
private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e)
     {
       int num1;
       int num2;
       int answer;
       String ^strNum1;
       String ^strNum2;
       String ^strAnswer;
       strNum1=textBox2->Text;
       strNum2=textBox3->Text;
       num1=Int32::Parse(strNum1);
       num2=Int32::Parse(strNum2);
       answer=num1+num2;
       strAnswer=answer.ToString();
       label4->Text=strAnswer;
     }

0 comments:

Post a Comment