=== CurrentDate.CurrentDate.Form1.cs =======================================
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace CurrentDate
{
///
/// CurrentDate Example: Display the current date and time
/// using the selected format.
///
public partial class Form1 : Form
{
ArrayList c = new ArrayList();
ArrayList s = new ArrayList();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
cboFormat.Items.AddRange(new string[] {"Short Date",
"Long Date", "Long Date / Short Time",
"Long Date / Long Time", "Short Date / Short Time",
"Short Date / Long Time", "Month / Day",
"IETF FRC 1123", "Sortable Date / Time",
"Short Time", "Long Time", "Universal Date / Time",
"Year Month"});
c.AddRange(new string[] {"d", "D", "f", "F", "g", "G",
"M", "R", "s", "t", "T", "u", "y"});
s.AddRange(new string[] {"MM/dd/yyyy", "dddd, MMMM dd/yyyy",
"MM/dd/yyyy HH:mm", "MM/dd/yyyy HH:mm:ss",
"MM/dd/yyyy HH:mm", "MM/dd/yyyy HH:mm:ss", "MMMM dd",
"ddd,dd,MMM,yyyy HH:mm:ssGMT", "yyy-MM-dd HH:mm:ss",
"HH:mm", "HH:mm:ss", "dddd,MMMM dd,yyy HH:mm:ss",
"MMMM yyyy"});
}
private void cboFormat_SelectedIndexChanged(object sender, EventArgs e)
{
int index = cboFormat.SelectedIndex;
txtCurrentDateTime.Text = DateTime.Now.ToString((string)c[index]);
txtFormatChar.Text = (string)c[index];
txtSpecification.Text = (string)s[index];
}
}
}
=== Unicode.Unicode.Form1.cs =======================================
using System;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Unicode
{
///
/// Unicode Example: Display characters from the Roman, Greek,
/// and Cyrillic alphabets.
///
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// Translate characters for first textbox:
// Uppercase Roman alphabet.
displayChars(textBox1, 65, 90);
// Translate characters for second textbox:
// Lowercase Roman alphabet.
displayChars(textBox2, 97, 122);
// Translate characters for third textbox:
//// Uppercase Greek alphabet.
displayChars(textBox3, 913, 937);
// Translate characters for fourth textbox:
// Lowercase Greek alphabet.
displayChars(textBox4, 945, 969);
// Translate characters for fifth textbox:
// Uppercase Cyrillic alphabet.
displayChars(textBox5, 1040, 1071);
// Translate characters for sixth textbox:
// Lowercase Cyrillic alphabet.
displayChars(textBox6, 1072, 1103);
}
public void displayChars(TextBox t, int start, int end)
{
byte[] b = new byte[2];
string s = "";
char[] c = { 'a' };
Decoder d = Encoding.Unicode.GetDecoder();
for (int i = start; i <= end; i++)
{
b[0] = (byte)(i % 256);
b[1] = (byte)(i / 256);
d.GetChars(b, 0, 2, c, 0, false);
s += c[0];
}
t.Text = s;
t.Select(0, 0);
}
}
}
=== Multiclass.Multiclass.Program.cs =====================================
using System;
namespace Multiclass
{
///
/// Multiclass Example: Show how to implement an
/// interface in a multiclass project.
///
public class Program
{
public static void Main()
{
// Declare and instantiate objects.
Dog x = new Dog("Fido");
Cat y = new Cat("Felix");
Person z = new Person("Alice", 'F', 25);
// Test Philosophize method.
Console.WriteLine("Test Philosophize method.");
z.Philosophize();
Console.WriteLine();
// Print objects using ToString methods.
Console.WriteLine("Print objects using ToString methods.");
Console.WriteLine(x);
Console.WriteLine(y);
Console.WriteLine(z);
Console.WriteLine();
// Create array of Speaker;
Speaker[] s = new Speaker[3];
// Each object implements Speaker so can be
// assigned to a speaker array.
s[0] = x;
s[1] = y;
s[2] = z;
// Test speaker methods.
Console.WriteLine("Test speaker methods.");
for(int i = 0; i <= 2; i++)
s[i].Speak();
Console.ReadLine();
}
}
}
// Console Output:
Test Philosophize method.
I think, therefore I am.
Print objects using ToString methods.
Dog: Fido
Cat: Felix
Person: Alice F 25
Test speaker methods.
Woof.
Meow.
Hello, my name is Alice.
--- Multiproject.Multiproject.Animal.cs ----------------------------------
using System;
using System.Collections.Generic;
using System.Text;
namespace Multiclass
{
///
/// Multiclass Example: Show how to implement an
/// interface in a multiclass project.
///
public abstract class Animal
{
protected string name;
public Animal(string n)
{
name = n;
}
}
}
--- Multiproject.Multiproject.Speaker.cs ---------------------------------
using System;
using System.Collections.Generic;
using System.Text;
namespace Multiclass
{
///
/// Multiclass Example: Show how to implement an
/// interface in a multiclass project.
///
interface Speaker
{
void Speak();
}
}
--- Multiproject.Multiproject.Cat.cs -------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
namespace Multiclass
{
///
/// Multiclass Example: Show how to implement an
/// interface in a multiclass project.
///
class Cat : Animal, Speaker
{
public Cat(string n) : base(n)
{ }
public void Speak()
{
Console.WriteLine("Meow.");
}
public override string ToString()
{
return "Cat: " + name;
}
}
}
--- Multiproject.Multiproject.Dog.cs -------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
namespace Multiclass
{
///
/// Multiclass Example: Show how to implement an
/// interface in a multiclass project.
///
class Dog : Animal, Speaker
{
public Dog(string n) : base(n)
{ }
public void Speak()
{
Console.WriteLine("Woof.");
}
public override string ToString()
{
return "Dog: " + name;
}
}
}
--- Multiproject.Multiproject.Person.cs ----------------------------------
using System;
namespace Multiclass
{
///
/// Multiclass Example: Show how to implement an
/// interface in a multiclass project.
///
class Person : Speaker
{
private string name;
private char gender;
private int age;
public Person(string n, char g, int a)
{
name = n;
gender = g;
age = a;
}
public void Speak()
{
Console.WriteLine("Hello, my name is " + name + ".");
}
public void Philosophize()
{
Console.WriteLine("I think, therefore I am.");
}
public override string ToString()
{
return "Person: " + name + " " + gender + " " + age;
}
}
}
=== Multiproject.Multiproject.Module1.vb ===================================
Imports System.Console
Imports SpeakerLib
'''
''' Multiclass Example: Show how to implement an interface in
''' a multiproject project.
'''
Public Module Module1
Public Sub Main()
' Declare and instantiate objects.
Dim x As New Dog("Fido")
Dim y As New Cat("Fido")
Dim z As New Person("Alice", "F"c, 25)
' Test Philosophize method.
WriteLine("Test Philosophize method.")
z.Philosophize()
WriteLine()
' Print objects using ToString methods.
WriteLine("Print objects using ToString methods.")
WriteLine(x)
WriteLine(y)
WriteLine(z)
WriteLine()
' Create array of Speaker;
Dim s(2) As Speaker
' Each object implements Speaker so can be
' assigned to a speaker array.
s(0) = x
s(1) = y
s(2) = z
' Test speaker methods.
WriteLine("Test speaker methods.")
For i As Integer = 0 To 2
s(i).Speak()
Next
Console.ReadLine()
End Sub
End Module
' Console Output:
Test Philosophize method.
I think, therefore I am.
Print objects using ToString methods.
Dog: Fido
Cat: Fido
Person: Alice F 25
Test speaker methods.
Woof
Meow
Hello, my name is Alice.
--- Multiproject.Multiproject.Person.vb -----------------------------------
Imports System.Console
Imports SpeakerLib
'''
''' Multiproject Example: Show how to implement an interface in
''' a multiproject project.
'''
Public Class Person
Implements Speaker
Private name As String
Private gender As Char
Private age As Integer
Public Sub New(ByVal n As String, ByVal g As Char, ByVal a As Integer)
name = n
gender = g
age = a
End Sub
Public Sub Speak() Implements Speaker.Speak
Console.WriteLine("Hello, my name is " + name + ".")
End Sub
Public Sub Philosophize()
WriteLine("I think, therefore I am.")
End Sub
Public Overrides Function ToString() As String
Return "Person: " & name & " " & gender & " " & age
End Function
End Class
--- Multiproject.Multiproject.Cat.vb --------------------------------------
Imports System.Console
Imports SpeakerLib
'''
''' Multiclass Example: Show how to implement an interface
''' in a multiproject project.
'''
Public Class Cat
Inherits Animal
Implements Speaker
Public Sub New(ByVal n As String)
MyBase.New(n)
End Sub
Public Sub Speak() Implements Speaker.Speak
WriteLine("Meow")
End Sub
Public Overrides Function ToString() As String
Return "Cat: " & name
End Function
End Class
--- Multiproject.Multiproject.Dog.vb --------------------------------------
Imports System.Console
Imports SpeakerLib
'''
''' Multiclass Example: Show how to implement an interface
''' in a multiproject project.
'''
Public Class Dog
Inherits Animal
Implements Speaker
Public Sub New(ByVal n As String)
MyBase.New(n)
End Sub
Public Sub Speak() Implements Speaker.Speak
WriteLine("Woof")
End Sub
Public Overrides Function ToString() As String
Return "Dog: " & name
End Function
End Class
--- Multiproject.Multiproject.Person.vb -----------------------------------
Imports System.Console
Imports SpeakerLib
'''
''' Multiproject Example: Show how to implement an interface in
''' a multiproject project.
'''
Public Class Person
Implements Speaker
Private name As String
Private gender As Char
Private age As Integer
Public Sub New(ByVal n As String, ByVal g As Char, ByVal a As Integer)
name = n
gender = g
age = a
End Sub
Public Sub Speak() Implements Speaker.Speak
Console.WriteLine("Hello, my name is " + name + ".")
End Sub
Public Sub Philosophize()
WriteLine("I think, therefore I am.")
End Sub
Public Overrides Function ToString() As String
Return "Person: " & name & " " & gender & " " & age
End Function
End Class
--- Multiproject.SpeakerLib.Animal.cs -------------------------------------
using System;
namespace SpeakerLib
{
///
/// Multiclass Example: Show how to implement an interface
/// in a multiproject project.
///
public abstract class Animal
{
protected string name;
public Animal(string n)
{
name = n;
}
}
}
--- Multiproject.SpeakerLib.Speaker.cs ------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
namespace SpeakerLib
{
///
/// Multiclass Example: Show how to implement an
/// interface in a multiproject project.
///
public interface Speaker
{
void Speak();
}
}
=== RealEstate.RealEstate.Form1.cs ========================================
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Windows.Forms;
namespace RealEstate
{
///
/// RealEstate Example: Illustrate how to use database
/// and class objects to display data interactively in
/// a secondary form.
///
/// Copy the RealEstate.mdb database into the bin/Debug
/// folder before executing the application.
///
///
public partial class Form1 : Form
{
OleDbConnection c = new OleDbConnection();
OleDbCommand sc = new OleDbCommand();
OleDbDataReader dr;
ArrayList rivers = new ArrayList();
ArrayList houses = new ArrayList();
frmHouse houseForm = new frmHouse();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// Configure connection object.
c.ConnectionString = "";
c.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=RealEstate.mdb";
c.Open();
// Configure command object.
sc.Connection = c;
sc.CommandType = CommandType.Text;
sc.CommandText = "SELECT * FROM Rivers";
// Plot rivers.
dr = sc.ExecuteReader();
while (dr.Read())
rivers.Add(new RiverPoint(dr.GetFloat(0),
dr.GetFloat(1), dr.GetBoolean(2)));
dr.Close();
txtMin.Text = trkMin.Value.ToString();
txtMax.Text = trkMax.Value.ToString();
}
private void trkMin_Scroll(object sender, EventArgs e)
{
txtMin.Text = trkMin.Value.ToString();
}
private void trkMax_Scroll(object sender, EventArgs e)
{
txtMax.Text = trkMax.Value.ToString();
}
private void mnuPlotHouses_Click(object sender, EventArgs e)
{
float minPrice = 1000 * trkMin.Value;
float maxPrice = 1000 * trkMax.Value;
sc.CommandType = CommandType.Text;
sc.CommandText = "SELECT * FROM Houses WHERE " +
minPrice + " < Price And Price < " + maxPrice;
dr = sc.ExecuteReader();
houses.Clear();
while (dr.Read())
houses.Add(new HousePoint(dr.GetFloat(1),
dr.GetFloat(2), dr.GetInt32(0)));
dr.Close();
picDisplay.Invalidate();
}
private void DisplayHouse(int theID)
{
float price;
sc.CommandText = "SELECT * FROM Houses WHERE ID = " + theID;
dr = sc.ExecuteReader();
if (dr.Read())
{
houseForm.txtAddress.Text = dr.GetString(3);
houseForm.txtCity.Text = dr.GetString(4);
houseForm.txtBedrooms.Text = dr.GetFloat(5).ToString();
houseForm.txtBathrooms.Text = dr.GetFloat(6).ToString();
price = (float) dr.GetDecimal(8);
houseForm.txtPrice.Text = price.ToString("$#,##0.");
}
houseForm.ShowDialog();
dr.Close();
}
private void picDisplay_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Pen p = new Pen(Color.Blue, 3);
SolidBrush br = new SolidBrush(Color.Red);
float xprev = 0, yprev = 0;
foreach(RiverPoint r in rivers)
{
if (r.StartPoint)
g.DrawLine(p, 10 * r.X, 10 * r.Y, 10 * r.X, 10 * r.Y);
else
g.DrawLine(p, 10 * xprev, 10 * yprev, 10 * r.X, 10 * r.Y);
xprev = r.X;
yprev = r.Y;
}
foreach(HousePoint h in houses)
{
g.FillEllipse(br, 10 * h.X - 3, 10 * h.Y - 3, 6, 6);
}
}
private void picDisplay_MouseUp(object sender, MouseEventArgs e)
{
foreach(HousePoint h in houses)
if (Math.Abs(e.X - 10 * h.X) < 3 &&
Math.Abs(e.Y - 10 * h.Y) < 3)
{
DisplayHouse(h.ID);
}
}
}
}
--- RealEstate.RealEstate.RiverPoint.cs ----------------------------------------
using System;
namespace RealEstate
{
///
/// RealEstate Example: Illustrate how to use database
/// and class objects to display data interactively in
/// a secondary form.
///
class RiverPoint
{
public float X, Y;
public int ID;
public bool StartPoint;
public RiverPoint(float XVal, float YVal, bool S)
{
X = XVal;
Y = YVal;
StartPoint = S;
}
}
}
--- RealEstate.RealEstate.HousePoint.cs ----------------------------------------
using System;
namespace RealEstate
{
///
/// RealEstate Example: Illustrate how to use database
/// and class objects to display data interactively in
/// a secondary form.
///
class HousePoint
{
public float X;
public float Y;
public int ID;
public HousePoint(float XVal, float YVal, int i)
{
X = XVal;
Y = YVal;
ID = i;
}
}
}
--- RealEstate.RealEstate.frmHouse.cs ------------------------------------------
using System;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
namespace RealEstate
{
///
/// RealEstate Example: Illustrate how to use database
/// and class objects to display data interactively in
/// a secondary form.
///
public partial class frmHouse : Form
{
public frmHouse()
{
InitializeComponent();
}
private void frmHouse_Load(object sender, EventArgs e)
{
txtAddress.Select(0, 0);
}
private void button1_Click(object sender, EventArgs e)
{
this.Hide();
}
}
}
================================================================================