SlideShare una empresa de Scribd logo
1 de 119
Descargar para leer sin conexión
C++.NET
Windows Forms Course
L06-Utility

Mohammad Shaker
mohammadshakergtr.wordpress.com
C++.NET Windows Forms Course
@ZGTRShaker
How to work with OOP in
.NET
How to work with OOP in .NET
• Structure of Form class
• Adding variables
– Public
– Private

• Adding member functions
– Procedural

• Adding classes by “ref”
• Passing parameters
– %,^
.NET
.NET
Debugging
Debugging – Break Point
Debugging
Debugging
Debugging
Debugging
references  declarations  definitions
Searching in msdn
DateTime class
DateTime
DateTime
private: System::Void button1_Click(System::Object^
System::EventArgs^ e)
{
DateTime D;
textBox1->Text= D.Day.ToString();
};

sender,

1

private: System::Void button1_Click(System::Object^
System::EventArgs^ e)
{
DateTime D;
D.Now;
textBox1->Text= D.Day.ToString();
};
1

sender,
DateTime
private: System::Void button1_Click(System::Object^
System::EventArgs^ e)
{
DateTime D;
D.Now;
textBox1->Text= D.Now.Day.ToString();
};
9

sender,
DateTime Constructor
DateTime Methods
DateTime
DateTime
DateTime
DateTime
DateTime
• Considering today is 22/10/2010, the output will be
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^
{
// Calculate what day of the week is 36 days from this instant
DateTime ^today= DateTime::Now;
TimeSpan duration(36, 0, 0, 0);
DateTime ^answer= today->Add(duration);
textBox1->Text= answer->ToString();
}

11/27/2010 1:49:12 AM

e)
DateTime
DateTime date1= gcnew DateTime::Now;
DateTime date2= gcnew DateTime::UtcNow;
DateTime date3= gcnew DateTime::Today;
Utc: Coordinated Universal Time

private: System::Void button1_Click(System::Object^
System::EventArgs^ e)
{
DateTime ^Day= gcnew DateTime(2010, 10, 6);
textBox1->Text= Day->ToString();
}
10/6/2010 12:00:00 AM

sender,
DateTime
private: System::Void button1_Click(System::Object^
System::EventArgs^ e)
{
DateTime ^Day= gcnew DateTime(2010, 10, 6);
textBox1->Text= Day->ToLongTimeString();
}

sender,

12:00:00 AM
private: System::Void button1_Click(System::Object^
System::EventArgs^ e)
{
DateTime ^Day= gcnew DateTime(2010, 10, 6);
textBox1->Text= Day->ToLongDateString();
}
Wednesday, October 06, 2010

sender,
DateTime
private: System::Void button1_Click(System::Object^
System::EventArgs^ e)
{
DateTime ^Day= gcnew DateTime(2010, 10, 6);
textBox1->Text= Day->ToShortDateString();
}

sender,

10/6/2010
private: System::Void button1_Click(System::Object^
System::EventArgs^ e)
{
DateTime ^Day= gcnew DateTime(2010, 10, 6);
textBox1->Text= Day->ToShortTimeString();
}

12:00 AM

sender,
DateTime
private: System::Void button1_Click(System::Object^
System::EventArgs^ e)
{
DateTime ^Day= gcnew DateTime(2010, 10, 6);
textBox1->Text= Day >ToString();
}

sender,

10/6/2010 12:00:00 AM
private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e)
{
DateTime ^Day= gcnew DateTime(2010, 10, 6);
textBox1->Text= Day->ToLocalTime().ToString();
}
10/6/2010 3:00:00 AM
DateTime
int window= 10;
int freq= 60 * 60 * 2; // 2 hours;
DateTime d1= DateTime.Now;
DateTime
DateTime
DateTime
DateTime

d2=
d3=
d4=
d5=

d1->AddSeconds(2 * window);
d1->AddSeconds(-2 * window);
d1->AddSeconds(window / 2);
d1->AddSeconds(-window / 2);

DateTime
DateTime
DateTime
DateTime

d6=
d7=
d8=
d9=

(d1.AddHours(2))->AddSeconds(2 * window);
(d1.AddHours(2))->AddSeconds(-2 * window);
(d1.AddHours(2))->AddSeconds(window / 2);
(d1.AddHours(2))->AddSeconds(-window / 2);

Console.WriteLine("d1
Console.WriteLine("d1
Console.WriteLine("d1
Console.WriteLine("d1
Console.WriteLine("d1

({0})
({0})
({0})
({0})
({0})

~=
~=
~=
~=
~=

d1
d2
d3
d4
d5

({1}):
({1}):
({1}):
({1}):
({1}):

{2}“,
{2}",
{2}",
{2}",
{2}",

d1,
d1,
d1,
d1,
d1,

d1,
d2,
d3,
d4,
d5,

RoughlyEquals(d1,
RoughlyEquals(d1,
RoughlyEquals(d1,
RoughlyEquals(d1,
RoughlyEquals(d1,

d1,
d2,
d3,
d4,
d5,

window,
window,
window,
window,
window,

freq));
freq));
freq));
freq));
freq));

Console.WriteLine("d1
Console.WriteLine("d1
Console.WriteLine("d1
Console.WriteLine("d1

({0})
({0})
({0})
({0})

~=
~=
~=
~=

d6
d7
d8
d9

({1}):
({1}):
({1}):
({1}):

{2}",
{2}",
{2}",
{2}",

d1,
d1,
d1,
d1,

d6,
d7,
d8,
d9,

RoughlyEquals(d1,
RoughlyEquals(d1,
RoughlyEquals(d1,
RoughlyEquals(d1,

d6,
d7,
d8,
d9,

window,
window,
window,
window,

freq));
freq));
freq));
freq));
Properties
Properties
• A compromise between a function and a variable!
• See, the following, how awesome!
private:
int MyInt;
public:
// property block
property int intProperty
{
int get()
{
return MyInt;
}
void set(int value)
{
MyInt= value;
}
}
Properties
The property keyword
introduces the
declaration of a
property and can
appear in a class,
interface, or value
type. A property can
have a getter function
(read only), a setter
function (write only),
or both (read-write).

public:
int MyInt;
// property block
property int intProperty
{
int get()
{
return MyInt;
}
void set(int value)
{
MyInt= value;
}
}
Properties
• So, how to use it? Like the following …
property int intProperty
{
int get()
{
return MyInt;
}
void set(int value)
{
MyInt= value;
}
}
private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e)
{
textBox1->Text= intProperty.ToString();
}
Properties
Properties
• So, how to use it? Like the following …
property int intProperty
{
int get()
{
return MyInt;
}
void set(int value)
{
MyInt= value;
}
}

