Components


What follows is a brief survey of the standard Windows Forms 2.0 components, listed in alphabetical order.

BackgroundWorker

See Chapter 18: Multithreaded User Interfaces.

BindingNavigator

See Chapter 16: Data Binding Basics and Chapter 17: Applied Data Binding.

BindingSource

See Chapter 16 and Chapter 17.

ColorDialog

See Chapter 3: Dialogs.

ErrorProvider

See Chapter 3.

FolderBrowserDialog

See Chapter 3.

FontDialog

See Chapter 3.

HelpProvider

See Chapter 3.

ImageList

Controls like TreeView and ListView contain tree nodes and list-view items whose images come from an ImageList component. ImageList manages a collection of images of the same size, color depth, and transparency color (as determined by the Size, ColorDepth, and TransparencyColor properties). The images themselves are stored in the Images collection and can contain any number of Image objects. You can edit the Images collection directly using the Images Collection Editor, as shown in Figure D.1.

Figure D.1. Images Collection Editor


To use ImageList after the images have been populated in the editor, you pull them by index from the Images collection property:

int imageIndex = -1; void timer_Tick(object sender, EventArgs e) {   ++this.imageIndex;   if( this.imageIndex == 4 ) this.imageIndex = 0;   this.BackgroundImage = this.imageList.Images[this.imageIndex]; }


What's nice about this code is that all the related images come from a single place. However, the ImageList component has some limitations:

  • You can't edit an image after it's been added; you must remove the old image and add the edited image.

  • The image can have only a fixed size of up to 256 pixels in either dimension.

  • The Images Collection Editor is difficult to use for images larger than 16 pixels in either direction, because it shows images only as 16 ¥ 16 pixels and squeezes larger images to fit.

  • You must set ColorDepth and Transparency before adding images for them to be applied.

  • Images are available only as type Image and not directly as type Icon, so if you need the Icon type you must convert it from Image.

NotifyIcon

See Chapter 2: Forms.

OpenFileDialog

See Chapter 3.

PageSetupDialog

See Chapter 8: Printing.

PrintDialog

See Chapter 8.

PrintDocument

See Chapter 8.

PrintPreviewDialog

See Chapter 8.

SaveFileDialog

See Chapter 3.

SoundPlayer

SoundPlayer is an enigma: Located in System.Media, SoundPlayer is a class that cannot be added to the Toolbox and, consequently, can't be dropped onto a form in VS05 at design time. However, it is a very useful class that happens to make it easy to play sound files:[2]

[2] Be aware, though, that SoundPlayer is geared to play only .wav files encoded with pulse-code modulation (PCM).

using System.Media;  ...  void soundPlayerButton_Click(object sender, EventArgs e) {    SoundPlayer soundPlayer =      new SoundPlayer(@"C:\WINDOWS\Media\tada.wav");    soundPlayer.Load();    soundPlayer.Play(); }


SoundPlayer also provides support for loading sound files from streams and URLs both synchronously and asynchronously, and for looping playback. Additionally, System.Media offers shortcuts for playing common system sounds using the SystemSounds class:

System.Media.SystemSounds.Exclamation.Play();


System sounds include Asterisk, Beep, Exclamation, Hand, and Question.

Timer

See Chapter 18.

Tool Tip

See Chapter 3.




Windows Forms 2.0 Programming
Windows Forms 2.0 Programming (Microsoft .NET Development Series)
ISBN: 0321267966
EAN: 2147483647
Year: 2006
Pages: 216

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net