Control items in versions Professional and Enterprise
In this section it is told about the several most often used controlling elements delivered in versions Professional and Enterprise of system Visual Basic. All these elements are accessible through dialogue panel Project|Components.
Controlling element of Microsoft Comm 5.0
By means of control items communications it is possible to create easily own communication packet working through the modem with a telephone line (not with network Internet). Also it is possible to change independently its adjustments by means of numerous properties. Currently the maximum accessible speed of an exchange is 28 800 baud. Except speed of an exchange it is possible to change such adjustments as number data bit, presence of parity bit, etc. the Control item communications serves as the brilliant example showing advantages of an event-driven programming language. For example, it is possible to create a control item caused only at arrival of a signal of activity from the communication port.
The table resulted more low contains key properties of control items communications.
|
|
|
| CommEvent | Keyword of control items communications. Various values of this property correspond both to events, and communication port errors. For example, if value of this property is equal to a constant comEOF (=7) it speaks about presence of the character of the end of a file (ASCII 26) in the reception buffer. |
| CommPort | At record installs the communication port address, at reading - returns the address of current port. (1 - for port Sosh 1,2 for port Corn 2 etc.) |
| Settings | Installs or returns following parameters: speed of an exchange, parity bit presence, number data bit, number of stop bits. It can be installed both at element creation, and in an application operating time. |
| PortOpen | Opens and closes the communication port. |
| Input | Returns the characters which are in the buffer of reception. |
| Output | Sends a line of characters to the sending buffer. |
The control item communications reacts only to event OnComm. This event corresponds to change of value of property CommEvent. At event origin it is possible, analyzing value of property CommEvent, to cause the appropriate handler of event.
The same as also remaining controlling elements, a control item communications gives the chance easy adjustment of properties through the dialogue panel. For this purpose it is enough to pass in window Properties to the user adjustments (Custom). In the appeared dialogue panel it is possible to install necessary control properties.
Example of usage of a control item communications.
As the elementary example of usage of a control item communications we result the program accepting information through one of communication ports (in the given example the port the CATFISH I is used):
Private Sub cmdGetData Click ()
Dim Foo As Integer, TheData As String MsCornml. CommPort = 1 ' COM1
' 28800 baud, no parity, 8 data, and 1 stop bit.
' the Communications control cannot go faster than 28800 baud
MsCornml. Settings = "28800, N, 8,1"
MsCornml. InputLen = 0 ' Clear the comm buffer
MsCornml. PortOpen = True
' Send the usual wake up signal to the modem.
MsCornml. Output = "AT" + Chr $ (13)
Do
Foo = DoEvents ()
MsCornml. InputLen = 0 ' clear buffer
TheData = TheData + ComiTil.Input "TheData will contain the data
Loop Until Commi. CommEvent = comEvEOF
MsCornml. PortOpen = False ' close the port
End Sub
Controlling element of editing with input mask Masked Edit Control 5.0
Application of an element of editing with an input mask allows to control the information entered into the panel of the text, without branching code writing. Usage of an element of editing with an input mask reminds usage of the normal text panel with that only a difference that it is possible to restrict entered characters without branching code writing in the field Key Events. Also it is possible to use certain characters for instructions to the user about type and appearance of the entered data (for example, telephone number or number of the social insurance). The controlling element of editing with an input mask belongs to the class of elements with the certain data (data - aware controls).
By operation with elements of editing with an input mask the most important is property Mask. It is possible to install this property both at element creation, and in runtime. This property is intended for the mask job on which the user enters the data. For example, if it is necessary to receive phone number in a format accepted in the USA it is necessary to install property Mask as follows:
MaskEdBoxl. Mask = "(###) -###-####"
As a result the element of editing with an input mask will look how is presented in a picture at the left.
(Naturally, at creation of this element it is not necessary to use a field of restrictions in window Properties.)
The element of editing with an input mask has own dialogue panel with the property list.
Generally the line set by property Mask, works similarly to a line of a format in expression Format. So, in the previous example the character "#" designates digit, and the character "-" is used as a separator.
Most often used characters of a mask are resulted in the following table.
|
|
|
|
|
The digit is required. |
|
|
Decimal point. Appearance of the given character at an output depends on current adjustments of system Windows. |
|
|
Set separator. As well as in the previous case, appearance of the deduced character depends on operating system adjustments. |
|
|
Separator for time field. |
|
|
Separator for a date field. |
|
|
|
|
|
The letter is required. For example, and - z or And - Z. |
|
|
ASCII character which code is in an interval 32-126 or 128-255 is required. |
|
|
Translates all entered characters in an uppercase. |
|
|
Translates all entered characters in the lower register. |
|
|
The letter or digit is required. |
|
|
Allows to enter a letter or digit. |
|
|
Allows to enter digit. |
|
|
|
| Blank line ("" in the code) | (It is used by default.) means absence of an input mask. In this case the panel of editing with an input mask behaves as the normal text panel. |
| ## - ??? - ## | Mask for date input (corresponds to the standard accepted in the USA). |
| ## - ## - ## | The same. Except that the title of month is replaced with its number. |
| ##:##?? | Mask for time input (the expanded format). |
| ##:## | Mask for time input (the reduced format). |
Control item means of multimedia
Devices of multimedia, such as a compact disk player, become an integral part of the modern personal computer. The idea of joint join of the text, a sound and the image really is a front line for our time.
Control items means of multimedia give the chance to the user to use interface commands media control interface (MCI). Commands MCI allow to control audio- and video devices and do not depend on the used equipment. By means of a control item means of multimedia it is possible to send such commands as start, forward wind, backward wind, a pause etc. this - control item contains All about 60 properties, therefore instead of their detailed description only main principles of operation proceeding from which it is possible to adjust independently a control item here are resulted, using page Custom Properties.
It simply dial-up of buttons with titles: Prev, Next, Play, Pause, Bask, Step, Stop, Record and Eject.
Every time when the user pushes one of buttons, it is necessary to send appropriate command MCI. But before to make it, it is necessary to solve, whether it is necessary:
That's all!
Control item fragments of Microsoft Picture Clip Control 5.0
The control item Microsoft Picture Clip Control fragments represents one more location mode of bitmap images (bitmaps) in a control item. The same as and in a case with "brisk" buttons, the similar technology allows to save system Windows resources, and also to raise speed of access to the image. For example, such element can be used for toolbar creation that allows the user to adjust toolkit under own discretion. In this case instead of reading of each tool as separate bitmap image, it is possible to make it one action, used a control item fragments.
Because of complexity in obtaining of one big bitmap image from the several files, a control item necessary at usage by fragments, normally use element List Image.
Anyway it is useful to look at the program using a control item by fragments (for example, the program
C:\VB\Samples\comptool\Picclip\Redtop.vbp).
Dialogue control item with bookmarks of Microsoft Tabbed Dialog Control 5.0
This control item gives the chance to create dialogue panels with bookmarks, like dialogue panel Tools/0ptions in system Visual Basic. This element allows to create group of dialogue panels, each of which is supplied by own bookmark.
As it was possible to note, the first step at creation of such element is setting of its size necessary for information output in each bookmark.
Example: usage of a control item by labels
At creation of this controlling element it is necessary:
As well as in a case with normal dialogue panels, it is possible to use in a control item bookmarks of button OK and Cancel.
Controlling elements of Microsoft Windows Common Controls 5.0
It is possible to add one action to a toolbar eight controlling elements. For this purpose it is necessary to select from dialogue panel Project|Components an appropriate line. In this section we briefly describe these controlling elements.
Controlling element Image List
Usage of element Image List - it one more location mode of group of images in one place. These images can be used in any part of application (for example, as images for a toolbar). The key moment by operation with element Image List is the understanding of principles of operation of objects List Image (and also collections of elements List Image) which define the images used in the controlling element. (It is possible to consider element Image List as the container for collection List Image.) most easier to work with element Image List by means of its property (Custom), appearing of dialogue panel Property Pages.
Bookmark Image on this panel allows to add images at element creation.
(In the course of operation it is possible to add images in collection List Image by means of method Add).
Controlling element Image List can store simultaneously both bitmap images, and icons. The same as and for other collections, it is possible to refer to stored images by means of an index or a key. For example, if to assign image ImageListI. Listlmages (l), a command
Set Picturel. Picture = ImageListI. Listlmages (1).Picture
' set Picture.
Fills the picture panel with the first image from a collection. (Numbering in collection List Images begins with 1.)
It is necessary to mark that there is no restriction on the size of the separate image, but total number the image which can be считано, is restricted by the sizes of accessible storage.
Controlling element List View
Controlling element List View allows to deduce elements on the display various ways - in essence, these are the same ways which could be watched, working with a desktop of system Windows 95. For example, it is possible to use List View for alignment of elements on columns (with title of each column or without it). Elements thus consist of an icon and the text. Various methods of representation of an element are described by property View which possible values are resulted in the table.
|
|
|
|
|
|
|
(It is used by default.) each object List Item consists from полноформатной icons and labels. |
|
|
|
Each object List Item is represented an icon of the small size and a label allocated to the right of an icon. All elements are aligned across. |
|
|
|
As well as in the previous case, each object.состоит from an icon of the small size and the text Smetki allocated to the right of an icon. But at.этом all objects are represented in the form of the list. |
|
|
|
Each object of element List Item is represented an icon of the small size and a label. Icons and labels are allocated in columns. Also for an output of the explanatory text additional columns are used. |
Represented elements of controlling element List View are called List Item as objects. Each object List Item has own properties describing its behavior. Most important of them are presented in the table further.
Also it is possible to select title for a deduced column from controlling element List View. For this purpose it is necessary to install value True/False for property Hide Column Headers. The appropriate title is stored in object Column Header, and all titles of columns are collected in collection Column Headers.
|
|
|
|
|
Returns or allows to install an index or a key for an icon, ассоциированной with object List Item. |
|
|
Informs on that object List Item has been selected by the user (or allows to select it independently). |
|
|
Returns or allows to install an index or a key for an icon of the small size, ассоциированный with object. |
|
|
Returns or allows to install explaining line for a subelement, ассоциированного with special object List Item. |
|
|
Sets the text which will be visible the user. |
Controlling element Progress Bаr
Usage of controlling element Progress Bar (.линейка progress) is similar to usage of a vertical ruler in a control item in the sizes. It represents a ruler filled with square-topped units. Further key properties of this element are described.
Property Align is intended for automatic alignment of position of an element on the screen. Possible values of this property are shown in the following table.
|
|
|
|
|
(It is used by default.) the size and element position can be arbitrary. |
|
|
The ruler is allocated above forms and has the width equal to width of the form. |
|
|
The same, but the ruler is allocated from below from the form. |
|
|
The ruler is left-justified forms, and its height is equal to form height. |
|
|
The same, but the ruler is right-justified forms. |
In the same way, as well as in a case with scroll bar, it is possible, changing properties Min and Mach, to install boundaries of a represented ruler of progress. Property Value defines progress current position.
Let's consider an example: let it is necessary to represent an amount of time which has transited from the beginning of any process. For this purpose we create a control item the timer, a label and a progress ruler.
Now we install for property Min value 0, and for property Mach - value 60. Property Interval for a control item the timer should be installed in 1000 (that corresponds to 1 second). Then the following fragment of the code will represent by means of a ruler of progress past tense (in seconds).
Private Sub Timerl_Timer ()
Static Progress As Integer
Progress = (Progress + 1) Mod 60
Labell. Caption = Str $ (Progress) AND "seconds elapsed."
ProgressBarl. Value = Progress
End Sub
Controlling element Slider Control
Controlling element Slider (бегунок) works similarly to a scrolling ruler. It represents a small ruler with divisions on which it can be moved бегунок.
The user can move бегунок normal pulling or clicking a mouse from the appropriate side of a ruler. For this sang it is possible to apply the keypad also. The same as and for a scrolling ruler, key properties are Mach, Min and Value that, accordingly, defines maximum, minimum and current position бегунка. Key event Scroll arises every time when the user moves бегунок.
Controlling element Status Bar (status bar)
Controlling element Status Bar represents a line (normally allocated in the lower part of the form) in which the current state of application is deduced. (For example, Microsoft Word text editor uses status bar for instructions of number of current page, and also for the information on insert mode or changeover presence, etc.). Property Align specifies a method of alignment for status bar. Values of this property same as well as for controlling element Progress Bar. Each status bar can be divided a maximum on 16 areas (panels). At status bar creation it is possible to add areas, using page Panels.
By means of the dialogue panel it is possible to add the text or a picture to any area of status bar. In the course of operation at usage of method Add normally at first declare a variable describing type of the panel, and then use method Add which syntax is presented more low:
Set PanelObject = NamedfStatusBar. Panels. Add {[index], [key], [text], [style], [picture])
Where all parameters are optional. (Owing to that this method does not support concrete arguments, it is necessary to use inverted commas for instructions of not included elements.) the parameter index is used for an area enumeration. If this parameter misses, by default given element will be added in the end of the list of existing areas. (As it is possible to use no more than 16 areas value of parameter index should be in an interval 1-16). Parameter Key (the same as and in any collection) represents one more method to install the link to an element. The parameter text sets the text for area. The parameter style installs an information output method in status bar. Possible values of this parameter are collected in the following table.
|
|
|
|
|
(It is used by default.) allows to deduce the arbitrary text or a picture. The deduced text is defined by value of property text. The picture output is carried out by means of method Load Picture. |
|
|
If key CAPS LOOK has been pushed, word CAPS is deduced by distinct characters, otherwise - the word is deduced by the muffled gray color. |
|
|
The same, but for key NumLock. |
|
|
The same, but for INSERT key. |
|
|
The same, but for key ScrollLock. |
|
|
Serves for an output of current time in a current format used by system. |
|
|
Serves for an output of current date in a current format used by system. |
And at last, the optional parameter picture sets the appropriate bitmap image. For example, the following fragment of the code:
Private Sub Form Load ()
Dim MyPanel As Panel
StatusBar1.Panels (1).Text. = "Default panel exits already"
Set MyPanel = StatusBarl. Panels. Add (sbrTime)
Set MyPanel = StatusBarl. Panels. Add ("Panel demo")
Set MyPanel = StatusBarl. Panels. Add (LoadPicture ("C:\VB\ICONS\TRAFFIC\TRFFC01.ICO"))
End Sub
Creates status bar.
Let's note what to have to use variables of object for creation of the panel with appropriate properties. However it is possible to replace it with two code lines, the first step creating the panel.
For example:
MyPanel = StatusBarl. Panels. Add
MyPanel == StatusBarl. Panels (2).Text = "Panel demo"
One more property connected to status bar, property AutoSize is. It can accept following values.
|
|
|
|
|
(It is used by default.) forbids automatic setting of the size. |
|
|
At change of the size of parent status bar the new size of area is automatically calculated. (The width of area cannot be less, than the width defined by property MinWidth of a window of a state). |
|
|
In the presence of an empty seat the size of the panel corresponds to the width necessary for a location of an inscription. |
Controlling element Tab Strip
Element Tab Strip is one more method of creation of the components which appearance is similar to a control item with bookmarks. However owing to that it is not the container, its usage is deprived the flexibility inherent in a control item with bookmarks. For this reason the given element here is not considered.
Controlling element Toolbar
Element Toolbar gives the chance to build in toolbars applications easily. Possibilities of the given means are similar under the content to possibilities of element Tool Tips (the given element will be described in one of following sections). At first, property Align sets a toolbar site. By default value of property Align is equal 1 (Top) that places the panel in the upper part of the form.
Further, if it is necessary to place the image on a toolbar at first it is necessary to save it in element Image List (this action well both in design time, and in application runtime). It is necessary to consider that for assignment of images in design time it is necessary, that element Image List and a toolbar were ассоциированы with the same working form.
After saving of images in element Image List it is necessary to use a name of an appropriate element as value of property Image List. For example, we add a toolbar and controlling element Image List on the empty working form, leaving the names installed by default. Now, if to look at the first page from dialogue panel Property Pages of a toolbar it is possible to see that drop down list Image List shows element Image List 1.
After correspondence for element Image List is installed, it is possible to assign the image from element Image List to any buttons, using page (Buttons) the dialogue panel. It can be made, installing the necessary number of the image from Image List in text panel Image. For example, in an example on the right to the second column the first image from element Image List is assigned.
Example: operation with a toolbar in the course of performance
Controlling element Toolbar contains a collection from buttons. In runtime it is necessary to use methods Add and Remove for adding and removal of buttons from the panel. To naturally, each button there corresponds the event Button Click, allowing to produce necessary actions at pushing by the user the button.
Normally for usage of method Add it is necessary to declare a variable of type Button. Syntax метола Add can be written down as follows:
Set ButtonObject = NameOfToolBar. Button. Add ([index], [key], [caption], [style], [image])
Where all parameters are optional. (Owing to that this method does not support concrete arguments, it is necessary to use inverted commas for instructions of included elements.)
The parameter index specifies the button location in a collection. If this parameter misses, the button automatically is located in the list end. Parameter Key (the same as and in any collection) represents one more method to create the reference to the button. Parameter Caption serves for the job of the deduced text for object Button. Property style sets a method of an output of the button. Possible values of this property are presented in the following table.
|
|
|
|
|
(It is used by default.) specifies that the button is the normal pushed button (push button). |
|
|
The button is a test button (check button). |
|
|
The button belongs to group. It means that the given button cannot be pushed until other button of group is pushed. At the same time only one button from group can be in a pushed state. |
|
|
The button represents the normal separator having standard width in 8 пикселов. |
|
|
The button represents a separator with variable width |
And, at last, the parameter image sets a key or an index for association with the image beforehand saved in element Image List.
The same as and in a case with object Panel, it is possible to add at first buttons, and then to describe their properties. For example, if it is necessary to add at a design stage only one button with an inscription "First button", it is necessary to use a following fragment of the code:
Tooibarl. Buttons. Add
Toolbarl. Buttons (2).Caption = "Second button"
Tooibarl. Buttons. Add
Toolbarl. Buttons (3).Caption = "Third button"
Labels ToolTips
ToolTips represent the small labels used for the short description of the tool. Such label appears approximately in 1 second after the mouse pointer is located on the tool, and disappears after shift of the pointer of the mouse. For adding of such possibility in a toolbar it is necessary:
Controlling element TreeView, judging by its title, allows to create a tree similar on used in Windows Explorer. The separate objects making a tree, are called as nodes (nodes), and, accordingly, controlling element TreeView contains collection Nodes. The upper node is underlined by means of property Root. Behind the additional information on controlling element TreeView we send the reader to reference system.