15.02.2015 Views

C# 4 and .NET 4

Create successful ePaper yourself

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

650 ❘ ChaPTer 24 netwOrkinG<br />

Enabling <strong>and</strong> disabling the appropriate Back <strong>and</strong> Forward buttons really depends on the ability to go<br />

backward or forward in the page stack. This is achieved by using both the CanGoForwardChanged() <strong>and</strong><br />

the CanGoBackChanged() events:<br />

private void webBrowser1_CanGoBackChanged(object sender, EventArgs e)<br />

{<br />

if (webBrowser1.CanGoBack)<br />

{<br />

buttonBack.Enabled = true;<br />

}<br />

else<br />

{<br />

buttonBack.Enabled = false;<br />

}<br />

}<br />

private void webBrowser1_CanGoForwardChanged(object sender, EventArgs e)<br />

{<br />

if (webBrowser1.CanGoForward)<br />

{<br />

buttonForward.Enabled = true;<br />

}<br />

else<br />

{<br />

buttonForward.Enabled = false;<br />

}<br />

}<br />

Run the project now, visit a web page, <strong>and</strong> click through a few links. You should also be able to use the<br />

toolbar to enhance your browsing experience. The end product is shown in Figure 24-7.<br />

figure 24-7<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!