Here the good code for C#!!!! :)

New Boston (https://www.youtube.com/channel/UCJbPGzawDH1njbqV-D5HqKw-https://thenewboston.com/) is an excellent site to learn programming.Author -me- has used these site  during his studies to learn C#.In the follow lines is presented the code of the first 100 C#  lectures. During the year will be presented the next 100 lectures.Enjoy it!! 🙂

//*******************NEW BOSTON C#:11 ***********************
//ONE BUTTON IS NEEDED
//Array is a special variable which accept multiple variables

//a)
private void button1_Click(object sender,EventArgs e)
{

//Array is a special variable which accept multiple variables
string[] Names={“Adam”,”Bob,”Joe”};
MessageBox.Show(Names[0]); //Declare the element of array
}

}
}

//b)
private void button1_Click(object sender,EventArgs e)
{

//Second way
string[] Names=new string[5] ;
Names[0]=”Joe”;
MessageBox.Show(Names[0]); //Declare the element of array
}

}
}

//c)
private void button1_Click(object sender,EventArgs e)
{

//Numbers
int[] numbers={555,111,777} ;
MessageBox.Show(numbers[0].ToString()); //Declare the element of array
}

}
}
//**************************NEW BOSTON C#:12***************

private void button1_Click(object sender, EventArgs e)
{
List<string> Names = new List<string>(); //Standard syntax
Names.Add(“Adam”); //Has one string
MessageBox.Show(Names[0]);
}
}
}

b)
//second way

//****************************NEW BOSTON C#:14************************
A)

private void button1_Click(object sender, EventArgs e)
{
int i = 0;
while (i < 10)
{
textBox1.Text += i.ToString();
i++;

}

}
B)
private void button1_Click(object sender, EventArgs e)
{
int i = 0;
do
{
textBox1.Text+=i.ToString();
i++;
}
while (i<10);
}

//*************************************NEW BOSTON C#:15****************
private void button1_Click(object sender, EventArgs e)
{
{
try
{
string[] names = new string[2];
string s = names[0];//If i change the value with the same of new string it will give me other result
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
MessageBox.Show(“Your code is done”);

}
}
*******************************************************************************************************
******************************************NEW BOSTON C#:16***********
namespace NB_16
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
Message(“Adam”, “Hello”);
}
void Message(string message, string title)
{
MessageBox.Show(message, title);
}

private void button2_Click(object sender, EventArgs e)
{
Message(“Bob”, “Hello”);
}
}
}
*******************************************************************************************************************************************
*******************New Boston 21:Access Midifiers and Static**********
//It is needed to make a class with name “MyClass.cs” & form1.cs
//A button

——————————————————————–
myfile

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using NB_21;

namespace NB_21
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
MyClass.ShowMessage(“Adam”);
}
}
}

—————————————————————————————–
//MyClass

using NB_21;

namespace NB_21
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
MyClass.ShowMessage(“Adam”);
}
}
}
————————————-

********************************************************************************************************************************************
namespace NB_26
{
class MyClass
{
private string Name = “Bob”;
protected int Age = 10;
public virtual void ShowMessage(string Message)
{
System.Windows.Forms.MessageBox.Show(Message);
}
}
class MySecondClass : MyClass, MyInterface
{
public string HairColor = “Brown”;
public override void ShowMessage(string Message)
{
System.Windows.Forms.MessageBox.Show(Message, “My title”);
}
public void MyVoid()
{
base.ShowMessage(“My Void”);
}
}

interface MyInterface
{
void MyVoid();
}
}

///////////////////////////////////////////////////////////////////////////////////////////////

namespace NB_26
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
MySecondClass msc = new MySecondClass();
msc.MyVoid();
}
}
}
****************************************************************************************************************************
*************************************************NB-29*************

namespace MyNamespace
{
partial class MyClass
{
public string Name=”Mr. Smith”;
public int Age=38;
partial void Message(string message);

///////////////////////////////////////////////////////
//Form1.cs

namespace Youtube
{
public partial class form1:form
{
public form1()
{
InitializeComponent();
}
private void button1_Click(object sender,(EventArgs e))
{
MyClass mc=new MyClass();
mc.ShowMessage(“Adam”);
/////////////////////////////////////////////
namespace MyNamespace
{
partial class MycLass
{
public string HairColor=”Brown”;
public bool Glasses=false;
partial void Message(string message)
{
System.Windows.forms.MessageBox.Show(message);
}
public void ShowMessage(string message)
}
{
Message(message);}
}
}

*********************************************NB-30***********
//ONE BUTTON IS NEEDED

namespace NB_30
{
abstract class MyClass
{
public static string Name = “Adam”;
public static int Age = 15;
public static void Message(string message)
{
System.Windows.Forms.MessageBox.Show(message);

}
public abstract void ShowMessage(string message);
}

class MySecondClass : MyClass
{
public override void ShowMessage(string message)
{
System.Windows.Forms.MessageBox.Show(message);
}
}
}
************************************************NB-31 Delegate**************
//ONE BUTTON IS NEEDED

//MycClass.cs
class MyClass
{

//Delegate pass the same parametres the same time
delegate void MyDelegate(string myString); //Declare delegate
public void ShowThoseMessages()
{
MyDelegate md = new MyDelegate(ShowMessage);
md += ShowAnotherMessage;
md(“Adam”);
}
void ShowAnotherMessage(string message)
{
System.Windows.Forms.MessageBox.Show(message);
}

void ShowMessage(string a)
{

System.Windows.Forms.MessageBox.Show(a, “Test”);
}
}
}
///////////////////////////////////////////////////////////////////////////
//form1.cs
namespace YouTube
{
public partial class form1:form
{
public form1()
{
InitializeComponent();
}
private void buuton1_Click(object sender,EventArgs e)
{
MyClass mc=new MyClass();
mc.ShowThoseMessages();

}
}
}
***************************************************NB-32*************

//MyClass.cs

class MyClass
{
public event EventHandler OnPropertyChanged;
string name;=””;
public string Name
{
get {return name;}
set
{
name=value;
OnPropertyChanged(this,new EventArgs()));
}
}
}
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////

//form1.cs

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
MyClass mc = new MyClass();
mc.OnPropertyChanged += new EventHandler(mc_OnPropertyChanged);
mc.Name = “Adam”;
}
void mc_OnPropertyChanged(object sender, EventArgs e)
{
MessageBox.Show(“The property has changed”);
}
}
}
*****************************************************NB-33***************

