Intro Source Code Files (intro.txt) === BlankForm.BlankForm.Form1.cs ============================= using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace BlankForm { /// /// BlankForm Example: A default Windows single-form project /// with no added runtime code. /// public partial class Form1 : Form { /// /// Form window for BlankForm project. /// public Form1() { InitializeComponent(); } } } --- BlankForm.BlankForm.Form1.Designer.cs -------------------- namespace BlankForm { partial class Form1 { /// /// Required designer variable. /// private System.ComponentModel.IContainer components = null; /// /// Clean up any resources being used. /// /// true if managed resources should /// be disposed; otherwise, false. protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.Text = "Form1"; } #endregion } } --- BlankForm.BlankForm.Program.cs --------------------------- using System; using System.Collections.Generic; using System.Windows.Forms; namespace BlankForm { /// /// BlankForm Example: A default Windows single-form project /// with no added runtime code. /// static class Program { /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } } } --- BlankForm.BlankForm.AssemblyInfo.cs ---------------------- using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("BlankForm")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("BlankForm")] [assembly: AssemblyCopyright("Copyright © 2006")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("e694c450-b362-4e6d-8cf6-4095f05f860c")] // Version information for an assembly consists of the following four values: // // Major Version // Minor Version // Build Number // Revision // [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] === Greeter1.Greeter1.Program.cs ============================= namespace Greeter1 { /// /// Greeter1 Example: Input the name of /// the person to greet, then write a /// greeting to the console. /// public class Program { public static void Main() { // Declare name. string name; // Print prompt to the console. System.Console.Write("Enter a name: "); // Read name from keyboard. name = System.Console.ReadLine(); // Print greeting to the console. System.Console.WriteLine( "Hello, " + name + ", how are you?"); // Hold output window until user presses Enter key. System.Console.ReadLine(); } } } // Console Output: Enter a name: Larry Hello, Larry, how are you? === ClickCounter1.ClickCounter1.Form1.cs ============================= using System; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; namespace ClickCounter { /// /// ClickCounter Example: Count the number of /// clicks of the "Click Me" button. /// public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnClickMe_Click(object sender, EventArgs e) { int count; count = int.Parse(txtClickCount.Text); count++; txtClickCount.Text = count.ToString(); } } } --- ClickCounter1.ClickCounter1.Form1.Designer.cs -------------------- namespace ClickCounter { partial class Form1 { /// /// Required designer variable. /// private System.ComponentModel.IContainer components = null; /// /// Clean up any resources being used. /// /// true if managed resources should be disposed; /// otherwise, false. protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.btnClickMe = new System.Windows.Forms.Button(); this.txtClickCount = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // // btnClickMe // this.btnClickMe.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.btnClickMe.Location = new System.Drawing.Point(12, 12); this.btnClickMe.Name = "btnClickMe"; this.btnClickMe.Size = new System.Drawing.Size(207, 37); this.btnClickMe.TabIndex = 0; this.btnClickMe.Text = "Click Me"; this.btnClickMe.UseVisualStyleBackColor = true; this.btnClickMe.Click += new System.EventHandler(this.btnClickMe_Click); // // txtClickCount // this.txtClickCount.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.txtClickCount.Location = new System.Drawing.Point(12, 55); this.txtClickCount.Name = "txtClickCount"; this.txtClickCount.Size = new System.Drawing.Size(207, 26); this.txtClickCount.TabIndex = 1; this.txtClickCount.Text = "0"; this.txtClickCount.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(231, 97); this.Controls.Add(this.txtClickCount); this.Controls.Add(this.btnClickMe); this.Name = "Form1"; this.Text = "ClickCounter Example"; this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.Button btnClickMe; private System.Windows.Forms.TextBox txtClickCount; } } === ClickCounter2.App.xaml =========================================== --- ClickCounter2.App.xaml.cs ---------------------------------------- using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Linq; using System.Windows; namespace ClickCounter2 { /// /// Interaction logic for App.xaml /// public partial class App : Application { } } --- ClickCounter2.Window1.xaml --------------------------------------- 0 --- ClickCounter2.Window1.xaml.cs ------------------------------------ using System; using System.Windows; namespace ClickCounter2 { /// /// Interaction logic for Window1.xaml /// public partial class Window1 : Window { public Window1() { InitializeComponent(); } private void btnClickMe_Click(object sender, RoutedEventArgs e) { int count = int.Parse(txtCount.Text); count++; txtCount.Text = count.ToString(); } } } --- ClickCounter2.csproj --------------------------------------------- Debug AnyCPU 9.0.21022 2.0 {5005CA4D-9637-4690-A3BD-D3A9D7393A3F} WinExe Properties ClickCounter2 ClickCounter2 v3.5 512 {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 4 true full false bin\Debug\ DEBUG;TRACE prompt 4 pdbonly true bin\Release\ TRACE prompt 4 3.5 3.5 3.5 MSBuild:Compile Designer MSBuild:Compile Designer App.xaml Code Window1.xaml Code Code True True Resources.resx True Settings.settings True ResXFileCodeGenerator Resources.Designer.cs Designer SettingsSingleFileGenerator Settings.Designer.cs === Greeter2.Greeter2.Form1.cs ===================================== using System; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; namespace Greeter2 { /// /// Greeter2 Example: Input the name of the person /// to greet, then display a greeting in one of /// four languages, given the name of the person to greet. /// Also show an image related to the selected language. /// /// /// (1) The non-english symbols ç, í, á and ¿ are entered /// using Insert Symbol in MS-Word. /// (2) Copy the JPEG image files from the source code folder /// into bin/Debug before executing the application. /// public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnDisplay_Click(object sender, EventArgs e) { string name = txtName.Text; if (radEnglish.Checked) { txtGreeting.Text = "Good day." + "\r\nHow are you, " + name + "?"; picDisplay.Image = Image.FromFile("english.jpg"); } else if (radFrench.Checked) { txtGreeting.Text = "Bon jour." + "\r\nComment ça va, " + name + "?"; picDisplay.Image = Image.FromFile("french.jpg"); } else if (radGerman.Checked) { txtGreeting.Text = "Guten Tag." + "\r\nWie gehen Sie, " + name + "?"; picDisplay.Image = Image.FromFile("german.jpg"); } else if (radSpanish.Checked) { txtGreeting.Text = "Buenos Días." + "\r\n¿Como estás, " + name + "?"; picDisplay.Image = Image.FromFile("spanish.jpg"); } } private void RadioClicked(object sender, EventArgs e) { btnDisplay.PerformClick(); } } } === Controls.Controls.Form1.cs ===================================== using System; using System.ComponentModel; using System.IO; using System.Drawing; using System.Windows.Forms; namespace Controls { /// /// Controls Example: Illustrate the behavior /// of some common Windows controls. /// public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void trk1_Scroll(object sender, EventArgs e) { txtValue.Text = trk1.Value.ToString(); } private void btnShowValues_Click(object sender, EventArgs e) { // Show values of all controls. MessageBox.Show( "txtString: " + txtString.Text + "\n\r" + "trk1 : " + trk1.Value + "\n\r" + "rad1 :" + rad1.Checked + "\n\r" + "rad2 :" + rad2.Checked + "\n\r" + "chk1 :" + chk1.Checked, "Control Data"); } private void mnuShowValues_Click(object sender, EventArgs e) { btnShowValues.PerformClick(); } private void mnuOpen_Click(object sender, EventArgs e) { string fileName; // If user clicks OK in OpenFileDialog control, open file. if (openFileDialog1.ShowDialog() == DialogResult.OK) { // Use open file dialog to get file name. fileName = openFileDialog1.FileName; // Use file name to create StreamReader object. StreamReader sr = new StreamReader(fileName); // Check if any characters to read in input buffer. if (sr.Peek() > -1) { // Read line from file. string line = sr.ReadLine(); // Use Split function to separate line into fields. string[] fields; fields = line.Split(','); // Assign values to controls from fields array. txtString.Text = fields[0]; trk1.Value = int.Parse(fields[1]); txtValue.Text = trk1.Value.ToString(); rad1.Checked = fields[2] == "True"; rad2.Checked = fields[3] == "True"; chk1.Checked = fields[4] == "True"; } // Although closing StreamReader object when finished // is optional, it is good practice. sr.Close(); } } private void mnuSave_Click(object sender, EventArgs e) { // Create comma delimited string of control values. string line = txtString.Text + ","; line += trk1.Value + ","; line += rad1.Checked + ","; line += rad2.Checked + ","; line += chk1.Checked; // If user clicks OK, save data. if (saveFileDialog1.ShowDialog() == DialogResult.OK) { // Get file name from save file dialog. string fileName = saveFileDialog1.FileName; // Create StreamWriter object. StreamWriter sw = new StreamWriter(fileName); // Write line to output file. sw.WriteLine(line); // Closing StreamWriter object to flush buffer // is required. sw.Close(); } } private void mnuExit_Click(object sender, EventArgs e) { this.Close(); } } } === Sound.Sound.Form1.cs =================================================== using System; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; using System.Media; using System.IO; namespace Sound { /// /// Sound Example: Choose a sound file in .wav format and play it /// with a SoundPlayer object. /// public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // Set initial directory and files to display. openFileDialog1.InitialDirectory = "C:/WINDOWS/Media"; openFileDialog1.Filter = "WAV Files|*.wav"; } private void mnuChoose_Click(object sender, EventArgs e) { // Choose sound file and display in textbox. openFileDialog1.ShowDialog(); txtSoundFile.Text = openFileDialog1.FileName; } private void mnuPlay_Click(object sender, EventArgs e) { if (txtSoundFile.Text.EndsWith(".wav")) { SoundPlayer sp = new SoundPlayer(txtSoundFile.Text); try { sp.Play(); } catch (FileNotFoundException excep) { MessageBox.Show("Sound file does not exist.\n\r\n\r" + excep); } } else { MessageBox.Show("File is not a .wav file."); } } } } === Localization.Localization.Form1.cs ===================================== using System; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; using System.Threading; using System.Globalization; namespace Localization { /// /// Localization Example: A click counter application /// with localizable text in English, French, or German. /// public partial class Form1 : Form { public Form1() { // Thread.CurrentThread.CurrentUICulture = // new CultureInfo("fr-FR"); // Thread.CurrentThread.CurrentUICulture = // new CultureInfo("de-DE"); InitializeComponent(); } private void btnClickMe_Click(object sender, EventArgs e) { int count; count = int.Parse(txtClickCount.Text); count++; txtClickCount.Text = count.ToString(); } } } === DocumentationFormatter.DocumentationFormatter.Form1.cs ================= using System; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; using System.Xml; using System.Xml.Xsl; using System.IO; namespace DocumentationFormatter { /// /// DocumentationFormatter Example: Display a formatted XML file as /// an HTML file in a WebBrowser control. Use an XSL stylesheet /// to format the XML file. /// /// /// The Employee.XML file is the documentation from the C#-2.Employee /// Example. The Documentation.xsl file is from www.codeproject.com. /// public partial class Form1 : Form { private string xmlInputFile, xsltStyleFile, htmlOutputFile; private XslCompiledTransform xslt = new XslCompiledTransform(); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // Set initial directory. } private void mnuSource_Click(object sender, EventArgs e) { // Select input XML File. openFileDialog1.InitialDirectory = "../.."; openFileDialog1.ShowDialog(); xmlInputFile = openFileDialog1.FileName; } private void mnuStyle_Click(object sender, EventArgs e) { // Select XSLT Style File. openFileDialog1.InitialDirectory = "../.."; openFileDialog1.ShowDialog(); xsltStyleFile = openFileDialog1.FileName; } private void mnuDisplay_Click(object sender, EventArgs e) { // Display formatted HTML file. if (xsltStyleFile == null || xmlInputFile == null) return; xslt.Load(xsltStyleFile); htmlOutputFile = "C:\\display.htm"; xslt.Transform(xmlInputFile, htmlOutputFile); webBrowser1.Navigate(new Uri("file://" + htmlOutputFile)); } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { // Delete temporary file when finished displaying. if (htmlOutputFile != null) File.Delete(htmlOutputFile); } } } --- DocumentationFormatter.DocumentationFormatter.Persons.xml--------------- Susan F 21 Michael M 25 Judy F 31 Chloe F 27 Scott M 58 William M 41 Mary F 30 --- DocumentationFormatter.DocumentationFormatter.Persons.xsl--------------- Formatted Persons.xml File
Name ID Gender Age
=== 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(); } } } ================================================================================