C++ Windows Forms L01 - Intro

1,024 views

Published on

C++ Windows Forms L01 - Intro of C++ Windows Forms Light Course

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,024
On SlideShare
0
From Embeds
0
Number of Embeds
300
Actions
Shares
0
Downloads
83
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

C++ Windows Forms L01 - Intro

  1. 1. C++.NET Windows Forms Course L01 - Introduction Mohammad Shaker mohammadshakergtr.wordpress.com C++.NET Windows Forms Course @ZGTRShaker
  2. 2. .NET What will you learn? • • • • • • OOP with .NET, Thinking OOP and The Concept of .NET Peek on C++.NET console Debugging in .NET Windows Forms Controls (Tabs, ComboBox, Timers, ...etc) Drawing with .NET Collections
  3. 3. .NET What will you learn? • • • • • Event Handling Exception Handling Files processing - Strings Manipulating Dynamic Controls associated with Event Handling The Concept of C#
  4. 4. What’s .NET? • .NET Framework : – A collection of technologies that … • Unite isolated applications • Make information available anytime, anywhere • Simplify development and deployment
  5. 5. What’s .NET? • .NET Framework : – Common Language Runtime* – provides an abstraction layer over the operating system – Base Class Libraries • pre-built code for common low-level programming tasks – Development frameworks and technologies • Reusable • customizable solutions for larger programming tasks _________________________________________________ *The Common Language Runtime (CLR) is the virtual machine component of the .NET Framework. All .NET programs execute under the supervision of the CLR, guaranteeing certain properties and behaviors in the areas of memory management, security, and exception handling.
  6. 6. Some .NET Base Class Libraries System.Web Services Description Discovery Protocols System.WinForms UI Design ComponentModel HtmlControls WebControls System.Drawing Security Caching Configuration Drawing2D Printing SessionState Imaging Text System.Data System.Xml ADO SQL XSLT Design SQLTypes Serialization XPath System Collections IO Security Configuration Net ServiceProcess Runtime InteropServices Diagnostics Reflection Text Remoting Globalization Resources Threading Serialization
  7. 7. Visual Studio® .NET Manage and Collaborate Planning Analysis Design Development Testing Deployment .NET Platform
  8. 8. .NET Framework, Languages, Tools VB C++ C# JScript Web Services User Interface Data and XML Base Class Library Common Language Runtime Visual Studio .NET Common Language Specification …
  9. 9. Common Language Runtime Base Class Library Support Thread Support COM Marchaler Type Checker Exception Manager Security Engine Debug Engine IL to Native Compilers Code Manager Class Loader Garbage Collector
  10. 10. .NET Framework Services  ASP.NET  Logical evolution of ASP (compiled)  Web forms  Manageable code (non spaghetti)  Windows® forms  Framework for building rich clients  ADO.NET, evolution of ADO  New objects (e.g., DataSets)  XML Support Throughout
  11. 11. Introduction to .NET
  12. 12. Introduction to .NET • The .NET Framework allows you to: – Apply common skills across a variety of devices , application types , and programming tasks – Integrate with other tools and technologies to build the right solution with less work – Build compelling applications faster • .NET Framework releases : – 1 , 1.1 , 2 , 3 , 3.5 , 4, 4.5
  13. 13. .NET IDE and Frameworks • .NET With Visual Studio 2008 2010 2012 2013 • Framework 3.5 4.0 4.5
  14. 14. Resources for .NET  http://www.w3.org/TR/SOAP/ - W3C standards for SOAP implementation  http://www.uddi.org – UDDI standards for web services implementation  http://www.microsoft.com/net - Microsoft .NET home  http://msdn.microsoft.com/net - Microsoft .NET developers home  http://msdn.microsoft.com/xml - Microsoft XML developers home  http://msdn.microsoft.com/webservices – Microsoft Web Services developers home  http://www.gotdotnet.com – Developers .NET resource
  15. 15. Controls • • • • • • • • Form Button CheckBox CheckedListBox ComboBox Label ListBox PictureBox • • • • • • • ProgressBar RadioButton TextBox Panel TabControl DataGridView Timer
  16. 16. Con.sole
  17. 17. Console
  18. 18. Console
  19. 19. Console // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { Console::WriteLine(L"Hello World"); return 0; }
  20. 20. Console
  21. 21. Console // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { Console::WriteLine(L"Hello World"); Console::ReadKey(); return 0; }
  22. 22. Console // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { Console::WriteLine(L"Hello World"); Console::ReadKey(); return 0; }
  23. 23. Console What’s this? // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { Console::WriteLine(L"Hello World"); Console::ReadKey(); return 0; }
  24. 24. Console What a “namespace” is?! // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { Console::WriteLine(L"Hello World"); Console::ReadKey(); return 0; }
  25. 25. Console Why using another namespace?! // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { Console::WriteLine(L"Hello World"); Console::ReadKey(); return 0; }
  26. 26. Console “main” Why? // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { Console::WriteLine(L"Hello World"); Console::ReadKey(); return 0; }
  27. 27. Console Why isn’t it just a void?! #include "stdafx.h" Why passing a string “args” // CppdotNetConsoleCourseTest.cpp : main project file. using namespace System; int main(array<System::String ^> ^args) { Console::WriteLine(L"Hello World"); Console::ReadKey(); return 0; }
  28. 28. Console Easy, right?! // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { Console::WriteLine(L"Hello World"); Console::ReadKey(); return 0; }
  29. 29. Console What’s that?! // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { Console::WriteLine(L"Hello World"); Console::ReadKey(); return 0; }
  30. 30. Console Object/Class // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { Console::WriteLine(L"Hello World"); Console::ReadKey(); return 0; }
  31. 31. Console “::” ?! // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { Console::WriteLine(L"Hello World"); Console::ReadKey(); return 0; }
  32. 32. Console // CppdotNetConsoleCourseTest.cpp : main project file. Console::WriteLine #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { Console::WriteLine(L"Hello World"); Console::ReadKey(); return 0; }
  33. 33. Console // CppdotNetConsoleCourseTest.cpp : main project file. Console::WriteLine #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { Console::WriteLine(L"Hello World"); Console::ReadKey(); return 0; }
  34. 34. Console // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { Console ^myConsole=gcew Console(); Console::WriteLine(L"Hello World"); Console::ReadKey(); return 0; }
  35. 35. Console // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { Console ^myConsole=gcew Console(); Console::WriteLine(L"Hello World"); Console::ReadKey(); return 0; }
  36. 36. Console Creating an instance of class “Console” // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { Console ^myConsole=gcew Console(); Console::WriteLine(L"Hello World"); Console::ReadKey(); return 0; }
  37. 37. Console // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { Console::WriteLine(L"Hello World"); Console::Write("Hi, again!"); Console::WriteLine("n Hi, again!"); Console::Write("Hi, again!"); Console::ReadKey(); return 0; }
  38. 38. Console // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { Console::WriteLine(L"Hello World"); Console::Write("Hi, again!"); Console::WriteLine("n Hi, again!"); Console::Write("Hi, again!"); Console::ReadKey(); return 0; } Hello World Hi, again! Hi, again! Hi, again!
  39. 39. Console // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { String ^str1=gcnew String("Hi Hi Hi, first time."); String ^str2="Hi Hi Hi, second time."; String ^str3; Console::Write("Enter your name plz: "); str3=Console::ReadLine(); Console::WriteLine(str1 + " " + str2 + " Hi " + str3 + "!"); Console::ReadKey(); return 0; }
  40. 40. Console // CppdotNetConsoleCourseTest.cpp : main project file. Everything is dynamically allocated through pointer! #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { String ^str1=gcnew String("Hi Hi Hi, first time."); String ^str2="Hi Hi Hi, second time."; String ^str3; Console::Write("Enter your name plz: "); str3=Console::ReadLine(); Console::WriteLine(str1 + " " + str2 + " Hi " + str3 + "!"); Console::ReadKey(); return 0; }
  41. 41. Console // CppdotNetConsoleCourseTest.cpp : main project file. Why no gcnew here?! #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { String ^str1=gcnew String("Hi Hi Hi, first time."); String ^str2="Hi Hi Hi, second time."; String ^str3; Console::Write("Enter your name plz: "); str3=Console::ReadLine(); Console::WriteLine(str1 + " " + str2 + " Hi " + str3 + "!"); Console::ReadKey(); return 0; }
  42. 42. Console // CppdotNetConsoleCourseTest.cpp : main project file. Why no gcnew here?! #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { String ^str1=gcnew String("Hi Hi Hi, first time."); String ^str2="Hi Hi Hi, second time."; String ^str3; Console::Write("Enter your name plz: "); str3=Console::ReadLine(); Console::WriteLine(str1 + " " + str2 + " Hi " + str3 + "!"); Console::ReadKey(); return 0; }
  43. 43. Console // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { String ^str1=gcnew String("Hi Hi Hi, first time."); String ^str2="Hi Hi Hi, second time."; String ^str3; Console::Write("Enter your name plz: "); str3=Console::ReadLine(); Console::WriteLine(str1 + " " + str2 + " Hi " + str3 + "!"); Console::ReadKey(); return 0; }
  44. 44. Console // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { String ^str1=gcnew String("Hi Hi Hi, first time."); String ^str2="Hi Hi Hi, second time."; String ^str3; Console::Write("Enter your name plz: "); str3=Console::ReadLine(); Console::WriteLine(str1 + " " + str2 + " Hi " + str3 + "!"); Console::ReadKey(); return 0; }
  45. 45. Console // CppdotNetConsoleCourseTest.cpp : main project file. Returns the string that’s read from the input buffer #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { String ^str1=gcnew String("Hi Hi Hi, first time."); String ^str2="Hi Hi Hi, second time."; String ^str3; Console::Write("Enter your name plz: "); str3=Console::ReadLine(); Console::WriteLine(str1 + " " + str2 + " Hi " + str3 + "!"); Console::ReadKey(); return 0; }
  46. 46. Console // CppdotNetConsoleCourseTest.cpp : main project file. Returns the string that’s read from the input buffer #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { String ^str1=gcnew String("Hi Hi Hi, first time."); String ^str2="Hi Hi Hi, second time."; String ^str3; Console::Write("Enter your name plz: "); str3=Console::ReadLine(); Console::WriteLine(str1 + " " + str2 + " Hi " + str3 + "!"); Console::ReadKey(); return 0; }
  47. 47. Console // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { int i=1; float f=0; Console::WriteLine(i.ToString() + f.ToString()); Console::ReadKey(); return 0; }
  48. 48. Console // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { int i=1; float f=0; Console::WriteLine(i.ToString() + f.ToString()); Console::ReadKey(); return 0; } It’s not a “->”
  49. 49. Console // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { int i=1; float f=0; Console::WriteLine(i.ToString() + f.ToString()); Console::ReadKey(); return 0; } Where this method “ToString()” comes from?!
  50. 50. Console // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { int i=1; float f=0; Console::WriteLine(i.ToString() + f.ToString()); Console::ReadKey(); return 0; } 10
  51. 51. Console // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { int i=1; float f=0; Console::WriteLine(i + f); Console::ReadKey(); return 0; }
  52. 52. Console No “ToString()” method! // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { int i=1; float f=0; Console::WriteLine(i + f); Console::ReadKey(); return 0; }
  53. 53. Console How compiler works?! // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { int i=1; float f=0; Console::WriteLine(i + f); Console::ReadKey(); return 0; }
  54. 54. Console How compiler works?! // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { int i=1; float f=0; Console::WriteLine(i + f); Console::ReadKey(); return 0; }
  55. 55. Console How compiler works?! // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { int i=1; float f=0; Console::WriteLine(i + f); Console::ReadKey(); return 0; }
  56. 56. Console How compiler works?! // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { int i=1; float f=0; Console::WriteLine(i + f); Console::ReadKey(); return 0; }
  57. 57. Console How compiler works?! // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { int i=1; float f=0; Console::WriteLine(i + f); Console::ReadKey(); return 0; }
  58. 58. Console How compiler works?! // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { int i=1; float f=0; Console::WriteLine(i + f); Console::ReadKey(); return 0; }
  59. 59. Console How compiler works?! // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { int i=1; float f=0; Console::WriteLine(i + f); Console::ReadKey(); return 0; }
  60. 60. Console How compiler works?! // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { int i=1; float f=0; Console::WriteLine(i + f); Console::ReadKey(); return 0; }
  61. 61. Console Arithmetic “Sum”! // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { int i=1; float f=0; Console::WriteLine(i + f); Console::ReadKey(); return 0; }
  62. 62. Console Results a “float” // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { int i=1; float f=0; Console::WriteLine(i + f); Console::ReadKey(); return 0; }
  63. 63. Console Results a “float” in a “String” context // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { int i=1; float f=0; Console::WriteLine(i + f); Console::ReadKey(); return 0; }
  64. 64. Console Results a “float” in a “String” context // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { int i=1; float f=0; Console::WriteLine(i + f); Console::ReadKey(); return 0; }
  65. 65. Console // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { int i=1; float f=0; Console::WriteLine(i + f); Console::ReadKey(); return 0; } 1
  66. 66. Console (Types Conversion) // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { int i=1; String ^str=i.ToString(); Console::WriteLine(str); Console::ReadKey(); return 0; }
  67. 67. Console // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { int i=1; String ^str=i.ToString(); Console::WriteLine(str); Console::ReadKey(); return 0; } 1
  68. 68. Console // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { String ^str="1123"; int i=Int32::Parse(str); i++; Console::WriteLine(i); Console::ReadKey(); return 0; }
  69. 69. Console // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { String ^str="1123"; int i=Int32::Parse(str); i++; Console::WriteLine(i); Console::ReadKey(); return 0; } 1124
  70. 70. Console // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { String ^str="1123"; int i=0; Int32::TryParse(str,i); i++; Console::WriteLine(i); Console::ReadKey(); return 0; }
  71. 71. Console // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { String ^str="1123"; int i=0; Int32::TryParse(str,i); i++; Console::WriteLine(i); Console::ReadKey(); return 0; } 1124
  72. 72. Console // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { String ^str="1123ccccc"; int i=0; Int32::TryParse(str,i); i++; Console::WriteLine(i); Console::ReadKey(); return 0; }
  73. 73. Console // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { String ^str="1123ccccc"; int i=0; Int32::TryParse(str,i); i++; Console::WriteLine(i); Console::ReadKey(); return 0; } 1
  74. 74. Arrays
  75. 75. Arrays • Defining an array of string with dimension of 3 public : array <String^ , 3 > ^MyArr;
  76. 76. Arrays • Defining an array of string with dimension of 3 public : array <String^ , 3 > ^MyArr; • Everything okay? public : array <String^ , 3 > MyArr; public : array <String , 3 > ^MyArr; Both are Compiler Errors!
  77. 77. Arrays • Sth wrong? array <String ^ , 1 > ^MyArr; MyArr[0][0]="1"; Compiler error array <String ^ , 1 > ^MyArr; MyArr[0]=1; Compiler error array <String ^ , 2> ^MyArr; MyArr=gcnew array <String^ , 2 > (100,50); MyArr[0,0]="1"; Everything is good
  78. 78. Arrays • Sth wrong? array <String ^ , 2> ^MyArr; MyArr=gcnew array <String^ > (100,50); MyArr[0,0]="1"; Compiler error array <String ^ , 2> ^MyArr; MyArr=gcnew array <String^ , 2 > (100,50); MyArr[0][0]="1"; Compiler error array <String ^ , 2> ^MyArr; MyArr=gcnew array <String^ , 2 > (100)(50); MyArr[0,0]="1"; Compiler error
  79. 79. Arrays • Sth wrong? array <String ^> ^MyArr; MyArr=gcnew array <String^ > (50); MyArr[0]="1"; Everything is good
  80. 80. Arrays
  81. 81. Arrays // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { array <String ^ , 1 > ^MyArr; MyArr[0]="1"; Console::ReadKey(); return 0; }
  82. 82. Arrays // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { array <String ^ , 1 > ^MyArr; MyArr[0]="1"; Console::ReadKey(); return 0; } Ntn wrong!
  83. 83. Arrays // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { array <String ^ , 1 > ^MyArr; MyArr[0]="1"; Console::ReadKey(); return 0; } Ntn wrong!
  84. 84. Arrays // CppdotNetConsoleCourseTest.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { array <String ^ , 1 > ^MyArr; MyArr[0]="1"; Console::ReadKey(); return 0; } Ntn wrong!
  85. 85. Arrays • Considering that we have a class named “CELL” array <CELL^ , 2> ^MyArr; MyArr=gcnew array <CELL^ , 2 > (100,50); CELL ^MyCell=gcnew CELL; MyArr[0,0]=MyCell;
  86. 86. Arrays • Considering that we have a class named “CELL” array <CELL^ , 2> ^MyArr; MyArr=gcnew array <CELL^ , 2 > (100,50); CELL ^MyCell=gcnew CELL; MyArr[0,0]=MyCell;
  87. 87. That’s it for today!

×