//One checkbox and a button is needed
//Ternary operator
private void button1_Click(object sender, EventArgs e)
{
private void button1_Click(object sender, EventArgs e)
{
// string myString=””;
//if (checkBox1.Checked) myString=”it’s checked”;
//else myString=”it’s not checked”;
//All the above is done with the code in the next line….
MessageBox.Show((checkBox1.Checked)? “It’s checked.”:”It’s not checked”);
// .. ? : Ternary operators
}
}
}
*****************************************************NB-34********************************************************
//a
private void button1_Click(object sender,EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
}
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////

private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
MessageBox.Show(“Test”);
}
}
}
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////

c)
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = ” Open Image”;
ofd.Filter = “PNG Image |*.png|BIK|.bik”;
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
MessageBox.Show(ofd.SafeFileName);
}
}
}
}

***************************************************NB-35c******************
****************************************************NB-36*********
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
StreamReader sr = new StreamReader(File.OpenRead(ofd.FileName));
textBox1.Text = sr.ReadToEnd();

}
}
***************************************************NB-37a*********

//It is need it a text box and a button

SOS It is no needed to add Openfile
a)

private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
StreamReader sr = new StreamReader(File.OpenRead(ofd.FileName));
textBox1.Text = sr.BaseStream.Readbyte().ToString();
sr.Dispose();
}

}
}
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
b)private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
StreamReader sr = new StreamReader(File.OpenRead(ofd.FileName));
byte[] buffer = new byte[3];
sr.BaseStream.Read(buffer, 0, 3);
foreach (byte mybyte in buffer)
textBox1.Text += mybyte.ToString(“x”)+””;
sr.Dispose();
}

}
}
}
c)
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
StreamReader sr = new StreamReader(File.OpenRead(ofd.FileName));
sr.BaseStream.Position=4;
byte[] buffer = new byte[3];
sr.BaseStream.Read(buffer, 0, 3);
foreach (byte mybyte in buffer)
textBox1.Text += mybyte.ToString(“x”)+””;
sr.Dispose();
}

*********************************************NB-38 Streamreader 3*********************************
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
StreamReader sr = new StreamReader(ofd.FileName);
//0
char c = (char)sr.Peek(); //0
char c1 = (char)sr.Read();//1
char c2 = (char)sr.Read();
MessageBox.Show(c.ToString() + “:” + c1.ToString() + “:” + c2.ToString());
}
}
}
}
**********************************************NB-39 StreamWriter 1*********************************************

a)
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string path;

private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == DialogResult.OK)
{
button2.Enabled = true;
path = ofd.FileName;

}
}

private void button2_Click(object sender, EventArgs e)
{
StreamWriter sw = new StreamWriter(File.Create(path));
sw.Write(textBox1.Text);
sw.Dispose();

}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
B)
string path;
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == DialogResult.OK)
{
button2.Enabled = true;
path = ofd.FileName;

}
}

private void button2_Click(object sender, EventArgs e)
{
StreamWriter sw = new StreamWriter(File.Create(path));
sw.Write(textBox1.Text);
sw.WriteLine(“This is the second line”);
sw.Dispose();
}
}
}

************************************NB-40 Streawriter-2************
namespace NB_40
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string path;
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == DialogResult.OK)
{
button2.Enabled = true;
path = ofd.FileName;

}
}

private void button2_Click(object sender, EventArgs e)
{

StreamWriter sw = new StreamWriter(File.OpenWrite(path));
sw.BaseStream.WriteByte(0x00);
sw.Dispose();
}
}
}

*********************NB-41:BinaryReader*****************
using System.IO;

//a
namespace NB_41
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string path;
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == DialogResult.OK)
{
button2.Enabled = true;
path = ofd.FileName;
}
}

private void button2_Click(object sender, EventArgs e)
{
BinaryReader br= new BinaryReader(File.OpenRead(path));
br.BaseStream.Position = 0x10;
textBox1.Text = br.ReadChar().ToString();

}
}
}
///////////////////////////////////////////////////////////////////////////////////////////

b)
//Read characters
private void button2_Click(object sender, EventArgs e)
{
BinaryReader br= new BinaryReader(File.OpenRead(path));
br.BaseStream.Position = 0x10;
foreach (char myChar in br.ReadChars(4)) textBox1.Text +=myChar;
br.Dispose();

}
}
}

//////////////////////////////////////////////////////////////////////////////////////////////
c) private void button2_Click(object sender, EventArgs e)
{
BinaryReader br= new BinaryReader(File.OpenRead(path));
br.BaseStream.Position = 0x1f;
textBox1.Text =br.ReadInt16().ToString(“X”);
br.Dispose();

}
}
}

**************************************NB-42**********

a )
private void button2_Click(object sender, EventArgs e)
{
BinaryReader br = new BinaryReader(File.OpenRead(path));
br.BaseStream.Position = 0x1f;
byte[] buffer = br.Readbytes(2);
Array.Reverse(buffer);
textBox1.Text = BitConverter.ToInt16(buffer, 0).ToString(“X”);
br.Dispose();
}

}
}

b)
string path;

private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == DialogResult.OK)
{
button2.Enabled = true;
path = ofd.FileName;
}
}

private void button2_Click(object sender, EventArgs e)
{
BinaryReader br = new BinaryReader(File.OpenRead(path));
br.BaseStream.Position = 0x11;
byte[] buffer = br.Readbytes(4);
Array.Reverse(buffer);
buffer = BitConverter.GetBytes(4312);
br.Dispose();
}
}
********************************************************NB C#43*******
string path;

private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == DialogResult.OK)
{
button2.Enabled = true;
path = ofd.FileName;
}
}

private void button2_Click(object sender,EventArgs e)
{
BinaryWriter bw = new BinaryWriter(File.OpenWrite(path));
bw.Write(‘C’); //try some values to parenthesis
bw.Dispose();
}
}
}

b)
BinaryWriter bw =new BinaryWriter(File.OpenWrite(path));
short myShort=1;
byte[] buffer=BitConverter.GetBytes(myShort);
Array.Reverse(buffer);
bw.Write(buffer);
bw.Dispose();
}
}
}

***********************************NB C# 44******************

