OOP Class9

esse quam videri
Revision as of 03:07, 1 July 2008 by Jeff (talk | contribs)
Jump to: navigation, search


Dog and Dog Binding

DataBound controls can bind to anyting that implements IEnumerable

   It's easier in 2.0 + to just inherit from ICollection

http://iam.colum.edu/oop/classsource/class9/DogBinding.aspx source codebehind


Motorvehicle Diagram

Oop Motorvehicle Diagram

http://iam.colum.edu/oop/browser/browser.aspx?f=/classsource/class7/MotorvehicleRace

Windows forms

Events

events from a windows form or web page are handled by event handlers. Events are raised when a user interacts with interface elements and handled by the event handlers.


http://www.csharphelp.com/archives/archive253.html

Examaple of event handlers and classes

http://iam.colum.edu/oop/MotorvehicleRace.zip

<csharp> private void button1_Click(object sender, EventArgs e)

       {
           Console.WriteLine("button1 Clicked");
           MessageBox.Show("button1 Clicked");   
       }

</csharp>

Create a windows form with a button the uses your class.

<csharp> using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;

namespace WindowsDog {

   public partial class Form1 : Form
   {
       Dog fido;
       
       public Form1()
       {
           InitializeComponent();
           fido = new Dog();
       }
       private void btnBark_Click(object sender, EventArgs e)
       {
           lblBark.Text = fido.Bark();
       }


       public class Dog 
       {
           public string Name;		// the dog's name
           public int Age;			// the dog's age
           public int Weight;			// the dog's weight
           public string BarkSound;	// the sound of the dog's bark
           public Dog()
           {
               BarkSound = "Woof!!!";
           }
           public string Bark()
           {
               return this.BarkSound;
           }
           public void Eat()
           {
               //put eat code here 
           }
       }	
   }

} </csharp>

Home Work