Difference between revisions of "OOP Class9"
esse quam videri
(→Home Work) |
|||
Line 1: | Line 1: | ||
[[Category:OOP]] | [[Category:OOP]] | ||
+ | |||
+ | ==Dog and Dog Binding== | ||
+ | |||
+ | DataBound controls can bind to anyting that implements [http://msdn2.microsoft.com/en-us/library/system.collections.ienumerable.aspx IEnumerable] | ||
+ | It's easier in 2.0 + to just inherit from [http://msdn2.microsoft.com/en-us/library/system.collections.icollection.aspx ICollection] | ||
+ | |||
+ | http://iam.colum.edu/oop/classsource/class9/DogBinding.aspx [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class9/DogBinding.aspx source] [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class9/DogBinding.aspx.cs codebehind] | ||
Revision as of 03:07, 1 July 2008
Contents
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
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>