private void button1_Click(object sender, EventArgs e)
{
/*
SaveFileDialog sfd = new SaveFileDialog();
if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string path = sfd.FileName;
BinaryWriter bw = new BinaryWriter(File.Create(path));
bw.Write(“Example text file”);
bw.Dispose();
*/

SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter=”Text File.txt” ;
if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string path = sfd.FileName;
BinaryWriter bw = new BinaryWriter(File.Create(path));
bw.Write(“Example text file”);
bw.Dispose();
}
}
}
}

*************************************** NB C# 45**********
private void button1_Click(object sender, EventArgs e)
{
/*
a)
int myInt = Convert.ToInt32(textBox1.Text);
MessageBox.Show(myInt.ToString());

b)
char c = Convert.ToChar(textBox1.Text);
MessageBox.Show(c.ToString());

c)
bool myBool = Convert.ToBoolean(textBox1.Text);
MessageBox.Show(myBool.ToString());

*/

try
{
bool myBool = Convert.ToBoolean(textBox1.Text);
MessageBox.Show(myBool.ToString());
}

catch
{
MessageBox.Show(“The conversion failed”);
}

}
}
}
******************************** NB C# 46***************

private void button1_Click(object sender, EventArgs e)
{

/*
* a)
int myInt = Convert.ToInt32(textBox1.Text);
MessageBox.Show(myInt.ToString());
*
*
*/
/*
* b)
char c = Convert.ToChar(textBox1.Text);
MessageBox.Show(c.ToString());
*
*/ c)
try
{
bool myBool = Convert.ToBoolean(textBox1.Text);
MessageBox.Show(myBool.ToString());
}
catch
{
MessageBox.Show(“The conversion failed”);

}

}

}

}
****************************NB C# 47 *****************************

private void button1_Click(object sender, EventArgs e)
{
/*
* a)
object myObj = “Adam”;
if (myObj is string) MessageBox.Show((string)myObj);
*
*
//b
Control myControl = button1;
if (myControl is Button)
{
Button myButton = (Button)myControl;
MessageBox.Show(myButton.Text);
*
// c)
Control myControl=button1;
if (myControl is Button)
{
Button myButton = myControl as Button;
MessageBox.Show(myButton.Text);

**/

//d)
Control myControl =button1;
object myObj=”Hello”;
if (myObj is string)
{
string myString = myObj as string;
MessageBox.Show(myString);

}
}
}
}

*********************** NB C# 48******************************

private void button1_Click(object sender, EventArgs e)
{

/*
a)

int myInt = Convert.ToInt32(textBox1.Text);
MessageBox.Show(myInt.ToString());

b)

char c = Convert.ToChar(textBox1.Text);
MessageBox.Show(c.ToString());
*

bool myBool = Convert.ToBoolean(textBox1.Text);
MessageBox.Show(myBool.ToString());

**/

try
{
bool myBool = Convert.ToBoolean(textBox1.Text);
MessageBox.Show(myBool.ToString());
}
catch {MessageBox.Show(“The conversion failed”);}
}
}
}
************************ NB-49:Substring *******************************
private void button1_Click(object sender, EventArgs e)
{

/*
* a)
string Name = “John Sith”;
string FirstNmae = Name.Substring(0, 4);//0,4 are the positions
MessageBox.Show(FirstName);
*/

string Name = “John Sith”;
string LastName = Name.Substring(5, 4); //are positions
MessageBox.Show(LastName);

}
**************************NB-50:IndexOf and Trim*********************
private void button1_Click(object sender, EventArgs e)
{
/*
*
//a)

string name = “John Smith”;
string FirstName=name.Substring(0, name.IndexOf(‘ ‘));
MessageBox.Show(FirstName);
*

//b)

string name = “John Smith”;
string FirstName = name.Substring(0, name.IndexOf(‘ ‘)+1);
MessageBox.Show(FirstName);
*

//c
*
string name = ” John Smith “;
string readName = name.Trim();
MessageBox.Show(name);

*/
string name = ” John Smith “;
string readName = name.Trim();
MessageBox.Show(readName);
}
}
}
********************************NB-51******************
private void button1_Click(object sender, EventArgs e)
{

/* a)
string sentence = “Hello, my name is Smith.”;
string after = sentence.Remove(0, 7); //Here is the remove method
MessageBox.Show(after);

b)
string sentence = “Hello, my name is Adam.”;
string after = sentence.Remove(18);
MessageBox.Show(after);

c)
string sentence = “Hello, my name is Smith.”;
string after = sentence.Replace(“Helo”,”Hi”); //Here is the replace method
MessageBox.Show(after);
*/
string sentence = “Hello, my name is Smith.”;
string after = sentence.Replace(‘l’, ‘s’); //Here is the replace method
MessageBox.Show(after);

}

***************************** NB-52:Split to Char ************************
private void button1_Click(object sender, EventArgs e)
{

/*
string names = “Adam;Bob;Joe;Steve;Allen;Matt”;
string[] nameArray = names.Split(‘;’) ; //split the Array
foreach (string name in nameArray)

MessageBox.Show(name);
*/

string _letters = “abcdefg”;
char[] letters=_letters.ToCharArray();
foreach (char c in letters)
MessageBox.Show(c.ToString());

}
}
**********************NB-53:Math class****************************

private void button1_Click(object sender, EventArgs e)
{
/*
*
a)
label1.Text = Math.Abs(-4).ToString();

b)
label1.Text = Math.PI.ToString();
*
c)

*/

label1.Text = Math.Pow(32,4).ToString();

}
}
}

****************************NB-54 Generating Random Numbers**********
private void button1_Click(object sender, EventArgs e)
{

/*
*

a)
*
Random r = new Random();
MessageBox.Show(r.Next().ToString());
*
b)
Random r = new Random();
MessageBox.Show(r.Next(0,100).ToString());

c)

Random r = new Random();
MessageBox.Show(r.NextDouble().ToString());
*

*/

byte[] buffer= new byte[5];
Random r = new Random();
r.NextBytes(buffer);
MessageBox.Show(BitConverter.ToString(buffer));
}
*************************NB-55 ************************************
private void button1_Click(object sender, EventArgs e)
{

/*
a)
* char[] letters = “qwertyabsdijlj”.ToCharArray();
Random r = new Random();
MessageBox.Show(letters[r.Next(0, 25)].ToString());
*/

char[] letters = “qwertyabsdijljgfshfsghsgsgsgs”.ToCharArray();
Random r = new Random();
string randomString = ” “;
for (int i = 0; i < 10; i++)
{
randomString += letters[r.Next(0,25)].ToString();
}
MessageBox.Show(randomString);

}
************************NB-56:FolderBrowserDialog****************
private void button1_Click(object sender, EventArgs e)
{
/*
* a)
FolderBrowserDialog fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
MessageBox.Show(“Test”);
*/
/*
* b)
*
FolderBrowserDialog fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
MessageBox.Show(fbd.SelectedPath); //We see the path
*/
FolderBrowserDialog fbd = new FolderBrowserDialog();
fbd.RootFolder = Environment.SpecialFolder.MyDocuments;
if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
MessageBox.Show(fbd.SelectedPath);
}
}
}

