Some times if you are asked to create an application
for a store that sells a specific number of items based on a fixed list,
you may ask for the list of items so you can create its elements in the
application. Here is an example:
For such an application, when the list of items
changes, you may have to modify the application, recompile, and
redistribute (or re-install it). One solution to this problem would
consist of providing placeholders for an employee to fill out and process
the order with them. Another problem that can be common with this type of
application is that, while the form may be crowded with too many objects,
most of the time, some items are rarely ordered.
In this exercise, to make this type of application a
little more flexible, we will use a few combo boxes that allow the user to
simply select the items that are valid for the order.
Practical Learning: Introducing Buttons
|
|
- Start a new Windows Forms Application named GCS2
- Set the form's icon to Drive:\Program Files\Microsoft Visual Studio .NET
2003\Common7\Graphics\icons\Misc\BULLSEYE.ICO
- On the main menu, click File -> New -> New File...
- In the New File dialog box, click Icon File (.ico) and click Open
- Right-click a white area in the drawing section, position the mouse on
Current Icon Image Types, and click 16x16, 16 Colors
- Design it as follows:
- Right-click a white area in the drawing section, position the mouse on
Current Icon Image Types, and click 32x32, 16 Colors
- Right-click a white area in the drawing section and click Delete Image
Type
- On the main menu, click File -> Save Cursor1
- Locate the GCS2 folder that contains the current project and display it in
the Save In combo box
- Double-click its bin folder to display in the Save In combo box
- Change the filename to Calculate.ico
- Click Save
- On the main menu, click File -> New -> New File...
- In the New File dialog box, double-click Icon File (.ico)
- Right-click a white area in the drawing section, position the mouse on
Current Icon Image Types, and click 16x16, 16 Colors
- Design the icon as follows:
- Right-click a white area in the drawing section, position the mouse on
Current Icon Image Types, and click 32x32, 16 Colors
- Right-click a white area in the drawing section and click Delete Image
Type
- On the main menu, click File -> Save Cursor2
- Make sure the bin sub-folder of the GCS2 folder that contains the current
project is selected and displays in the Save In combo box
- Change the filename to SubTotal.ico
- Click Save
- Return to the form (Form1.vb [Design]) and design it as follows:
|
Control |
Name |
Text |
Additional Properties |
GroupBox |
|
|
Order Identification |
|
Label |
|
|
Customer Name: |
|
TextBox |
|
txtCustomerName |
|
|
Label |
|
|
Date Left: |
|
DateTimePicker |
|
dtpDateLeft |
|
Format: Custom
Custom Format: dddd dd MMM yyyy |
Label |
|
|
Time Left: |
|
DateTimePicker |
|
dtpTimeLeft |
|
Format: Time |
Label |
|
|
Date Expected: |
|
DateTimePicker |
|
dtpDateExpected |
|
Format: Custom
Custom Format: dddd dd MMM yyyy |
Label |
|
|
Time Expected: |
|
DateTimePicker |
|
dtpTimeExpected |
|
Format: Time |
GroupBox |
|
|
Order Processing |
|
Label |
|
|
Item Type |
|
Label |
|
|
Unit Price |
|
Label |
|
|
Qty |
|
Label |
|
|
Sub Total |
|
Label |
|
|
Shirts |
|
TextBox |
|
txtShirtsUnitPrice |
0.95 |
TextAlign: Right |
TextBox |
|
txtShirtsQuantity |
0 |
TextAlign: Right |
Button |
|
btnCalcShirts |
|
Image: SubTotal.ico |
TextBox |
|
txtShirtsSubTotal |
0.00 |
TextAlign: Right |
Label |
|
|
Pants |
|
TextBox |
|
txtPantsUnitPrice |
2.75 |
TextAlign: Right |
TextBox |
|
txtPantsQuantity |
|
TextAlign: Right |
Button |
|
btnCalcPants |
|
Image: SubTotal.ico |
TextBox |
|
txtPantsSubTotal |
0.00 |
TextAlign: Right |
ComboBox |
|
cboItem1 |
None |
|
TextBox |
|
txtItem1UnitPrice |
0.00 |
TextAlign: Right |
TextBox |
|
txtItem1Quantity |
0 |
TextAlign: Right |
Button |
|
btnCalcItem1 |
|
Image: SubTotal.ico |
TextBox |
|
txtItem1SubTotal |
0.00 |
TextAlign: Right |
ComboBox |
|
cboItem2 |
None |
|
TextBox |
|
txtItem2UnitPrice |
0.00 |
TextAlign: Right |
TextBox |
|
txtItem2Quantity |
0 |
TextAlign: Right |
Button |
|
btnCalcItem2 |
|
Image: SubTotal.ico |
TextBox |
|
txtItem2SubTotal |
0.00 |
TextAlign: Right |
ComboBox |
|
cboItem3 |
None |
|
TextBox |
|
txtItem3UnitPrice |
0.00 |
TextAlign: Right |
TextBox |
|
txtItem3Quantity |
0 |
TextAlign: Right |
Button |
|
btnCalcItem3 |
|
Image: SubTotal.ico |
TextBox |
|
txtItem3SubTotal |
0.00 |
TextAlign: Right |
ComboBox |
|
cboItem4 |
None |
|
TextBox |
|
txtItem4UnitPrice |
0.00 |
TextAlign: Right |
TextBox |
|
txtItem4Quantity |
0 |
TextAlign: Right |
Button |
|
btnCalcItem4 |
|
Image: SubTotal.ico |
TextBox |
|
txtItem4UnitPrice |
0.00 |
TextAlign: Right |
Button |
|
btnCalculate |
Calculate |
|
GroupBox |
|
|
Order Summary |
|
Label |
|
|
Order Total: |
|
TextBox |
|
txtOrderTotal |
0.00 |
TextAlign: Right |
Label |
|
|
TaxRate |
|
TextBox |
|
txtTaxRate |
5.75 |
TextAlign: Right |
Label |
|
|
% |
|
Label |
|
|
Tax Amount |
|
TextBox |
|
txtTaxAmount |
0.00 |
TextAlign: Right |
Label |
|
|
Order Price |
|
TextBox |
|
txtOrderPrice |
0.00 |
TextAlign: Right |
|
- Click each combo box. Access its Items property and fill it up as follows:
- Click OK and save All
|
|