|
Microsoft.NET Compact Framework Kick Start Authors: Rubin E., Yates R. Published year: 2003 Pages: 44-46/206 |
Using the Panel ControlThe Panel control is a container for other controls. You can add controls to the Panel at design time and runtime. Panels are customarily used to group related controls. For example, the .NET Compact Framework does not support the GroupBox control, which can be used to group together RadioButton controls. Instead, you can add your RadioButton controls to a Panel to display to the user that these RadioButton s are related. Unsupported FunctionalityNone of the following properties is supported by the Panel control:
|
Using the HScrollBar and VScrollBar ControlsThe HScrollBar and VScrollBar controls allow you to add scrolling capabilities to components that do not support scrolling by default. The controls are driven by several properties. The following list contains these properties and their meanings.
A ValueChanged event is fired when the Value property changes. Trap this event to perform some action, such as change the position of a control, when the scroll bar's value changes. The following code demonstrates how to handle the ValueChanges event:
C#
private void hScrollBar1_ValueChanged(object sender, System.EventArgs e) {
this.label1.Text = string.Format("Scroll Bar Value: ",
this.hScrollBar1.Value);
}
VB
Private Sub hScrollBar1_ValueChanged(object sender,
System.EventArgs e) _Handles hScrollBar1.ValueChanged
Me.label1.Text = string.Format("Scroll Bar Value: ",
this.hScrollBar1.Value)
End Sub
Figure 3.21 shows an application with a HScrollBar control linked to a Label control. The Label control displays the Value of the HScrollBar . When you move the scroll bar, the label is updated with the new value. In this sample the Minimum is 0, the Maximum is 100, SmallChange is 10, and LargeChange is 20. The complete code for this sample can be found in the code list for this book. Figure 3.21. A Sample Application Showcasing the HScrollBar .
|
Using the ImageList ControlThe ImageList control is a non-graphical control that is meant to be a container for images. Other .NET Compact Framework controls use the ImageList control to retrieve images they need to display. This is true for the ListView , TreeView , and ToolBar controls. The usage of the ImageList with these controls is discussed in their respective sections. Images can be added to the control at design time as well as at runtime. To add an ImageControl to a Form , drag an ImageControl from the ToolBox to the application form in the Form Designer. Now click the ellipsis next to the Images property in the Properties window. This will bring up the Image Collection Editor (see Figure 3.17). Use the Image Collection Editor to add the images to the ImageList . It is important to note that the images will be resized to 16 x 16 pixels by default. You can set the ImageSize property if you want the images to be resized differently. These images also get imported into the resource file for the application. You need not deploy the images along with the application, because they will be embedded inside the application assembly. Images can also be loaded at runtime. The ImageList control exposes an Images property, which represents the list of images stored in the control. The Images property provides the Add method, which allows you to add images to the list of images. Interestingly, this method will add the image to the head of the list (index 0) ”not the tail of the list, like other methods that add objects to collections would. The Add method can accept either a System.Drawing.Icon or a System.Drawing.Image . Images loaded at runtime can be either loaded from the file system or loaded from the assembly's resource by using the ResourceManager . The following code demonstrates how to load an image from the assembly's resource file:
C#
BitMap image =
new BitMap(Assembly.GetExecutingAssembly().GetManifestResourceStream("image1.jpg");
ImageList imgList = new ImageList();
imgList.Images.Add(image);
VB
Dim imgLst as new ImageList()
Dim image as BitMap
image = new _
BitMap(Assembly.GetExecutingAssembly().GetManifestResourceStream("image1.jpg")
imgList.Images.Add(image)
|
|
Microsoft.NET Compact Framework Kick Start Authors: Rubin E., Yates R. Published year: 2003 Pages: 44-46/206 |