**********************NB-57 Directory Class pt1*******************************

namespace NB_57
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

/*
private void button1_Click(object sender, EventArgs e)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string[] files = Directory.GetFiles(fbd.SelectedPath);
foreach (string s in files)
MessageBox.Show(s);
*/
private void button1_Click(object sender, EventArgs e)
{

string[] drives = Directory.GetLogicalDrives();
foreach (string s in drives)
MessageBox.Show(s);
}

************************NB-58-Directory Class pt2**************
namespace NB_58
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
/*
private void button1_Click(object sender, EventArgs e)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
MessageBox.Show(Directory.GetCreationTime(fbd.SelectedPath).ToString());

}
* MessageBox.Show(s);
*
* b)
*
private void button1_Click(object sender, EventArgs e)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
MessageBox.Show(Directory.GetLastAccessTime(fbd.SelectedPath).ToString());

}

*/
private void button1_Click(object sender, EventArgs e)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
MessageBox.Show(Directory.GetLastWriteTime(fbd.SelectedPath).ToString());

}
{
MessageBox.Show(Directory.GetParent(fbd.SelectedPath).ToString());

}

}
}
}
************************NB-59:Directory Class pt3******************************
private void button1_Click(object sender, EventArgs e)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
Directory.CreateDirectory(fbd.SelectedPath=”\\CV”);
/*
b) FolderBrowserDialog fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
Directory.Move(fbd.SelectedPath, “C:\\”); // sos: The syntx is different
*
*
c) FolderBrowserDialog fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
Directory.Delete(fbd.SelectedPath, “C:\\”);
*/
}
}
}

****************************NB-60: File class ******************
private void button1_Click(object sender, EventArgs e)
{

/*
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
MessageBox.Show(File.Exists(ofd.FileName).ToString());
*
*/
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
File.Delete(ofd.FileName);
//sos delete files

}
}
}

*****************NB-61:File class PT *******************************

private void button1_Click(object sender, EventArgs e)
{

/*
a)
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
File.Copy(ofd.FileName, “”);
*
* */

b)

OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
File.Move(ofd.FileName, “”);
}
}
}

***************************NB-62:Path Class****************
//A button is needed
a)
private void button1_Click(object sender,EventArgs e)
{
OpenFileDialog ofd=new OpenFileDialog();
if (ofd.ShowDialog()==System.Windows.Forms.DialogResult.OK)
MessageBox.Show(Path.GetDirectoryName(ofd.FileName));
b)

private void button1_Click(object sender,EventArgs e)
{
OpenFileDialog ofd=new OpenFileDialog();
if (ofd.ShowDialog())==System.Windows.Forms.DialogResult.OK
MessageBox.Show(Path.GetExtension(ofd.FileName)); //Message the extension of the file

c)
private void button1_Click(object sender,EventArgs e)
{
OpenFileDialog ofd=new OpenFileDialog();
if (ofd.ShowDialog())==System.Windows.Forms.DialogResult.OK
MessageBox.Show(Path.GetFileName(ofd.FileName));

d)
MessageBox.Show(Path.GetFileNameWithoutExtension(ofd.FileName));

e)MessageBox.Show(Path.GetFullPath(ofd.FileName));

f)MessageBox.Show(ofd.FileName);

g)MessageBox.Show(Path.GetFullPath(ofd.FileName));

***************************NB-63:Process Class pt1*********************

//It is needed a)a button b)usinf System.Diagnostic
a)
private void button1_Click(object sender,EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == DialogResult.OK)
{
Process.Start(ofd.FileName);
}

b)
private void button1_Click(object sender,EventArgs e)
{
Process.Start(ofd.FileName);
}

c)
private void button1_Click(object sender,EventArgs e)
{
MessageBox.Show(Process.GetCurrentProcess().ProcessName);
}
d)
private void button1_Click(object sender,EventArgs e)
{
Process.GetCurrentProcess().Kill();
}

*****************************NB-64:Process Class pt2***********
/* a)
foreach (Process p in Process.GetProcesses())
MessageBox.Show(p.ProcessName);

b) foreach (Process p in Process.GetProcesses())
MessageBox.Show(p.Responding.ToString());
*
* *
foreach (Process p in Process.GetProcesses())
if (!p Responding) p.kill();
*
* */

foreach (Process p in Process.GetProcessesByName(“Chrome”))
MessageBox.Show(p.ProcessName);

***********************NB-66:Bitwise Operator pt1*********
private void button1_Click(object sender, EventArgs e)
{
/*
string myString = null;

if (myString == null)
MessageBox.Show(“The string is null.”);
else MessageBox.Show(myString);
*

string myString = null;
MessageBox.Show(myString?? “The string is null.”);
*
* * */
int ? i=null;
int x=i ?? 8;
MessageBox.Show(x.ToString());
}

******************************NB-67:Bitwise Operator pt2********************
private void button1_Click(object sender, EventArgs e)
{
short myShort = 3 & 5; //011 &101=0001
MessageBox.Show(Convert.ToString(myShort, 2));
}
}
}

*********************NB-68:Bitwise Operator pt3***************

private void button1_Click(object sender, EventArgs e)
{
/*
short myShort = 3 ^ 5; //POWER
MessageBox.Show(Convert.ToString(myShort, 2));
*/

short myShort = 5>>1; //Opposite swift left
MessageBox.Show(Convert.ToString(myShort, 2));
}

********************************NB-69:Threading pt1*************

//You must add : using System.Threading;

