140 likes | 197 Views
Learn how to use Checkbox, Radio Buttons, Date Time Picker, Masked Text Box, List Boxes, Combo Boxes, and Spinner Control efficiently in your application for better user interaction and data input accuracy.
E N D
Topics • Check Boxes • Radio Buttons • Date Time Picker • Masked Text Box • List Boxes • Combo Boxes • Spinner Control “Those parts of a computer you can hit with a hammer are called hardware; those program instructions you can only curse at are called software” Unknown
Check Boxes • Check boxes enable the user to indicate a single “Boolean” (Yes or No) state by checking or unchecking the box • The control’s Checked property will be read as either True or False • The CheckChanged event executes if the box state is changed by the user or in code • The Text property provides a label and a hot key • Selecting the hot key toggles the checked status of the box • All check boxes act independently
Radio Buttons • Radio buttons belong to a group • All buttons directly on the face of the form belong to the same group • All radio buttons in the same group box are in the same group • Only one button in a group may be pressed at a time • Selecting one in a group unselects all others • All button CheckChanged events execute • The Checked property indicates whether checked or not
Date Time Picker Control • Presents a calendar that lets user find a date easily • Value property contains the selected date, including the current time as a datetime data type • Text property is a string representation of the Value (not available at design time) • Default Value is current system clock time • May set value in code • Other date formats are available • ValueChanged event is the default event • Very useful with date-time functions (later)
Masked Text Box • Provides various predefined as well as custom formats to force user input into a “mask” • Typing forces characters into available mask spaces • Control also validates input • No letters allowed in the Phone Number mask • Selecting control and thenproperties arrow gives quick access to mask dialog • Many controls have this quick access feature
Masked Text Box (cont.) • TextMaskFormat propertydetermines if mask charactersare included in the Text property of the control • Default is IncludeLiterals (they are) • You may wish to use ExcludePromptAndLiterals • Same behavior for CutCopyMaskFormat property
List Boxes and Como Boxes • All of the properties and methods illustrated in code for the list box form work on combo boxes as well • Reading • Adding & removing items • Setting selected item • Code • User selection • Sorting • Text property gives access to current text
Adding List Items at Design Time • Add the control • Select the Items property in property window ORSelect the properties arrow on the control & choose “Edit Items” • Add one item per line in the edit window • These items willbe the initial contents of the list or combo
Adjusting List Items at Run Time • ControlName.Items.Add(value) • Adds value to the end of the list • ControlName.Items.Insert(index, value) • Adds the value into the list position specified by index • Other items are pushed upwards to make room • ControlName.Items.RemoveAt(index) • Removes the item in the index location • Other items are moved downward to fill in
List Items Properties • ControlName.Items.Count • Number of items in the list (1-based counting) • .SelectedIndex • Index in the list of the item that is selected • Zero-based numbering • If there are five items in the list • The .Count property = 5 • The items are indexed as 0 – 4 • This approach is used for any collection in .Net
List & Combo Box Behavior • List and Combo boxes will add vertical scroll bars when needed—allow enough width if contents are wide • List boxes and Simple combo boxes are always open • List boxes and DropDownList style combo boxes do not allow users to type in a value—must select • DropDown and Simple style combo boxes allow the user to enter a value not in the list
Group Boxes • Uses • Provide visual grouping of controls with a common caption • Allow a group of controls to be enabled or disabled or turned visible or invisible in one step • Allow you to create multiple independent groups of radio buttons • Text property labels the group box • I suggest a leading and trailing space so frame doesn’t pinch the text
Numeric UpDown (Spinner) Control • Allows user to select a numeric value using the up/down arrows • Useful properties: • Value—currently displayed number • Maximum and Minimum—smallest and largest values spinner will reach • Decimal places • Increment • ValueChanged is most useful event Use together to create a fractionally incrementing spinner