private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e)
{
intProperty= 5;
textBox1->Text= intProperty.ToString();
}
Properties
Properties
int MyInt;
// property block
property int intProperty
{
int get()
{
return MyInt;
}
void set(int value)
{
MyInt= value;
}
}
private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e)
{
intProperty= 5;
textBox1->Text= intProperty.ToString();
intProperty= 14;
textBox1->Text += " " + intProperty.ToString();
}
Properties
Properties
int MyInt;
// property block
property int intProperty
{
int get()
{
MessageBox::Show("You are lucky to know the property
before others:P:D");
return MyInt;
}
void set(int value)
{
MyInt= value;
}
}
#pragma endregion
private: System::Void button1_Click(System::Object^
System::EventArgs^ e)
{
intProperty= 5;
textBox1->Text= intProperty.ToString();
}

sender,
Properties
Properties
int MyInt;
// property block
property int intProperty
{
int get()
{
return MyInt;
Note where it is!
MessageBox::Show("You are lucky to know the property
before others:P:D");
}
void set(int value)
{
MyInt= value;
}
}
#pragma endregion
private: System::Void button1_Click(System::Object^
System::EventArgs^ e)
{
intProperty= 5;
textBox1->Text= intProperty.ToString();
}

sender,
Properties
No message box
stringint Conversion
stringint Conversion
• NewLine:
– Environment::NewLine;

• Converting from string to int:
– Int32::Parse(textBox1->Text);

– Int32::TryParse(textBox1->Text);
stringint Conversion
• Converting from int to string:
– Exp #1:
• int x;
• textBox1->Text= x.ToString();

– Exp #2:
• int ^;
x
• textBox1->Text= x->ToString();

– Exp #3:
• int ^;
x
• String ^S= x->ToString();
stringint Conversion
private: System::Void button1_Click_1(System::Object^
System::EventArgs^ e)
{
int i= 3;
i= int::Parse(textBox1->Text);
}

What happens if we have “435345” in textBox1?
What happens if we have “wewe” in textBox1?
What happens if we have “213s” in textBox1?
What happens if we have “” in textBox1?

sender,
stringint Conversion
private: System::Void button1_Click_1(System::Object^
System::EventArgs^ e)
{
int i= 3;
i= int::TryParse(textBox1->Text, i ;
}

What happens if we have “435345” in textBox1?
What happens if we have “wewe” in textBox1?
What happens if we have “213s” in textBox1?
What happens if we have “” in textBox1?

sender,
Files!
The Concept
Working with Files
• using!
using namespace System::IO;
using namespace System::IO;
void FileManipulate::PrintTextFile ()
{
String ^FilePath = "D:HashFile.Txt" ;
FileStream ^MyFile = gcnew FileStream(FilePath, FileMode::Open);
StreamReader ^SR = gcnew StreamReader(MyFile);
String ^str="" ;
// Extracting words
while(SR->Peek() > -1)
{
str = SR->ReadLine();
MyForm->textBox1->Text += str + Environment::NewLine ;
}
MyFile->Close();
}
using namespace System::IO;
void FileManipulate::PrintTextFile ()
{
String ^FilePath = "D:HashFile.Txt" ;
FileStream ^MyFile = gcnew FileStream ;

StreamReader ^SR = gcnew StreamReader(MyFile);
String ^str="" ;
// Extracting words
while(SR->Peek() > -1)
{
str = SR->ReadLine();
MyForm->textBox1->Text += str + Environment::NewLine ;
}
MyFile->Close();
}

Compiler error
FileStream ^MyFile = gcnew FileStream(FilePath, FileMode::Open);
Working with Files
private: System::Void Form1_Load(System::Object^ sender,
System::EventArgs^ e)
{
SaveFileDialog ^Dialog = gcnew SaveFileDialog();
FileStream ^MyFC ;
String ^FilePath = "" ;
if (Dialog->ShowDialog() ==
System::Windows::Forms::DialogResult::OK)
{
FilePath = Dialog->FileName ;
}
Working with Files
MyFC = File::Create(FilePath) ;
MyFC->Close();
MyFC = File::Open(FilePath ,FileMode::Append );
StreamWriter ^SW = gcnew StreamWriter(MyFC);
SW->WriteLine("I AM ZGTR");
SW->WriteLine("I AM ALWAYS ZGTR");
SW->Close();
MyFC->Close();
MyFC = File::Open(FilePath ,FileMode::Open );
StreamReader ^SR = gcnew StreamReader(MyFC);
String ^str="" ;
// Extracting words
while(SR->Peek() > -1)
{
str = SR->ReadLine();
this->textBox1->Text += str + Environment::NewLine ;
}
MyFC->Close();
}
Working with Files
MyFC = File::Create(FilePath) ;
MyFC->Close();
MyFC = File::Open(FilePath ,FileMode::Append );
StreamWriter ^SW = gcnew StreamWriter(MyFC);
while (textBox1->Text!= “000”)
{ SW-> WriteLine(textBox2->Text) ;}
SW->Close();
MyFC->Close();
MyFC = File::Open(FilePath ,FileMode::Open );
StreamReader ^SR = gcnew StreamReader(MyFC);
String ^str="" ;
// Extracting words
while(SR->Peek() > -1)
{
str = SR->ReadLine();
this->textBox1->Text += str + Environment::NewLine ;
}
MyFC->Close();
}
Working with Files
Working with Files
Live test
Use the console to trackdebug values!
Do not use messagebox for tracking!
Change between Console and
Windows Form
• In the project properties for all configurations (Project |
Properties, choose Configuration 'All Configurations', locate
Config Properties -> Linker -> System), change the SubSystem
from Console to Windows.
Change between Console and
Windows Form
Change between Console and
Windows Form
Change between Console and
Windows Form
Project output type example
• Let’s have the following design
Project output type example
• And the following code-behind
Project output type example
• After setting the project output to “console”, Run
Project output type example
• Now, press the button multiple times and there you go!
Creating You Own Windows
Forms Control (C++)
http://msdn.microsoft.com/en-us/library/vstudio/ms235628(v=vs.100).aspx
Peak on Exception Handling
try, catch, throw and finally
Peak on Exception Handling
• Test it live!
private: System::Void panel1_MouseClick(System::Object^ sender,
System::Windows::Forms::MouseEventArgs^ e)
{
try
{
if (textBox1->text == “Hi”)
{
MessageBox::Show(“It’s time for Exceptions! ");
}
}
catch (System::FormatException ^e)
{
MessageBox::Show("You Should Enter a String in textBox first ");
}
}
C++.NET
Windows Forms Course
Strings

Mohammad Shaker
mohammadshakergtr.wordpress.com
C++.NET Windows Forms Course
@ZGTRShaker
Welcome!
Strings in Action
Strings in Action
-> and ::
Strings in Action
• Let’s have the following form …
Strings in Action
• What happens?
private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e)
{
int i = 3;
i++;
String ^Str = textBox1->Text;
String ^TempStr =String::Format("{0}{1}{2}" , Str , "What?" ,
i.ToString());
textBox2->Text += TempStr;
}
Strings in Action
Strings in Action
private: System::Void button1_Click(System::Object^
sender, System::EventArgs^ e)
{
int i = 3;
i++;
String ^Str = textBox1->Text;
String ^TempStr = String::Format("{0}{1} Go! {2}" , Str ,
" What? " , i.ToString());
textBox2->Text += TempStr;
}
Strings in Action
Strings in Action
• Is it okay?
private: System::Void button1_Click(System::Object^
sender, System::EventArgs^ e)
{
int i = 3;
i++;
String ^Str = textBox1->Text;
String ^TempStr = String::Format("{0}{1} Go! {2}" , Str ,
" What? " , i);
textBox2->Text += TempStr;
}
Strings in Action
String Operations by Category
Strings in Action
• Comparing Strings (int):
– Compare :
• returns an integer that indicates the relationship of one string to a
second string in the sort order.
Strings in Action
Value

Condition

Less than zero

strA is less than strB.

Zero

strA equals strB.

Greater than zero

strA is greater than strB.
Strings in Action
private: System::Void button1_Click(System::Object^
sender, System::EventArgs^ e)
{
String ^str1 = "I Wanna go!";
String ^str2 = "I decided not to go!";
int i = String::Compare(str1,str2);
textBox1->Text = i.ToString();
}
Strings in Action
• Testing Strings for Equality (bool):
– You call the Equals method to determine whether two strings are
equal.
Strings in Action
private: System::Void button1_Click(System::Object^
System::EventArgs^ e)
{
String ^str1 = "I Wanna go!";
String ^str2 = "I decided not to go!";
bool b= String::Equals(str1,str2);
textBox1->Text = b.ToString();
}

sender,
Strings in Action

private: System::Void button1_Click(System::Object^
System::EventArgs^ e)
{
String ^str1 = "I Wanna go!";
String ^str2 = "I Wanna go!";
bool b = String::Equals(str1,str2);
textBox1->Text = b.ToString();
}

true

sender,
Strings in Action

private: System::Void button1_Click(System::Object^
System::EventArgs^ e)
{
String ^str1 = "I Wanna go!";
String ^str2 = "I Wanna go! ";
bool b = String::Equals(str1,str2);
textBox1->Text = b.ToString();
}

false

sender,
Strings in Action
• Finding Characters in a String :
– The String class includes two kinds of search methods:
• Methods that return a “ bool” value to indicate whether a particular
substring is present in a string instance. These include
the Contains, EndsWith, and StartsWith methods.
• Methods that indicate the starting position of a substring in a string
instance “int”. These include the IndexOf,IndexOfAny, LastIndexOf,
and LastIndexOfAny methods.
Strings in Action
• String::Contains Method (bool)
– Returns a value indicating whether the specified String object occurs
within this string.
Strings in Action
{
String^ s1 = "The brown fox jumps over the lazy dog";
String^ s2 = "fox";
bool b;
b = s1->Contains( s2 );
Console::WriteLine( "Is the string, s2, in the string, s1?: {0}", b );
}
Is string , s2, in string, s1? True
Strings in Action
• String::IndexOf Method (int)
– Reports the index of the first occurrence of one or more characters,
or the first occurrence of a string, within this string.
– This member is overloaded. For complete information about this
member, including syntax, usage, and examples, click a name in the
overload list.
Name

IndexOf(Char)
IndexOf(String)
IndexOf(Char, Int32)

Description

Reports the index of the first occurrence of the specified Unicode character in this
string.
Reports the index of the first occurrence of the specified string in this instance.

Reports the index of the first occurrence of the specified Unicode character in this
string. The search starts at a specified character position.
IndexOf(String, Int32) Reports the index of the first occurrence of the specified string in this instance.
The search starts at a specified character position.
IndexOf(String,
Reports the index of the first occurrence of the specified string in the
StringComparison)
current Stringobject. A parameter specifies the type of search to use for the
specified string.
IndexOf(Char, Int32,
Reports the index of the first occurrence of the specified character in this
Int32)
instance. The search starts at a specified character position and examines a
specified number of character positions.
IndexOf(String, Int32, Reports the index of the first occurrence of the specified string in this instance.
Int32)
The search starts at a specified character position and examines a specified number
of character positions.
IndexOf(String, Int32, Reports the index of the first occurrence of the specified string in the
StringComparison)
current Stringobject. Parameters specify the starting search position in the current
string and the type of search to use for the specified string.
IndexOf(String, Int32, Reports the index of the first occurrence of the specified string in the
Int32, StringComparison) current Stringobject. Parameters specify the starting search position in the current
string, the number of characters in the current string to search, and the type of
search to use for the specified string.
int main(array<System::String ^> ^args)
{
Console::WriteLine(L"Hello World");
// Create a Unicode String with 5 Greek Alpha characters
String^ szGreekAlpha = gcnew String( L'x0319',5 );

// Create a Unicode String with a Greek Omega character
wchar_t charArray5[3] = {L'x03A9',L'x03A9',L'x03A9'};
String^ szGreekOmega = gcnew String( charArray5,2,1 );
String^ szGreekLetters = String::Concat( szGreekOmega, szGreekAlpha, szGreekOmega>Clone() );
// Examine the result
Console::WriteLine( szGreekLetters );
// The first index of Alpha
int ialpha = szGreekLetters->IndexOf( L'x0319' );
// The last index of Omega
int iomega = szGreekLetters->LastIndexOf( L'x03A9' );
Console::WriteLine( String::Concat( "The Greek letter Alpha first appears at
index ", Convert::ToString( ialpha ) ) );
Console::WriteLine( String::Concat( " and Omega last appears at index ",
Convert::ToString( iomega ), " in this String." ) );
return 0;
}
Strings in Action

Hello World
Ω?????Ω

The Greek letter Alpha first appears at index 1
and Omega last appears at index 6 in this String.
Press any key to continue . . .
Strings in Action–Trim() method
• String::Trim Method
– Removes all leading and trailing white-space characters from the
current String object.
int main()
{
String^ animal1 = "fox";
String^ animal2 = "dog";
String^ strTarget = String::Format( "The {0} jumped over the {1}.", animal1, animal2 );

Console::WriteLine
( "The original string is:{0}{1}{0}", Environment::NewLine, strTarget );
Console::Write
( "Enter an adjective (or group of adjectives) to describe the {0}: ==> ", animal1 );
String^ adj1 = Console::ReadLine();

Console::Write
( "Enter an adjective (or group of adjectives) to describe the {0}: ==> ", animal2 );
String^ adj2 = Console::ReadLine();
adj1 = String::Concat( adj1->Trim(), " " );
adj2 = String::Concat( adj2->Trim(), " " );
strTarget = strTarget->Insert( strTarget->IndexOf( animal1 ), adj1 );
strTarget = strTarget->Insert( strTarget->IndexOf( animal2 ), adj2 );
Console::WriteLine
( " {0}The final string is: {0} {1}", Environment::NewLine, strTarget );
}
Strings in Action
The original string is:
The fox jumped over the dog.
Enter an adjective (or group of adjectives) to describe the fox: ==>
bold

Enter an adjective (or group of adjectives) to describe the dog: ==>
lazy
The final string is:
The bold fox jumped over the lazy dog.
Strings in Action
private: System::Void button1_Click(System::Object^
System::EventArgs^ e)
{
String ^str1 = "I Wanna go!";
String ^str2 = "I DeciDEd not to go!";
str2 = str2->ToLower();
textBox1->Text = str2;
}

sender,
Strings in Action
private: System::Void button1_Click(System::Object^
System::EventArgs^ e)
{
String ^str1 = "I Wanna go!";
String ^str2 = "I decided not to go!
";
str2 = (str2->ToLower())->Trim() ;
textBox1->Text = str2+str1;
}

sender,
Strings in Action
private: System::Void button1_Click(System::Object^
System::EventArgs^ e)
{
String ^str1 = "I Wanna go!";
String ^str2 = “
I DeCided not to go! ";
str2 = (str2->ToLower())->Trim() ;
textBox1->Text = str2;
}

sender,
Strings in Action
• String::Copy Method (String to String)
– Creates a new instance of String with the same value as a specified String.
// Sample for String::Copy()
using namespace System;
int main()
{
String^ str1 = "abc";
String^ str2 = "xyz";
Console::WriteLine( "1) str1 = '{0}'",
Console::WriteLine( "2) str2 = '{0}'",
Console::WriteLine( "Copy..." );
str2 = String::Copy( str1 );
Console::WriteLine( "3) str1 = '{0}'",
Console::WriteLine( "4) str2 = '{0}'",
}
1) str1
2) str2
Copy...
3) str1
4) str2

= 'abc'
= 'xyz'
= 'abc'
= 'abc'

str1 );
str2 );

str1 );
str2 );
Strings in Action
• String::CopyTo Method (String)
– Copies a specified number of characters from a specified position in
this instance to a specified position in an array of Unicode characters.
Strings in Action
• Parameters
– sourceIndexType: System::Int32
The index of the first character in this instance to copy.
– destinationType: array<System::Char>
An array of Unicode characters to which characters in this instance
are copied.
– destinationIndexType: System::Int32
The index in destination at which the copy operation begins.