namespace NB_69
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Thread t; //Only in part two is needed
private void button1_Click(object sender, EventArgs e)
{
/*
* a)
Thread t = new Thread(Freeze);
t.Start();
}
void Freeze()
{
for (; ; ) ;
}
private void form_FormClosing(object sender,FormClosingEventArgs e)
{

}
*/

t = new Thread(Freeze);
t.Start();
}
void Freeze()
{
for (; ; ) ;
}
private void form_FormClosing(object sender, FormClosingEventArgs e)
{
t.Abort();
}

****************************NB-70:Threading pt2******************
namespace NB_70
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Thread t;
string myString;
private void button1_Click(object sender, EventArgs e)
{
t = new Thread(Write);
t.Start();
while (t.IsAlive) ;
textBox1.Text = myString;
}
void Write()
{
for (int i = 0; i < 1000; i++)
myString += “Adam” + i.ToString() + “\r\n”;
}
********************************NB-71:Threading pt3********************

//A Textbox an dbutton is needed
//using System.Threading;
a)
Thread t;
string myString=””;
private void button1_Click(object sender, EventArgs e)
{
Thread t;
string myString = “”;
private void button1_Click(object sender, EventArgs e)
{
t = new Thread(Write);
object[] objA = { “Bob”, 500 };
t.Start(objA);
while (t.IsAlive) ;
textBox1.Text = myString;
}
void Write(object array)
{
object[] o = array as object[];
for (int i = 0; i < Convert.ToInt32(o[1]); i++)
myString += o[0].ToString() + i.ToString() + “\r\n”;
}
private void form1_formClosing(object sender, FormClosingEventArgs e)
{
t.Abort();
}
}

b)
string myString=””;
private void button1_Click(object sender, EventArgs e)
{
t=new Thread(Write);
object[] objA={“Steve”,500};
t.Start(objA);
while(t.IsAlive)
textBox1.Text=myString;
}
void Write(object array)
{
object[]o=array as object[];
for(int i=0; i<Convert.ToInt32(o[1]);i++)
{
Thread.Sleep(10);// sleep method,0,05
myString +=o[0].ToString()+i.ToString()+”\r\n”;
}
}
private void form1_formClosing(object sender,FormClosingEventArgs e)
{
t.Abort();
}
}
}

*******************NB-72:Web Client pt1 Status Log*****************************
It is needed a) A textbook b) http://www.webps.com c)//using System.Net;

//using System.Net;

private void Form1_Load(object sender,EventArgs e)
{
WebClient wc=new WebClient();
textBox1.Text = wc.DownloadString(“http//:itzabam5x.webs.com/Status.txt”);
}
}
************NB-73:WebClientClass pt2 Downloading Files*****************
It is needed a) A button b)using System.Net;

a)
private void button1_Click(object sender, EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
WebClient wc = new WebClient();
wc.DownloadFileAsync(new Uri(“http//:itzabam5x.webs.com/Status.txt”), sfd.FileName);
}
}
b)
private void button1_Click(object sender, EventArgs e)
{
{
SaveFileDialog sfd = new SaveFileDialog();
if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
WebClient wc = new WebClient();
wc.DownloadFileAsync(new Uri(“http//:itzabam5x.webs.com/Status.txt”), sfd.FileName);
wc.DownloadFileCompleted +=new AsyncCompletedEventHandler(wc_DownloadFileCompleted);

}
}
}

void wc_DownloadFileCompleted(object sender,AsyncCompletedEventArgs e)
{
MessageBox.Show (“File is downloaded”);
}
}
}
c)

private void button1_Click(object sender, EventArgs e)
{
{
{
SaveFileDialog sfd = new SaveFileDialog();
if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
WebClient wc = new WebClient();
wc.DownloadFileAsync(new Uri(“http//:itzabam5x.webs.com/Status.txt”), sfd.FileName);
wc.DownloadFileCompleted += new AsyncCompletedEventHandler(wc_DownloadFileCompleted);

}
}
}
void wc_DownloadProgressChanged(object sender,DownloadProgressChangedEventArgs e)

{
label1.Text=”Progress:” +e.ProgressPercentage.ToString();
}

void wc_DownloadFileCompleted(object sender,AsyncCompletedEventArgs e)
{
MessageBox.Show (“File is downloaded”);
}
}
}
*****************NB-74-75-76:Project 1 Email Sender, pt1,pt2,pt3 ****************

//Project name:”Email Sender”
They are needed a)4 Text Boxes b)1 button c)1 groupBox d)//using System.Net.Mail;
note:The passwordbox we make it with star.Look at the tutorial.Maximizebox=false

a)
MailMessage message = new MailMessage();
message.From = new MailAddress(textBox3.Text);
message.Subject = textBox1.Text;
message.Body = textBox2.Text;
foreach (string s in textBox5.Text.Split(‘;’))
message.To.Add(s);
SmtpClient client = new SmtpClient();
client.Credentials = new NetworkCredential(textBox3.Text, textBox4.Text);
client.Host = “smtp.gmail.com”;
client.Port = 587;
client.EnableSsl = true;
client.Send(message);
}

b)
{

try
{
MailMessage message = new MailMessage();
message.From = new MailAddress(textBox3.Text);
message.Subject = textBox1.Text;
message.Body = textBox2.Text;
foreach (string s in textBox5.Text.Split(‘;’))
message.To.Add(s);
SmtpClient client = new SmtpClient();
client.Credentials = new NetworkCredential(textBox3.Text, textBox4.Text);
client.Host = “smtp.gmail.com”;
client.Port = 587;
client.EnableSsl = true;
client.Send(message);

}
catch { MessageBox.Show(“There is error,look the address & connections”, “Error”, MessageBoxButtons.OK, MessageBoxIcon.Error); }
}
}

}

c)
private void button1_Click(object sender, EventArgs e)
{

try
{

if (!textBox3.Text.Contains(“@gmail.com”))
{
MessageBox.Show(“You need to provide an email @gmail.com”);
}

MailMessage message = new MailMessage();
message.From = new MailAddress(textBox3.Text);
message.Subject = textBox1.Text;
message.Body = textBox2.Text;
foreach (string s in textBox5.Text.Split(‘;’))
message.To.Add(s);
SmtpClient client = new SmtpClient();
client.Credentials = new NetworkCredential(textBox3.Text, textBox4.Text);
client.Host = “smtp.gmail.com”;
client.Port = 587;
client.EnableSsl = true;
client.Send(message);

}

catch { MessageBox.Show(“There is error,look the address & connections”, “Error”, MessageBoxButtons.OK, MessageBoxIcon.Error); }

}
d)
//in the main code we add above all
button1.Enabled=false

