Windows Control: The Panel |
|
Introduction |
The panel is a rectangular object that can provide various valuable services for application design. A panel allows you to design good-looking forms by adjusting colors and other properties. A panel can also be used as control delimiter for objects that behave as a group. An example would be a set of radio buttons. As a member of the family of control containers, a panel can be used to hold or carry controls placed on it. When a panel moves, it does so with the controls placed on it. When a panel is visible, the controls placed on it can be visible too, unless they have their own visibility removed. |
When a panel is hidden, its child controls are hidden too, regardless of their own visibility status. This property also applies to the panel's availability. Panels are not transparent. Therefore, their color can be changed to control their background display. A panel is a complete control with properties, methods, and events.
To add a panel to a container, you can click the Panel button from the Toolbox and click the desired location on the container. Unlike the form, during design, a panel must primarily be positioned on another container which would be a form or another panel. To programmatically create a panel, declare a handle to Panel, allocate memory for it using the new operator, and add it to its parent. Here is an example: Imports System.Drawing Imports System.Windows.Forms Module Exercise Public Class Starter Inherits Form Private pnlContainer As Panel Dim components As System.ComponentModel.Container Public Sub New() InitializeComponent() End Sub Public Sub InitializeComponent() Text = "Domain Configuration" Width = 320 Height = 210 Location = New Point(140, 100) StartPosition = FormStartPosition.CenterScreen pnlContainer = New Panel() pnlContainer.Location = Point(20, 20) pnlContainer.Size = New Size(100, 60) Controls.Add(pnlContainer) End Sub End Class Function Main() As Integer Dim frmStart As Starter = New Starter Application.Run(frmStart) Return 0 End Function End Module
By default, a panel object is drawn without borders. If you want to add borders to it, use the BorderStyle property. It provides three values that you can set in the Properties window: None, FixedSingle, and Fixed3D and their effects are as follows:
To programmatically specify the border style, assign the desired value to the Panel.BorderStyle property. Here is an example: Public Sub InitializeComponent() Text = "Domain Configuration" Width = 320 Height = 210 Location = New Point(140, 100) StartPosition = FormStartPosition.CenterScreen pnlContainer = New Panel() pnlContainer.Location = New Point(20, 20) pnlContainer.Size = New Size(100, 60) pnlContainer.BorderStyle = BorderStyle.Fixed3D Controls.Add(pnlContainer) End Sub A panel can be used as a button, in which case the user would click it to initiate an action. A property that is highly used on panels (and forms) is the Color. If you change the BackColor property, the new color would cover the face of the panel. |
|
||
Home | Copyright © 2007-2011 FunctionX | |
|