– countType: System::Int32
The number of characters in this instance to copy to destination.
using namespace System;
int main()
{
// Embed an array of characters in a string
String^ strSource = "changed";
array <Char> ^destination = {'T','h','e',' ','i','n','i','t','i','a','l','
','a','r','r','a','y'};
// Print the char array
Console::WriteLine( destination );
// Embed the source string in the destination string
strSource->CopyTo( 0, destination, 4, strSource->Length );
// Print the resulting array
Console::WriteLine( destination );
strSource = "A different string";
// Embed only a section of the source string in the destination
strSource->CopyTo( 2, destination, 3, 9 );
// Print the resulting array
Console::WriteLine( destination );
}
Strings in Action

The initial array
The changed array
Thedifferentarray
Press any key to continue . . .
Strings in Action
• String::Replace Method (String , String)
– Returns a new string in which all occurrences of a specified string in
the current instance are replaced with another specified string.
Strings in Action
using namespace System;
int main()
{
String^ errString = "This docment uses 3 other docments to docment the
docmentation";
Console::WriteLine( "The original string is:n'{0}'n", errString );
// Correct the spelling of S"document".
String^ correctString = errString->Replace( "docment", "document" );
Console::WriteLine( "After correcting the string, the result is:n'{0}'",
correctString );
}

This code example produces the following output:
The original string is:
'This docment uses 3 other docments to docment the docmentation'
After correcting the string, the result is:
'This document uses 3 other documents to document the documentation'
SubString()
SubString()
private: System::Void button1_Click(System::Object^
System::EventArgs^ e)
{
String ^str1 = "I Wanna go!";
String ^str2 = "I decided not to go! ";
String ^TempStr = "";
TempStr = str2->Substring(3);
textBox1->Text = TempStr;
}

sender,
SubString()
private: System::Void button1_Click(System::Object^
System::EventArgs^ e)
{
String ^str1 = "I Wanna go!";
String ^str2 = "I decided not to go! ";
String ^TempStr = "";
TempStr = str2->Substring(3,3);
textBox1->Text = TempStr;
}

sender,
That’s it for today!

Más contenido relacionado

La actualidad más candente

DOM-based Test Adequacy Criteria for Web Applications
DOM-based Test Adequacy Criteria for Web ApplicationsDOM-based Test Adequacy Criteria for Web Applications
DOM-based Test Adequacy Criteria for Web Applications
SALT Lab @ UBC
 

La actualidad más candente (20)

C++ Windows Forms L08 - GDI P1
C++ Windows Forms L08 - GDI P1 C++ Windows Forms L08 - GDI P1
C++ Windows Forms L08 - GDI P1
 
.net progrmming part4
.net progrmming part4.net progrmming part4
.net progrmming part4
 
The Ring programming language version 1.8 book - Part 7 of 202
The Ring programming language version 1.8 book - Part 7 of 202The Ring programming language version 1.8 book - Part 7 of 202
The Ring programming language version 1.8 book - Part 7 of 202
 
The Ring programming language version 1.5.2 book - Part 7 of 181
The Ring programming language version 1.5.2 book - Part 7 of 181The Ring programming language version 1.5.2 book - Part 7 of 181
The Ring programming language version 1.5.2 book - Part 7 of 181
 
The Ring programming language version 1.5.3 book - Part 7 of 184
The Ring programming language version 1.5.3 book - Part 7 of 184The Ring programming language version 1.5.3 book - Part 7 of 184
The Ring programming language version 1.5.3 book - Part 7 of 184
 
The Ring programming language version 1.5.1 book - Part 6 of 180
The Ring programming language version 1.5.1 book - Part 6 of 180The Ring programming language version 1.5.1 book - Part 6 of 180
The Ring programming language version 1.5.1 book - Part 6 of 180
 
VB Dot net
VB Dot net VB Dot net
VB Dot net
 
The Ring programming language version 1.5.1 book - Part 13 of 180
The Ring programming language version 1.5.1 book - Part 13 of 180The Ring programming language version 1.5.1 book - Part 13 of 180
The Ring programming language version 1.5.1 book - Part 13 of 180
 
The Ring programming language version 1.3 book - Part 83 of 88
The Ring programming language version 1.3 book - Part 83 of 88The Ring programming language version 1.3 book - Part 83 of 88
The Ring programming language version 1.3 book - Part 83 of 88
 
The Ring programming language version 1.7 book - Part 7 of 196
The Ring programming language version 1.7 book - Part 7 of 196The Ring programming language version 1.7 book - Part 7 of 196
The Ring programming language version 1.7 book - Part 7 of 196
 
Exploring Clojurescript
Exploring ClojurescriptExploring Clojurescript
Exploring Clojurescript
 
The Ring programming language version 1.5.3 book - Part 6 of 184
The Ring programming language version 1.5.3 book - Part 6 of 184The Ring programming language version 1.5.3 book - Part 6 of 184
The Ring programming language version 1.5.3 book - Part 6 of 184
 
DOM-based Test Adequacy Criteria for Web Applications
DOM-based Test Adequacy Criteria for Web ApplicationsDOM-based Test Adequacy Criteria for Web Applications
DOM-based Test Adequacy Criteria for Web Applications
 
Comparing JVM languages
Comparing JVM languagesComparing JVM languages
Comparing JVM languages
 
Testing in Python: doctest and unittest
Testing in Python: doctest and unittestTesting in Python: doctest and unittest
Testing in Python: doctest and unittest
 
Testing in Python: doctest and unittest (Updated)
Testing in Python: doctest and unittest (Updated)Testing in Python: doctest and unittest (Updated)
Testing in Python: doctest and unittest (Updated)
 
Lesson11
Lesson11Lesson11
Lesson11
 
Python 3.6 Features 20161207
Python 3.6 Features 20161207Python 3.6 Features 20161207
Python 3.6 Features 20161207
 
Kotlin Bytecode Generation and Runtime Performance
Kotlin Bytecode Generation and Runtime PerformanceKotlin Bytecode Generation and Runtime Performance
Kotlin Bytecode Generation and Runtime Performance
 
Introduction to Apache Flink
Introduction to Apache FlinkIntroduction to Apache Flink
Introduction to Apache Flink
 

Similar a C++ Windows Forms L06 - Utlitity and Strings

Python-GTK
Python-GTKPython-GTK
Python-GTK
Yuren Ju
 
Python Interview Questions | Python Interview Questions And Answers | Python ...
Python Interview Questions | Python Interview Questions And Answers | Python ...Python Interview Questions | Python Interview Questions And Answers | Python ...
Python Interview Questions | Python Interview Questions And Answers | Python ...
Simplilearn
 
Introduction To Csharp
Introduction To CsharpIntroduction To Csharp
Introduction To Csharp
g_hemanth17
 
Introduction to-csharp-1229579367461426-1
Introduction to-csharp-1229579367461426-1Introduction to-csharp-1229579367461426-1
Introduction to-csharp-1229579367461426-1
Sachin Singh
 
Introduction to CSharp
Introduction to CSharpIntroduction to CSharp
Introduction to CSharp
Mody Farouk
 
Introduction to csharp
Introduction to csharpIntroduction to csharp
Introduction to csharp
Raga Vahini
 
Introduction to csharp
Introduction to csharpIntroduction to csharp
Introduction to csharp
Satish Verma
 
Introduction to csharp
Introduction to csharpIntroduction to csharp
Introduction to csharp
singhadarsh
 
Gae icc fall2011
Gae icc fall2011Gae icc fall2011
Gae icc fall2011
Juan Gomez
 
Introduction To Csharp
Introduction To CsharpIntroduction To Csharp
Introduction To Csharp
sarfarazali
 
Introduction to c#
Introduction to c#Introduction to c#
Introduction to c#
singhadarsh
 
Python GTK (Hacking Camp)
Python GTK (Hacking Camp)Python GTK (Hacking Camp)
Python GTK (Hacking Camp)
Yuren Ju
 

Similar a C++ Windows Forms L06 - Utlitity and Strings (20)

Python-GTK
Python-GTKPython-GTK
Python-GTK
 
Creating a Facebook Clone - Part XXXI - Transcript.pdf
Creating a Facebook Clone - Part XXXI - Transcript.pdfCreating a Facebook Clone - Part XXXI - Transcript.pdf
Creating a Facebook Clone - Part XXXI - Transcript.pdf
 
Python Interview Questions | Python Interview Questions And Answers | Python ...
Python Interview Questions | Python Interview Questions And Answers | Python ...Python Interview Questions | Python Interview Questions And Answers | Python ...
Python Interview Questions | Python Interview Questions And Answers | Python ...
 
Classes and objects1
Classes and objects1Classes and objects1
Classes and objects1
 
Introduction To Csharp
Introduction To CsharpIntroduction To Csharp
Introduction To Csharp
 
Introduction to-csharp-1229579367461426-1
Introduction to-csharp-1229579367461426-1Introduction to-csharp-1229579367461426-1
Introduction to-csharp-1229579367461426-1
 
Introduction to CSharp
Introduction to CSharpIntroduction to CSharp
Introduction to CSharp
 
Introduction to csharp
Introduction to csharpIntroduction to csharp
Introduction to csharp
 
Introduction to csharp
Introduction to csharpIntroduction to csharp
Introduction to csharp
 
Introduction to csharp
Introduction to csharpIntroduction to csharp
Introduction to csharp
 
Chapter iii(oop)
Chapter iii(oop)Chapter iii(oop)
Chapter iii(oop)
 
Clean Code: Chapter 3 Function
Clean Code: Chapter 3 FunctionClean Code: Chapter 3 Function
Clean Code: Chapter 3 Function
 
.NET F# Events
.NET F# Events.NET F# Events
.NET F# Events
 
Gae icc fall2011
Gae icc fall2011Gae icc fall2011
Gae icc fall2011
 
Notes on c++
Notes on c++Notes on c++
Notes on c++
 
Lecture 4. mte 407
Lecture 4. mte 407Lecture 4. mte 407
Lecture 4. mte 407
 
Introduction To Csharp
Introduction To CsharpIntroduction To Csharp
Introduction To Csharp
 
Introduction to c#
Introduction to c#Introduction to c#
Introduction to c#
 
Writing a compiler in go
Writing a compiler in goWriting a compiler in go
Writing a compiler in go
 
Python GTK (Hacking Camp)
Python GTK (Hacking Camp)Python GTK (Hacking Camp)
Python GTK (Hacking Camp)
 

Más de Mohammad Shaker

Más de Mohammad Shaker (20)

12 Rules You Should to Know as a Syrian Graduate
12 Rules You Should to Know as a Syrian Graduate12 Rules You Should to Know as a Syrian Graduate
12 Rules You Should to Know as a Syrian Graduate
 
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
 
Interaction Design L06 - Tricks with Psychology
Interaction Design L06 - Tricks with PsychologyInteraction Design L06 - Tricks with Psychology
Interaction Design L06 - Tricks with Psychology
 
Short, Matters, Love - Passioneers Event 2015
Short, Matters, Love -  Passioneers Event 2015Short, Matters, Love -  Passioneers Event 2015
Short, Matters, Love - Passioneers Event 2015
 
Unity L01 - Game Development
Unity L01 - Game DevelopmentUnity L01 - Game Development
Unity L01 - Game Development
 
Android L07 - Touch, Screen and Wearables
Android L07 - Touch, Screen and WearablesAndroid L07 - Touch, Screen and Wearables
Android L07 - Touch, Screen and Wearables
 
Interaction Design L03 - Color
Interaction Design L03 - ColorInteraction Design L03 - Color
Interaction Design L03 - Color
 
Interaction Design L05 - Typography
Interaction Design L05 - TypographyInteraction Design L05 - Typography
Interaction Design L05 - Typography
 
Interaction Design L04 - Materialise and Coupling
Interaction Design L04 - Materialise and CouplingInteraction Design L04 - Materialise and Coupling
Interaction Design L04 - Materialise and Coupling
 
Android L05 - Storage
Android L05 - StorageAndroid L05 - Storage
Android L05 - Storage
 
Android L04 - Notifications and Threading
Android L04 - Notifications and ThreadingAndroid L04 - Notifications and Threading
Android L04 - Notifications and Threading
 
Android L09 - Windows Phone and iOS
Android L09 - Windows Phone and iOSAndroid L09 - Windows Phone and iOS
Android L09 - Windows Phone and iOS
 
Interaction Design L01 - Mobile Constraints
Interaction Design L01 - Mobile ConstraintsInteraction Design L01 - Mobile Constraints
Interaction Design L01 - Mobile Constraints
 
Interaction Design L02 - Pragnanz and Grids
Interaction Design L02 - Pragnanz and GridsInteraction Design L02 - Pragnanz and Grids
Interaction Design L02 - Pragnanz and Grids
 
Android L10 - Stores and Gaming
Android L10 - Stores and GamingAndroid L10 - Stores and Gaming
Android L10 - Stores and Gaming
 
Android L06 - Cloud / Parse
Android L06 - Cloud / ParseAndroid L06 - Cloud / Parse
Android L06 - Cloud / Parse
 
Android L08 - Google Maps and Utilities
Android L08 - Google Maps and UtilitiesAndroid L08 - Google Maps and Utilities
Android L08 - Google Maps and Utilities
 
Android L03 - Styles and Themes
Android L03 - Styles and Themes Android L03 - Styles and Themes
Android L03 - Styles and Themes
 
Android L02 - Activities and Adapters
Android L02 - Activities and AdaptersAndroid L02 - Activities and Adapters
Android L02 - Activities and Adapters
 
Android L01 - Warm Up
Android L01 - Warm UpAndroid L01 - Warm Up
Android L01 - Warm Up
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

C++ Windows Forms L06 - Utlitity and Strings

  • 1. C++.NET Windows Forms Course L06-Utility Mohammad Shaker mohammadshakergtr.wordpress.com C++.NET Windows Forms Course @ZGTRShaker
  • 2. How to work with OOP in .NET
  • 3. How to work with OOP in .NET • Structure of Form class • Adding variables – Public – Private • Adding member functions – Procedural • Adding classes by “ref” • Passing parameters – %,^
  • 12. references declarations definitions
  • 13.
  • 15.
  • 18. DateTime private: System::Void button1_Click(System::Object^ System::EventArgs^ e) { DateTime D; textBox1->Text= D.Day.ToString(); }; sender, 1 private: System::Void button1_Click(System::Object^ System::EventArgs^ e) { DateTime D; D.Now; textBox1->Text= D.Day.ToString(); }; 1 sender,
  • 19. DateTime private: System::Void button1_Click(System::Object^ System::EventArgs^ e) { DateTime D; D.Now; textBox1->Text= D.Now.Day.ToString(); }; 9 sender,
  • 26. DateTime • Considering today is 22/10/2010, the output will be private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ { // Calculate what day of the week is 36 days from this instant DateTime ^today= DateTime::Now; TimeSpan duration(36, 0, 0, 0); DateTime ^answer= today->Add(duration); textBox1->Text= answer->ToString(); } 11/27/2010 1:49:12 AM e)
  • 27. DateTime DateTime date1= gcnew DateTime::Now; DateTime date2= gcnew DateTime::UtcNow; DateTime date3= gcnew DateTime::Today; Utc: Coordinated Universal Time private: System::Void button1_Click(System::Object^ System::EventArgs^ e) { DateTime ^Day= gcnew DateTime(2010, 10, 6); textBox1->Text= Day->ToString(); } 10/6/2010 12:00:00 AM sender,
  • 28. DateTime private: System::Void button1_Click(System::Object^ System::EventArgs^ e) { DateTime ^Day= gcnew DateTime(2010, 10, 6); textBox1->Text= Day->ToLongTimeString(); } sender, 12:00:00 AM private: System::Void button1_Click(System::Object^ System::EventArgs^ e) { DateTime ^Day= gcnew DateTime(2010, 10, 6); textBox1->Text= Day->ToLongDateString(); } Wednesday, October 06, 2010 sender,
  • 29. DateTime private: System::Void button1_Click(System::Object^ System::EventArgs^ e) { DateTime ^Day= gcnew DateTime(2010, 10, 6); textBox1->Text= Day->ToShortDateString(); } sender, 10/6/2010 private: System::Void button1_Click(System::Object^ System::EventArgs^ e) { DateTime ^Day= gcnew DateTime(2010, 10, 6); textBox1->Text= Day->ToShortTimeString(); } 12:00 AM sender,
  • 30. DateTime private: System::Void button1_Click(System::Object^ System::EventArgs^ e) { DateTime ^Day= gcnew DateTime(2010, 10, 6); textBox1->Text= Day >ToString(); } sender, 10/6/2010 12:00:00 AM private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { DateTime ^Day= gcnew DateTime(2010, 10, 6); textBox1->Text= Day->ToLocalTime().ToString(); } 10/6/2010 3:00:00 AM
  • 31. DateTime int window= 10; int freq= 60 * 60 * 2; // 2 hours; DateTime d1= DateTime.Now; DateTime DateTime DateTime DateTime d2= d3= d4= d5= d1->AddSeconds(2 * window); d1->AddSeconds(-2 * window); d1->AddSeconds(window / 2); d1->AddSeconds(-window / 2); DateTime DateTime DateTime DateTime d6= d7= d8= d9= (d1.AddHours(2))->AddSeconds(2 * window); (d1.AddHours(2))->AddSeconds(-2 * window); (d1.AddHours(2))->AddSeconds(window / 2); (d1.AddHours(2))->AddSeconds(-window / 2); Console.WriteLine("d1 Console.WriteLine("d1 Console.WriteLine("d1 Console.WriteLine("d1 Console.WriteLine("d1 ({0}) ({0}) ({0}) ({0}) ({0}) ~= ~= ~= ~= ~= d1 d2 d3 d4 d5 ({1}): ({1}): ({1}): ({1}): ({1}): {2}“, {2}", {2}", {2}", {2}", d1, d1, d1, d1, d1, d1, d2, d3, d4, d5, RoughlyEquals(d1, RoughlyEquals(d1, RoughlyEquals(d1, RoughlyEquals(d1, RoughlyEquals(d1, d1, d2, d3, d4, d5, window, window, window, window, window, freq)); freq)); freq)); freq)); freq)); Console.WriteLine("d1 Console.WriteLine("d1 Console.WriteLine("d1 Console.WriteLine("d1 ({0}) ({0}) ({0}) ({0}) ~= ~= ~= ~= d6 d7 d8 d9 ({1}): ({1}): ({1}): ({1}): {2}", {2}", {2}", {2}", d1, d1, d1, d1, d6, d7, d8, d9, RoughlyEquals(d1, RoughlyEquals(d1, RoughlyEquals(d1, RoughlyEquals(d1, d6, d7, d8, d9, window, window, window, window, freq)); freq)); freq)); freq));
  • 33. Properties • A compromise between a function and a variable! • See, the following, how awesome! private: int MyInt; public: // property block property int intProperty { int get() { return MyInt; } void set(int value) { MyInt= value; } }
  • 34. Properties The property keyword introduces the declaration of a property and can appear in a class, interface, or value type. A property can have a getter function (read only), a setter function (write only), or both (read-write). public: int MyInt; // property block property int intProperty { int get() { return MyInt; } void set(int value) { MyInt= value; } }
  • 35. Properties • So, how to use it? Like the following … property int intProperty { int get() { return MyInt; } void set(int value) { MyInt= value; } } private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { textBox1->Text= intProperty.ToString(); }
  • 37. Properties • So, how to use it? Like the following … property int intProperty { int get() { return MyInt; } void set(int value) { MyInt= value; } } private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { intProperty= 5; textBox1->Text= intProperty.ToString(); }
  • 39. Properties int MyInt; // property block property int intProperty { int get() { return MyInt; } void set(int value) { MyInt= value; } } private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { intProperty= 5; textBox1->Text= intProperty.ToString(); intProperty= 14; textBox1->Text += " " + intProperty.ToString(); }
  • 41. Properties int MyInt; // property block property int intProperty { int get() { MessageBox::Show("You are lucky to know the property before others:P:D"); return MyInt; } void set(int value) { MyInt= value; } } #pragma endregion private: System::Void button1_Click(System::Object^ System::EventArgs^ e) { intProperty= 5; textBox1->Text= intProperty.ToString(); } sender,
  • 43. Properties int MyInt; // property block property int intProperty { int get() { return MyInt; Note where it is! MessageBox::Show("You are lucky to know the property before others:P:D"); } void set(int value) { MyInt= value; } } #pragma endregion private: System::Void button1_Click(System::Object^ System::EventArgs^ e) { intProperty= 5; textBox1->Text= intProperty.ToString(); } sender,
  • 46. stringint Conversion • NewLine: – Environment::NewLine; • Converting from string to int: – Int32::Parse(textBox1->Text); – Int32::TryParse(textBox1->Text);
  • 47. stringint Conversion • Converting from int to string: – Exp #1: • int x; • textBox1->Text= x.ToString(); – Exp #2: • int ^; x • textBox1->Text= x->ToString(); – Exp #3: • int ^; x • String ^S= x->ToString();
  • 48. stringint Conversion private: System::Void button1_Click_1(System::Object^ System::EventArgs^ e) { int i= 3; i= int::Parse(textBox1->Text); } What happens if we have “435345” in textBox1? What happens if we have “wewe” in textBox1? What happens if we have “213s” in textBox1? What happens if we have “” in textBox1? sender,
  • 49. stringint Conversion private: System::Void button1_Click_1(System::Object^ System::EventArgs^ e) { int i= 3; i= int::TryParse(textBox1->Text, i ; } What happens if we have “435345” in textBox1? What happens if we have “wewe” in textBox1? What happens if we have “213s” in textBox1? What happens if we have “” in textBox1? sender,
  • 51. Working with Files • using! using namespace System::IO;
  • 52. using namespace System::IO; void FileManipulate::PrintTextFile () { String ^FilePath = "D:HashFile.Txt" ; FileStream ^MyFile = gcnew FileStream(FilePath, FileMode::Open); StreamReader ^SR = gcnew StreamReader(MyFile); String ^str="" ; // Extracting words while(SR->Peek() > -1) { str = SR->ReadLine(); MyForm->textBox1->Text += str + Environment::NewLine ; } MyFile->Close(); }
  • 53. using namespace System::IO; void FileManipulate::PrintTextFile () { String ^FilePath = "D:HashFile.Txt" ; FileStream ^MyFile = gcnew FileStream ; StreamReader ^SR = gcnew StreamReader(MyFile); String ^str="" ; // Extracting words while(SR->Peek() > -1) { str = SR->ReadLine(); MyForm->textBox1->Text += str + Environment::NewLine ; } MyFile->Close(); } Compiler error FileStream ^MyFile = gcnew FileStream(FilePath, FileMode::Open);
  • 54. Working with Files private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { SaveFileDialog ^Dialog = gcnew SaveFileDialog(); FileStream ^MyFC ; String ^FilePath = "" ; if (Dialog->ShowDialog() == System::Windows::Forms::DialogResult::OK) { FilePath = Dialog->FileName ; }
  • 55. Working with Files MyFC = File::Create(FilePath) ; MyFC->Close(); MyFC = File::Open(FilePath ,FileMode::Append ); StreamWriter ^SW = gcnew StreamWriter(MyFC); SW->WriteLine("I AM ZGTR"); SW->WriteLine("I AM ALWAYS ZGTR"); SW->Close(); MyFC->Close(); MyFC = File::Open(FilePath ,FileMode::Open ); StreamReader ^SR = gcnew StreamReader(MyFC); String ^str="" ; // Extracting words while(SR->Peek() > -1) { str = SR->ReadLine(); this->textBox1->Text += str + Environment::NewLine ; } MyFC->Close(); }
  • 56. Working with Files MyFC = File::Create(FilePath) ; MyFC->Close(); MyFC = File::Open(FilePath ,FileMode::Append ); StreamWriter ^SW = gcnew StreamWriter(MyFC); while (textBox1->Text!= “000”) { SW-> WriteLine(textBox2->Text) ;} SW->Close(); MyFC->Close(); MyFC = File::Open(FilePath ,FileMode::Open ); StreamReader ^SR = gcnew StreamReader(MyFC); String ^str="" ; // Extracting words while(SR->Peek() > -1) { str = SR->ReadLine(); this->textBox1->Text += str + Environment::NewLine ; } MyFC->Close(); }
  • 57.
  • 60. Use the console to trackdebug values! Do not use messagebox for tracking!
  • 61. Change between Console and Windows Form • In the project properties for all configurations (Project | Properties, choose Configuration 'All Configurations', locate Config Properties -> Linker -> System), change the SubSystem from Console to Windows.
  • 62. Change between Console and Windows Form
  • 63. Change between Console and Windows Form
  • 64. Change between Console and Windows Form
  • 65. Project output type example • Let’s have the following design
  • 66. Project output type example • And the following code-behind
  • 67. Project output type example • After setting the project output to “console”, Run
  • 68. Project output type example • Now, press the button multiple times and there you go!
  • 69. Creating You Own Windows Forms Control (C++) http://msdn.microsoft.com/en-us/library/vstudio/ms235628(v=vs.100).aspx
  • 70. Peak on Exception Handling try, catch, throw and finally
  • 71. Peak on Exception Handling • Test it live! private: System::Void panel1_MouseClick(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) { try { if (textBox1->text == “Hi”) { MessageBox::Show(“It’s time for Exceptions! "); } } catch (System::FormatException ^e) { MessageBox::Show("You Should Enter a String in textBox first "); } }
  • 72. C++.NET Windows Forms Course Strings Mohammad Shaker mohammadshakergtr.wordpress.com C++.NET Windows Forms Course @ZGTRShaker
  • 76. Strings in Action • Let’s have the following form …
  • 77. Strings in Action • What happens? private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { int i = 3; i++; String ^Str = textBox1->Text; String ^TempStr =String::Format("{0}{1}{2}" , Str , "What?" , i.ToString()); textBox2->Text += TempStr; }
  • 79. Strings in Action private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { int i = 3; i++; String ^Str = textBox1->Text; String ^TempStr = String::Format("{0}{1} Go! {2}" , Str , " What? " , i.ToString()); textBox2->Text += TempStr; }
  • 81. Strings in Action • Is it okay? private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { int i = 3; i++; String ^Str = textBox1->Text; String ^TempStr = String::Format("{0}{1} Go! {2}" , Str , " What? " , i); textBox2->Text += TempStr; }
  • 84. Strings in Action • Comparing Strings (int): – Compare : • returns an integer that indicates the relationship of one string to a second string in the sort order.
  • 85.
  • 86. Strings in Action Value Condition Less than zero strA is less than strB. Zero strA equals strB. Greater than zero strA is greater than strB.
  • 87. Strings in Action private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { String ^str1 = "I Wanna go!"; String ^str2 = "I decided not to go!"; int i = String::Compare(str1,str2); textBox1->Text = i.ToString(); }
  • 88. Strings in Action • Testing Strings for Equality (bool): – You call the Equals method to determine whether two strings are equal.
  • 89.
  • 90.
  • 91. Strings in Action private: System::Void button1_Click(System::Object^ System::EventArgs^ e) { String ^str1 = "I Wanna go!"; String ^str2 = "I decided not to go!"; bool b= String::Equals(str1,str2); textBox1->Text = b.ToString(); } sender,
  • 92. Strings in Action private: System::Void button1_Click(System::Object^ System::EventArgs^ e) { String ^str1 = "I Wanna go!"; String ^str2 = "I Wanna go!"; bool b = String::Equals(str1,str2); textBox1->Text = b.ToString(); } true sender,
  • 93. Strings in Action private: System::Void button1_Click(System::Object^ System::EventArgs^ e) { String ^str1 = "I Wanna go!"; String ^str2 = "I Wanna go! "; bool b = String::Equals(str1,str2); textBox1->Text = b.ToString(); } false sender,
  • 94. Strings in Action • Finding Characters in a String : – The String class includes two kinds of search methods: • Methods that return a “ bool” value to indicate whether a particular substring is present in a string instance. These include the Contains, EndsWith, and StartsWith methods. • Methods that indicate the starting position of a substring in a string instance “int”. These include the IndexOf,IndexOfAny, LastIndexOf, and LastIndexOfAny methods.
  • 95. Strings in Action • String::Contains Method (bool) – Returns a value indicating whether the specified String object occurs within this string.
  • 96. Strings in Action { String^ s1 = "The brown fox jumps over the lazy dog"; String^ s2 = "fox"; bool b; b = s1->Contains( s2 ); Console::WriteLine( "Is the string, s2, in the string, s1?: {0}", b ); } Is string , s2, in string, s1? True
  • 97. Strings in Action • String::IndexOf Method (int) – Reports the index of the first occurrence of one or more characters, or the first occurrence of a string, within this string. – This member is overloaded. For complete information about this member, including syntax, usage, and examples, click a name in the overload list.
  • 98. Name IndexOf(Char) IndexOf(String) IndexOf(Char, Int32) Description Reports the index of the first occurrence of the specified Unicode character in this string. Reports the index of the first occurrence of the specified string in this instance. Reports the index of the first occurrence of the specified Unicode character in this string. The search starts at a specified character position. IndexOf(String, Int32) Reports the index of the first occurrence of the specified string in this instance. The search starts at a specified character position. IndexOf(String, Reports the index of the first occurrence of the specified string in the StringComparison) current Stringobject. A parameter specifies the type of search to use for the specified string. IndexOf(Char, Int32, Reports the index of the first occurrence of the specified character in this Int32) instance. The search starts at a specified character position and examines a specified number of character positions. IndexOf(String, Int32, Reports the index of the first occurrence of the specified string in this instance. Int32) The search starts at a specified character position and examines a specified number of character positions. IndexOf(String, Int32, Reports the index of the first occurrence of the specified string in the StringComparison) current Stringobject. Parameters specify the starting search position in the current string and the type of search to use for the specified string. IndexOf(String, Int32, Reports the index of the first occurrence of the specified string in the Int32, StringComparison) current Stringobject. Parameters specify the starting search position in the current string, the number of characters in the current string to search, and the type of search to use for the specified string.
  • 99. int main(array<System::String ^> ^args) { Console::WriteLine(L"Hello World"); // Create a Unicode String with 5 Greek Alpha characters String^ szGreekAlpha = gcnew String( L'x0319',5 ); // Create a Unicode String with a Greek Omega character wchar_t charArray5[3] = {L'x03A9',L'x03A9',L'x03A9'}; String^ szGreekOmega = gcnew String( charArray5,2,1 ); String^ szGreekLetters = String::Concat( szGreekOmega, szGreekAlpha, szGreekOmega>Clone() ); // Examine the result Console::WriteLine( szGreekLetters ); // The first index of Alpha int ialpha = szGreekLetters->IndexOf( L'x0319' ); // The last index of Omega int iomega = szGreekLetters->LastIndexOf( L'x03A9' ); Console::WriteLine( String::Concat( "The Greek letter Alpha first appears at index ", Convert::ToString( ialpha ) ) ); Console::WriteLine( String::Concat( " and Omega last appears at index ", Convert::ToString( iomega ), " in this String." ) ); return 0; }
  • 100. Strings in Action Hello World Ω?????Ω The Greek letter Alpha first appears at index 1 and Omega last appears at index 6 in this String. Press any key to continue . . .
  • 101. Strings in Action–Trim() method • String::Trim Method – Removes all leading and trailing white-space characters from the current String object.
  • 102. int main() { String^ animal1 = "fox"; String^ animal2 = "dog"; String^ strTarget = String::Format( "The {0} jumped over the {1}.", animal1, animal2 ); Console::WriteLine ( "The original string is:{0}{1}{0}", Environment::NewLine, strTarget ); Console::Write ( "Enter an adjective (or group of adjectives) to describe the {0}: ==> ", animal1 ); String^ adj1 = Console::ReadLine(); Console::Write ( "Enter an adjective (or group of adjectives) to describe the {0}: ==> ", animal2 ); String^ adj2 = Console::ReadLine(); adj1 = String::Concat( adj1->Trim(), " " ); adj2 = String::Concat( adj2->Trim(), " " ); strTarget = strTarget->Insert( strTarget->IndexOf( animal1 ), adj1 ); strTarget = strTarget->Insert( strTarget->IndexOf( animal2 ), adj2 ); Console::WriteLine ( " {0}The final string is: {0} {1}", Environment::NewLine, strTarget ); }
  • 103. Strings in Action The original string is: The fox jumped over the dog. Enter an adjective (or group of adjectives) to describe the fox: ==> bold Enter an adjective (or group of adjectives) to describe the dog: ==> lazy The final string is: The bold fox jumped over the lazy dog.
  • 104. Strings in Action private: System::Void button1_Click(System::Object^ System::EventArgs^ e) { String ^str1 = "I Wanna go!"; String ^str2 = "I DeciDEd not to go!"; str2 = str2->ToLower(); textBox1->Text = str2; } sender,
  • 105. Strings in Action private: System::Void button1_Click(System::Object^ System::EventArgs^ e) { String ^str1 = "I Wanna go!"; String ^str2 = "I decided not to go! "; str2 = (str2->ToLower())->Trim() ; textBox1->Text = str2+str1; } sender,
  • 106. Strings in Action private: System::Void button1_Click(System::Object^ System::EventArgs^ e) { String ^str1 = "I Wanna go!"; String ^str2 = “ I DeCided not to go! "; str2 = (str2->ToLower())->Trim() ; textBox1->Text = str2; } sender,
  • 107. Strings in Action • String::Copy Method (String to String) – Creates a new instance of String with the same value as a specified String. // Sample for String::Copy() using namespace System; int main() { String^ str1 = "abc"; String^ str2 = "xyz"; Console::WriteLine( "1) str1 = '{0}'", Console::WriteLine( "2) str2 = '{0}'", Console::WriteLine( "Copy..." ); str2 = String::Copy( str1 ); Console::WriteLine( "3) str1 = '{0}'", Console::WriteLine( "4) str2 = '{0}'", } 1) str1 2) str2 Copy... 3) str1 4) str2 = 'abc' = 'xyz' = 'abc' = 'abc' str1 ); str2 ); str1 ); str2 );
  • 108. Strings in Action • String::CopyTo Method (String) – Copies a specified number of characters from a specified position in this instance to a specified position in an array of Unicode characters.
  • 109. Strings in Action • Parameters – sourceIndexType: System::Int32 The index of the first character in this instance to copy. – destinationType: array<System::Char> An array of Unicode characters to which characters in this instance are copied. – destinationIndexType: System::Int32 The index in destination at which the copy operation begins. – countType: System::Int32 The number of characters in this instance to copy to destination.
  • 110. using namespace System; int main() { // Embed an array of characters in a string String^ strSource = "changed"; array <Char> ^destination = {'T','h','e',' ','i','n','i','t','i','a','l',' ','a','r','r','a','y'}; // Print the char array Console::WriteLine( destination ); // Embed the source string in the destination string strSource->CopyTo( 0, destination, 4, strSource->Length ); // Print the resulting array Console::WriteLine( destination ); strSource = "A different string"; // Embed only a section of the source string in the destination strSource->CopyTo( 2, destination, 3, 9 ); // Print the resulting array Console::WriteLine( destination ); }
  • 111.
  • 112. Strings in Action The initial array The changed array Thedifferentarray Press any key to continue . . .
  • 113. Strings in Action • String::Replace Method (String , String) – Returns a new string in which all occurrences of a specified string in the current instance are replaced with another specified string.
  • 114. Strings in Action using namespace System; int main() { String^ errString = "This docment uses 3 other docments to docment the docmentation"; Console::WriteLine( "The original string is:n'{0}'n", errString ); // Correct the spelling of S"document". String^ correctString = errString->Replace( "docment", "document" ); Console::WriteLine( "After correcting the string, the result is:n'{0}'", correctString ); } This code example produces the following output: The original string is: 'This docment uses 3 other docments to docment the docmentation' After correcting the string, the result is: 'This document uses 3 other documents to document the documentation'
  • 116.
  • 117. SubString() private: System::Void button1_Click(System::Object^ System::EventArgs^ e) { String ^str1 = "I Wanna go!"; String ^str2 = "I decided not to go! "; String ^TempStr = ""; TempStr = str2->Substring(3); textBox1->Text = TempStr; } sender,
  • 118. SubString() private: System::Void button1_Click(System::Object^ System::EventArgs^ e) { String ^str1 = "I Wanna go!"; String ^str2 = "I decided not to go! "; String ^TempStr = ""; TempStr = str2->Substring(3,3); textBox1->Text = TempStr; } sender,
  • 119. That’s it for today!