//in the last line of code we add:

Finally (button1.Enabled=true;)
}
//Close brackets

************************NB-77:DateTime Struct *****************************
//One button is needed

a)
private void button1_Click(object sender, EventArgs e)
{
DateTime dt= new DateTime(1995,10,16,3,32,52);
MessageBox.Show(dt.ToString());
}
}

b)
private void button1_Click(object sender, EventArgs e)
{
DateTime dt=DateTime.Today;
MessageBox.Show(dt.ToString());
}

c)
private void button1_Click(object sender, EventArgs e)
{
DateTime dt=DateTime.Now;
MessageBox.Show(dt.ToString());
}

d)
private void button1_Click(object sender, EventArgs e)
{
{
MessageBox.Show(DateTime.IsLeapYear(2012).ToString());
}

e)
private void button1_Click(object sender, EventArgs e)

{
MessageBox.Show(DateTime.DaysInMonth(2011,7).ToString());
}

f)
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(DateTime.Now.ToFileTime().ToString(“x”));
**********************NB-78:DateTimePicker*****************************
//It is needed a)One button b)A datetime picker c)Look at DateTimePicker.CustomFormat.Property d)dateTimePicker+value

private void button1_Click(object sender, EventArgs e)
{
DateTime dt=dateTimePicker1.Value;
MessageBox.Show(dt.ToString());
}

*****************NB-79:Picture Box & Image Class*****************************

a)

private void button1_Click(object sender, EventArgs e)
{

OpenFileDialog ofd=new OpenFileDialog();
if (ofd.ShowDialog()==System.Windows.Forms.DialogResult.OK)
{
pictureBox1.ImageLocation=ofd.FileName;
}
b)

private void button1_Click(object sender, EventArgs e)
{

OpenFileDialog ofd=new OpenFileDialog();
if (ofd.ShowDialog()==System.Windows.Forms.DialogResult.OK)
{
Image image=Image.FromFile(ofd.FileName);
pictureBox1.Image=image;
}

c)
private void button1_Click(object sender, EventArgs e)
{
pictureBox1.ImageLocation=”http://www.imagelocation.com&#8221;;
}

*****************NB-80:Clipboard Class*****************************
It is needed: a)One button b)Two picture boxes

a)

private void button1_Click(object sender, EventArgs e)
{
textBox2.Text=Clipboard.GetText();
}

b)

private void button1_Click(object sender, EventArgs e)
{
pictureBox2.Image=Clipboard.GetImage();
}
c)
private void button1_Click(object sender, EventArgs e)
{
{
Clipboard.Select(“Adam”);
}
catch {}
}

d)
private void button1_Click(object sender, EventArgs e)
{
try
{
Clipboard.SetImage(pictureBox1.Image);
}
catch{}
pictureBox2.Image=Clipboard.GetImage());
}

e)
{
Clipboard.Clear();

f)
private void button1_Click(object sender, EventArgs e)
{
pictureBox1.ImageLocation = “C:\\Documents and Settings\\cv\\Desktop\\10395_10153824764358205_6420089315749104731_n.jpg”;
}
FINAL:
textBox2.Text = Clipboard.GetText();

}

private void Form1_Load(object sender, EventArgs e)
{
pictureBox1.ImageLocation = “C:\\Documents and Settings\\cv\\Desktop\\10395_10153824764358205_6420089315749104731_n.jpg”;
}

***************-NB C# 81:Colour Dialog***************
//One button is needed

a)
private void button1_Click(object sender,EventArgs e)
{
ColorDialog cd = new ColorDialog();
if (cd.ShowDialog()==System.Windows.Forms.DialogResult.OK)
button1.BackColor=cd.Color;
}

b)
private void button1_Click(object sender,EventArgs e)
{
ColorDialog cd= new ColorDialog();
cd.AllowFullOpen=false;
if (cd.ShowDialog()==System.Windows.Forms.DialogResult.OK)
button1.BackColor=cd.Color;
}

c)
private void button1_Click(object sender,EventArgs e)
{
ColorDialog cd= new ColorDialog();
cd.ShowHelp=true;
if (cd.ShowDialog()==System.Windows.Forms.DialogResult.OK)
button1.BackColor=cd Color;
}

d)
private void button1_Click(object sender,EventArgs e)
{
ColorDialog cd = new ColorDialog();
cd.ShowHelp = true;
cd.HelpRequest += new EventHandler(cd_HelpRequest);
if (cd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
button1.BackColor = cd.Color;
}
void cd_HelpRequest(object sender, EventArgs e)
{
MessageBox.Show(“Choose a colour for the Backround of your button “);
}

*****************NB-82: Colour Struct***********************
//One button is needed

a)
//One button is needed

private void button1_Click(object sender,EventArgs e)
{
ColorDialog cd= new ColorDialog();
cd.ShowHelp=true;
if (cd.ShowDialog()==System.Windows.Forms.DialogResult.OK)
{
Color c=cd Color;
if(c.IsNamedColor) MessageBox.Show(c.Name);
}

b)
private void button1_Click(object sender,EventArgs e)
{
ColorDialog cd= new ColorDialog();
if (cd.ShowDialog()==System.Windows.Forms.DialogResult.OK)
{
Color c= cd.Color;
if (c.IsKnownColor) MessageBox.Show(c.ToKnownColor().ToString());
}

c)
private void button1_Click(object sender,EventArgs e)
{
Color c.Color.FromKnownColor(KnownColor.GradientActiveCaption);
MessageBox.Show(c.ToKnownColor().ToString());
}

d)
private void button1_Click(object sender,EventArgs e)
{
Color c= Color.FromKnownColor(KnownColor.GradientActiveCaption);
MessageBox.Show(c.ToArgb().ToString(“x”));

}

e)
private void button1_Click(object sender,EventArgs e)
{
Color c = Color.Black;
int i = c.ToArgb();
Color b = Color.FromArgb(i);
button1.BackColor = b;
}

