Basics Active X Controls in VB
·
Text Box Control = The text box is the primary mechanism
for displaying and entering text . The text control is a small text editor that
provide all the basics text -editing facilities.
Basics properties
- Multiline =
The text box controls will hold a single or multi lines of text.
- Scroll bar =
This property control the attachment of scroll bars to the text box
control if the text exceed the control dimension. Scroll bars will appears
in multiline textboxes even if they are not needed or the text does not
exceed the dimension of the control.
- Max length =
This property determines the number of chararcters the text box control
will accept its default value is zero.
Manipulating
the control text
1.
Text =
The most important properties of the textbox controls in the text property ,
that hold the control text. This property is also available at design time so
that you can design some initial text to the control.z
2.
Password Characteristics = If you can set this value to an asterisk
("*") . Example : The user sees an asterisk in the place of every
char typed.
Text
Selection
The text box control provide three properties for
manupulating the text select by the user.
1.
Seltext =
The Seltext properties returns the selected text . If you want to
2.
manipulate
the currently selected text from within your code use the seltext
property .
3.
Selstart =
The position of the first char of the selected text somewhat like placing the
cursor at a specific location in the text and selecting text by dragging the
mouse.
4.
Sel length =The
sellength property return the length of the selected text.
Example :
text2.text=text1.selstart
text2.text= text1.sel length
Dim a
Dim b
Dim c
Private Sub Command1_Click()
If Option1.Value = True Then
a = Text1.Text
b = Text2.Text
c = (a * 2.75 * b) \ 100
Text3.Text = c
Text4.Text = c + a
End If
If Option2.Value = True Then
a = Text1.Text
b = Text2.Text
c = (a * 3 * b) \ 100
Text3.Text = c
Text4.Text = c + a
End If
If Option3.Value = True Then
a = Text1.Text
b = Text2.Text
c = (a * 2.25 * b) \ 100
Text3.Text = c
Text4.Text = c + a
End If
End Sub
- Combo box & List box
- Combo Box = The combo box control also contain multiple items but occupies less space on the screen. The combo box control is an expandable list box control : the user can expand it to make a selection and restracts if after the selection is made. User can enter new information in the combo box , rather than being forced to select only the items listed.
- List box = The list box control occupies a user specified amount of space on the form and is populated with a list of item , the user can select one or more with the mouse . The items must be inserted in the list box control through the code. Each new property in the list property must be entered on a seperate line .To change line , press (ctrl
+enter).
- Multi select = This property determines how the user can select the list items and must be set at design time (at runtime , you can only read property value). The multi select property values determines whether the user can select multiple items.
Setting
|
Description
|
O
|
Multiple selection not allowed , the default.
|
1
|
Simple multiple selection.
|
2
|
Extended multiple selection press
shift and
click the mouse
|
- Sorted = Items can be inserted by the application into a list box or combo box cotrol , but inserted them in the proeper place and maintaining some sort of organisation can be quite a task for the programmer . If you want the items to be always sorted , set the control sorted property to true.
“AA”
“Aa”
“aA”
“aa”
“BA”
“ba”
|
- Style = This property determines the appearance of the control . It value can be 0 (standard) or 1 (check box).
List box control method
- Add items = To add items to the list , use the Add item method.
List1.Additem item , index
- Remove item = To remove an item from the list, you must first find its position (index) in the list , which you must then supply to the remove item method.
Dim a as integer
a = text2.text
list1.remove(lst1.count-1)
- Clear = The clear method removes the item from the control.
List1.clear
- List count = This is the number of items in the list . The items in the list can be accessed with an index value , that goes from 0 to listcount - 1.
- Selected = This property in an array , similar to the list property , with element that have a true or a false value , depending on the status of the corresponding list item.
Coding
Private Sub Command1_Click()
Text3.Text = Combo1.List(Combo1.ListIndex)
Combo2.AddItem (Text3.Text)
End Sub
Private Sub Command2_Click()
Text3.Text = Combo2.List(Combo2.ListIndex)
Combo1.AddItem (Text3.Text)
End Sub
Private Sub Command3_Click()
Combo1.AddItem (Text1.Text), 0
End Sub
Private Sub Command4_Click()
Combo1.Clear
End Sub
Private Sub Command5_Click()
If Combo1.ListCount > 0 Then
Combo1.RemoveItem (0)
Else
MsgBox ("combobox is empty")
End If
End Sub
Private Sub Command6_Click()
Combo2.AddItem (Text2.Text), 0
End Sub
Private Sub Command7_Click()
If Combo2.ListCount > 0 Then
Combo2.RemoveItem (0)
Else
MsgBox ("combobox is empty")
End If
End Sub
Private Sub Command8_Click()
Combo2.Clear
End Sub
If list1.listcount>0 then
- Remove ( error not come ) condition
list1.removeitem(0)
else
msgbox(list box is empty, you cannot add)
end if
0 comments:
Post a Comment