For the button images, we'll have an ImageList that will allow us to select a picture for all the buttons on the form.
You'll need some images for your buttons.
The images are all PNG files. If the above link no longer works, try Googling the term "free icons" (with the quote marks). Or search your hard drive for suitable images. You can search for files that end in, say, GIF by entering *.gif in the Windows search box. Go for an image size no bigger than 64 pixels high by 64 pixels wide. Image types supported by the ImageList control are JPEG, GIF, BMP, PNG and ICO.
So, add an ImageList control to your project (under the Components category in the toolbox).
The ImageList has a ColorDepth property that we need to change. Our images are in the PNG-24 format, where the 24 stands for the number of bits. You'd think, then, that we'd need to set the ColorDepth to 24Bit. However, they look awful at this Depth. When we switch to 32Bit, they look fine! But if your images look awful, change the ColorDepth property.
Our images are 32 pixels high by 32 pixels wide. We can change to that size in the ImageList properties area. The default is to have the images 16 by 16. Type the new size into the ImageSize property, if you need to:
Graphic Buttons
Adding graphics to your buttons is quite easy. Add a button to your form, using the toolbox area on the left. Change the Name property to btnBack. Delete the default text from the Text property of the button, leaving it blank. Resize your button to a suitable size.To add an image from your ImageList, locate the ImageList property for btnBack. From the dropdown box, select the name of your ImageList:
if (webBrowser1.CanGoBack)
{
{
webBrowser1.GoBack();
}
We're using an if statement first to check whether there is a page to go back
to. This is done with the CanGoBack property of the WebBrowser object.If there is a page to go back to, we then use the built-in GoBack function. This will force the browser to go back to the page you were previously looking at.
Exercise
Add four more buttons to your Form. Set up the following properties for your buttons:
Name: btnForward
Image: An image of your choice
Image: An image of your choice
Name: btnHome
Image: An image of your choice
Image: An image of your choice
Name: btnStop
Image: An image of your choice
Image: An image of your choice
Name: btnRefresh
Image: An image of your choice
When you're done, your form may look something like ours:Image: An image of your choice
Exercise
Below, you'll find four pieces of code. Add the right code to the appropriate button:
if (webBrowser1.CanGoForward)
{
{
webBrowser1.GoForward();
}
webBrowser1.Stop( );
webBrowser1.GoHome( );
webBrowser1.Refresh( );
So you're adding code to each of your remaining four buttons. When you're done,
all four buttons should work, when you run your programme.In the next lesson below, we'll take a look at how to add Tool Tips.
0 comments:
Post a Comment