***********************************************************NB-83:FontDialog***************************************************************
It is needed: a)A button b)A text box (big)
a)
private void button1_Click(object sender,EventArgs e)
{
FontDialog fd=new FontDialog();
if (fd.ShowDialog()==System.Windows.Forms.DialogResult.OK)
{
textBox1.Font=fd.Font;
}

b)
//Restrictions & additions
private void button1_Click(object sender,EventArgs e)
{
FontDialog fd=new FontDialog();
fd.MinSize=10;
fd.MaxSize=20;
fd.ShowColor=true;
fd.ShowHelp=true;
if (fd.ShowDialog()==System.Windows.Forms.DialogResult.OK)
{
textBox1.Font=Font;
textBox1.ForeColour=fd.Colour;
}

c)
private void button1_Click(object sender,EventArgs e)
{
FontDialog fd=new FontDialog();
fd.MinSize=10;
fd.MaxSize=20;
fd.ShowColor=true;
fd.ShowHelp=true;
fd.HelpRequest +=new EventHandler(fd_HelpRequest);
if (fd.ShowDialog()==System.Windows.Forms.DialogResult.OK)
{
textBox1.Font=Font;
textBox1.ForeColor=fd.Color;
}
}
void fd_HelpRequest(object sender,EventArgs e)
{
MessageBox.Show(“Choose a font for the textBox”);
}

*************************************NB-84:Timer Control**********************************************************
//One button is needed
//Drag & drop in form a timer
//In interval property we put 1000msec
a)

private void button1_Click(object sender,EventArg e)
{
timer1.Start();
}

private voi timer1_Tick(object sender,EventArgs e)
{
MessageBox.Show(“Hello”);
}
}
}

b)
private void button1_Click(object sender,EventArg e)
{
timer1.Start
}
private void timer1_Tick(object sender,EventArgs e)
{
timer1.Stop();
MessageBox.Show(“Hello”);
}

c)
private void button1_Click(object sender,EventArg e)
{
timer1.Start();
}
int i=0;

private void timer1_Tick(object sender,EventArgs e)
{
i++
teBox1.Text +=i.ToString();
}
********************************************NB-85:Playing Sounds**********************************************************

//a)One button is needed b)add: using System.Media;

a)
private void button1_Click(object sender,EventArg e)
{
OpenFileDialog ofd=new OpenFileDialog();
if (ofd.ShowDialog()==DialogResult.OK)
{
SoundPlayer s=new SoundPlayer(ofd.FileName);
s.Play();
}}

b)
private void button1_Click(object sender,EventArg e)
{
OpenFileDialog ofd=new OpenFileDialog();
if (ofd.ShowDialog()==DialogResult.OK
{
SoundPlayer=new SoundPlayer(ofd.FileName)
s.PlayLooping();
}
}

c)//System Sounds
private void button1_Click(object sender,EventArg e)

// Check the follows
// a) SystemSounds.Beep.Play();
// b) SystemSounds.Exclamation.Play();
// c) SystemSounds.Hand.Play();

***************NB-86:MaskedTextBox Control*************

//A button & a MaskedTextBox is needed
*In Propertes->Masked->Numbers only (check)

**********NB-87:Multiple Forms********************

*Extra Form:Project->New WindowsForms->Name it and add
//One button is needed

a)
//How to pass in second form

private void button1_Click(object sender,EventArgs e)
{

Form2 f=new form2();
f.Show();
}
}
b)
//Alternative

private void button1_Click(object sender,EventArg e)
{
Form2 f=new Form2();
f.ShowDialog();
}
c)
//In form 2we put:
public Form2(string myString)
{
InitialnteComponent
}

d)
//
we go to form1

private void button1_Click(object sender,EventArg e)
{
Form2=new Form(textBox1.Text);
f.ShowDialog();
}
e)
public form2(string my String)
{
InitialieComponent()
label1.Text=myString;
}

****************NB-88:Multi Document Interface MDI*******************
//Two buttons are needed
a)

private void button1_Click (object sender,EventArgs e)
{
this.IsMdiContainer=true;
Form2 f=new Form2();
f.MdiParent=this;
f.Show();
}
}

b)

private void button1_Click (object sender,EventArgs e)
{
this.IsMdiContainer=true;
Form2 f=new Form2();
f.MdiParent=this;
f.Show();
Form3 f1=new form3();
f1.MdiParent=this;
f1.Show();
Form4 f2=new Form4();
f2.MdiParent=this;
f2.Show();
}

private void button2_Click (object sender,EventArgs e)
{
this.layoutMdi(MdiLayout.ArrangeIcons);
}

c)
this.LayoutMdi(MdiLayout.TileHorizontal);// TileVertical
********************NB-89:ComboBox Control**************
//A button & a Combobox is needed
//In Combobox we can Edit (look at the tutorial)
//Properties->DropDownStyle->DropDownList

a)
private void button1_Click (object sender,EventArgs e)
{
if (comboBox1.Text==”Adam”) MessageBox.Show(“Test”);
}

b)

private void button1_Click (object sender,EventArgs e)
{
comboBox1.Items[0]:”Steve”;
}
c)

private void button1_Click (object sender,EventArgs e)
{
comboBox1.Items.Add(“Steve”);
}

d)

private void button1_Click (object sender,EventArgs e)
{
MessageBox.Show(comboBox1.Items.Count.ToString())
}

e)
private void button1_Click (object sender,EventArgs e)
{
MessageBox.Show(“Test”);
}***********NB-90:ProgressBar Control************

//We need a)Two buttons b)a progreess bar

a)
Properties Value 0,1/Maximum 0/Step

private void button1_Click (object sender,EventArgs e)
{
progressBar1.Value=0;
}

private void button2_Click (object sender,EventArgs e)
{
progressBar1.Value=0;
}

b)
private void button1_Click (object sender,EventArgs e)
{
progressBar1.PerformStep();
}

c)
private void button1_Click (object sender,EventArgs e)
{
progressBar1.Value=0;
}

d)
private void button1_Click (object sender,EventArgs e)
{
progressBar1.Style=ProgressBarStyle.Marquee;
progressBar1.MarqueeAnimationSpeed=200;
}

private void button2_Click (object sender,EventArgs e)
{
progressBar1.Style=ProgressBarStyle.Blocks;
}

**********NB-91:ListView Control Part1**************
//They are needed a)Two text b)a button c)A list View.It is recommended to look at tutorial

private void button1_Click_1(object sender, EventArgs e)
{
ListViewItem lvi = new ListViewItem(textBox1.Text);
lvi.SubItems.Add(textBox2.Text);
lvi.SubItems.Add(textBox3.Text);
listView1.Items.Add(lvi);
textBox1.Text = “”;
textBox2.Text = “”;
textBox3.Text = “”;

}
}
}

