03.01.2015 Views

Complete set: Intro to C - Bill Buchanan

Complete set: Intro to C - Bill Buchanan

Complete set: Intro to C - Bill Buchanan

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

We keep a record of the country that is currently on display<br />

//We do this so that we can "unsubscribe" it when the user<br />

//selects a different item<br />

Country CurrentlyFocussed = null;<br />

Country.changeHandler CurrentlyFocussedCH = null;<br />

//This is the action that causes the subject of the detail panel<br />

//<strong>to</strong> change<br />

private void worldLB_SelectedIndexChanged(object sender, System.EventArgs<br />

e)<br />

{<br />

//Put details of the currently selected country<br />

//in the detail text boxes<br />

Country c =<br />

world[worldLB.SelectedIndex] as Country;<br />

ShowDetailsOfCountry(c,e);<br />

//Now we want <strong>to</strong> subscribe <strong>to</strong> the OnChange event for this<br />

//country.<br />

//First we must unsubscribe whoever was registered before<br />

if (CurrentlyFocussed!=null)<br />

CurrentlyFocussed.OnChange -= CurrentlyFocussedCH;<br />

//We create a new handler<br />

CurrentlyFocussedCH = new<br />

cia.Country.changeHandler(ShowDetailsOfCountry);<br />

//We subscribe our new handler <strong>to</strong> the OnChange event of c<br />

c.OnChange += CurrentlyFocussedCH;<br />

//Remember the currently focussed item so we can unsubscribe<br />

CurrentlyFocussed = c;<br />

duction <strong>to</strong> .NET<br />

<strong>Intro</strong><br />

}<br />

//Show the user which record we are on<br />

label6.Text = String.Format("{0}/{1}",<br />

worldLB.SelectedIndex.ToString(),<br />

worldLB.Items.Count);<br />

Agilent .NET Course: Module 10,page<br />

10

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!