The information in this article applies to:
- Microsoft Visual FoxPro for Windows, version 3.0
SUMMARY
The "Using Spinners" section in chapter 11 of the Visual FoxPro Developer's
Guide gives the following incorrect information:
If you want a user to be able to spin through a range of dates,
you could size the spinner so that only the buttons are visible and
position a text box beside the spinner buttons.
It is not possible to size a spinner so that only the buttons are visible.
The example in this article shows how to make a Day Date spinner and make
it appear to be a single control.
MORE INFORMATION
- Create a new class called DayDateSpin based on Container.
- Store it in MyLib.vcx.
- Set the following properties for the DayDateSpin container:
BackStyle = 0 - Transparent
BorderWidth = 0
Height = 24
Width = 164
- Add a text box to the container, and set these properties:
FontName = Courier New && Or any nonproportional font
FontSize = 9
Format = k && Highlights the text box when the focus gets set to it.
Height = 22
Left = 0
ReadOnly = .T. && Keeps the user from editing the text box
Top = 1
Width = 148
- In the Init event procedure of the text box, add this code:
THIS.Value = PADR(CDOW(DATE()),11) + DTOC(DATE())
** This puts current day and date in the text box when the form starts
- Add a spinner to the container and set these properties:
FontSize = 1
Height = 24
Left = 146
Top = 0
Width = 18
- On the Format menu, click Send to Back
- Add the following code to the spinner's DownClick event procedure:
dMyDate = CTOD(RIGHT(ALLTRIM(THIS.PARENT.Text1.Value),8))
** Gets the Date from the text box
dMyDate = dMyDate - 1 && Decrease the date by one
THIS.PARENT.Text1.Value = PADR(CDOW(dMyDate),11) + DTOC(dMyDate)
**Stores the new day of the week and date back into the text box
THIS.PARENT.Text1.SetFocus
- Add the following code to the spinner's UpClick event procedure:
dMyDate = CTOD(RIGHT(ALLTRIM(THIS.PARENT.Text1.Value),8))
** Gets the Date from the text box
dMyDate = dMyDate + 1 && Increment the date by one
THIS.PARENT.Text1.Value = PADR(CDOW(dMyDate),11) + DTOC(dMyDate)
**Stores the new day of the week and date back into the text box
THIS.PARENT.Text1.SetFocus
- Save and close the class.
- Create a new form. Then click the View Classes Icon on the Form
Controls toolbar. Click Add, and select MyLib.vcx.
- Pick the DayDateSpin class from the Form Controls toolbar, and place it
on the form.
- Save and run the form. Click the up arrow or down arrow to see the day
and date go up or down.
REFERENCES
For more infromation about creating classes and working with Visual FoxPro
controls, please see chapters 10 and 11 in the Developer's Guide.
|