********NB-92:ListView Control Part2************

//We add Content MenuStrip.We put it in specific location.**Look at the tutorials

private void getNameOfItemToolStripMenuItem_Click(object sender,EventArgs e)
{
if (listView1.SelectedItems.Count !=0)
{
MessageBox.Show(listView1.SelectedItems[0].SubItems[0].Text);}
}

*****************NB-93:ListView Control Part3*********

//Look at the tutorial:We add the multiselect

private void getNameOfItemToolStripMenuItem_Click(object sender,EventArgs e)
{
if (listView1.SelectedItems.Count !=0)
{
foreach (ListViewItem lvi in listView1.SelectedItems)
MessageBox.Show(lvi.SubItems[1].Text);
}
}

****************NB-94:ListView Control Part4**************
//Look at the tutorial
//We add in the tuttorial the follow lines

namespace NB_94
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
ListViewItem lvi = new ListViewItem(textBox1.Text);
lvi.SubItems.Add(textBox2.Text);
lvi.SubItems.Add(textBox3.Text);
listView1.Items.Add(lvi);
textBox1.Text = “”;
textBox2.Text = “”;
textBox3.Text = “”;

}
private void getNameOfItemToolStripMenuItem_Click(object sender, EventArgs e)
{
if (listView1.SelectedItems.Count != 0)
{
foreach (ListViewItem lvi in listView1.SelectedItems)
MessageBox.Show(lvi.SubItems[1].Text);
}
}

private void getNameOfItemToolStripMenuItem_Click(object sender, EventArgs e)
{
if (listView1.SelectedItems.Count != 0)
{
foreach (ListViewItem lvi in listView1.SelectedItems)
lvi.Remove();
}
}

private void removedItemsToolStripMenu_Click(object sender, EventArgs e)
{
listView1.Items.Clear();
}
private void button2_Click(object sender, EventArgs e)
{
foreach (ListViewItem lvi in listView1.Items)
if (lvi.Checked) lvi.Remove();
}

private void button2_Click_1(object sender, EventArgs e)
{

}
}

}

**********NB-95:ToolStrip & StatusStrip Controls*********

//We put in the form a)A ToolStrip b)We must save form As(Look at the tutorial c) we select “Drop Down Button”.We put Open & Save d)In DesplayStyle:Text
e)Propertes:Text:file f)Add Status Strip

**********NB-96:Notify Control***********

//We add a)one button b)a Notifier icon
a)
private void button1_Click (object sender,EventArgs e)
{
notifyIcon1.ShowBallonTip(100,”My Title”,”My Text”,ToolTipIcon.Info);
}

b)
private void button1_Click (object sender,EventArgs e)
{
this.Hide();
notifyIcon1.ShowBalloonTip(100,”Still Running”,”Your app is still running”,ToolTipIcon.Info);
}

c)
//We choose Notification -> In the wright corner thunder (thunder icon)->Choose MouseDoubleClick
//Next we go to code editor and add:
private void notifyIcon1_MouseDoubleClick(object sender,MoveEventArgs e)
{
this.Show();
}
}

***********NB-97:Opening Files with your App******************

a)
// We go to Form1.cs
public Form1(string s)
{
InitializeComponent();
MessageBox.Show(s);
}
}
//Next we go to:
static void Main(string() files)
{
Applicaion.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
foreach(string s in files)
Application.Run(new Form1(s));

}
}
*********************NB-98:Settings**********
//It is something like database
//A button & a Text Box is needed
//Go to Project->WindowsForm Application Properties->Settings
//Look at the tuttorial

namespace WindowsFormsApplication11
{
public partial class Form:Form
{
public Form1()
{
InitializeComponent();
textBox1.Text=WindowsFormsApplication1.Properties.Settings.Default.Name;
textBox2.Text=WindowsFormsApplication1.Properties.Settings.Default.Age.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
WindowsFormsApplication1.Properties.Settings.Default.Name=textBox1.Text;
WindowsFormsApplication1.Properties.Settings.Default.Age=Convert.ToInt32(textBox2.Text);
WindowsFormsApplication1.Properties.Settings.ButtonA=button1;
WindowsFormsApplication1.Properties.Settings.Default.Save();
}
}
In this program is:
NB_98.Properties.Settings.Default.Name = textBox1.Text;
NB_98.Properties.Settings.Default.Age = Convert.ToInt32(textBox2.Text);
NB_98.Properties.Settings.Button1 = button1;
NB_98.Properties.Settings.Default.Save();
}

***************NB-99:TreeView Control pt1****************
//We need a) a button b)a treeView

private void button1_Click(object sender, EventArgs e)
{
treeView1.Nodes.Add(“People”);
treeView1.Nodes.Add(“Animals”);
treeView1.Nodes[0].Nodes.Add(“Adam”);
treeView1.Nodes[0].Nodes.Add(“Bob”);
treeView1.Nodes[0].Nodes.Add(“Joe”);
treeView1.Nodes[1].Nodes.Add(“Dog”);
treeView1.Nodes[1].Nodes.Add(“Cat”);
treeView1.Nodes[1].Nodes[0].Nodes.Add(“Spot”);
}

*********************NB-100:TreeView Control pt2**********

private void button2_Click_1(object sender,EventArgs e)
{
treeView1.Nodes.Clear();
}

b)
namespace NB_100
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
treeView1.Nodes.Add(“People”);
treeView1.Nodes.Add(“Animals”);
treeView1.Nodes[0].Nodes.Add(“Adam”);
treeView1.Nodes[0].Nodes.Add(“Bob”);
treeView1.Nodes[0].Nodes.Add(“Joe”);
treeView1.Nodes[1].Nodes.Add(“Dog”);
treeView1.Nodes[1].Nodes.Add(“Cat”);
treeView1.Nodes[1].Nodes[0].Nodes.Add(“Spot”);
}

private void button2_Click(object sender, EventArgs e)
{
treeView1.Nodes.Clear();
}

List<TreeNode> tnList = new List<TreeNode>();
void RemoveChecked(TreeNodeCollection tnc)
{
foreach (TreeNode tn in tnc)
if (tn.Checked) tnList.Add(tn);
else if (tn.Nodes.Count != 0) RemoveChecked(tn.Nodes);
foreach (TreeNode tn in tnList)
treeView1.Nodes.Remove(tn);
}
}
}

source:https://thenewboston.com/

***This code is for educational use!****

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s