RibbonX for Dummies: Chapter 6 (Part 2) (
Page 6 of 6 )
Including a date
One of the problems that occurs most often with forms is that users enter the
date incorrectly. People are forever forgetting the current date (or they don't
have a calendar handy for looking up the precise date when they do remember
the approximate date). The code in this section helps a user enter an
accurate date using one of two methods. Either the user lets the application
calculate the date (based on some static criterion such as the time interval)
or the user uses a calendar to choose the date. Listing 6-15 shows examples
of both scenarios.
The DateLastMonth() callback shows an example of a date calculation (the
most complex for the example). The code begins by creating a variable that
contains the number of days in the current month. When the application subtracts
this value from the current date, it receives the proper date from the previous
month. The calculation relies on the DateTime.Today.Subtract()
method, which requires a TimeSpan as input. As always, the code must call
the ThisAddIn class to make the actual entry.
The calendar method relies on the form shown in Figure 6-15. The user
chooses a date in the dialog box and clicks OK to make the date entry. The
code obtains the information directly from the MonthCalendar control
(make sure you make the control public). Notice that the code calls the same
ThisAddIn class method as the DateLastMonth() callback to add the date
to the form.
The final method appears as part of the ThisAddIn class. The application
uses the following method to add all of the dates to the form:
public void InsertDateInEmpReqField(String InsertDate)
{
// Define the field to fill.
object SelectEmpReq = (object)"ReqDate";
// Insert the date into the field.
Application.ActiveDocument.FormFields.get_Item(
ref SelectEmpReq).Result = InsertDate;
}
As with the other form methods, the InsertDateInEmpReqField()
method begins by creating a variable to represent the name of the field on
the form. It then uses the Application.ActiveDocument.FormFields.
get_Item() method to add the date to the form.
Figure 6-15:
Select a
date from
the calendar
when a
static
choice
won't work.
Manipulating Society through Technology
Jeremy Bailenson, Director of the Virtual Human Interaction Lab at Stanford University, talks about virtual reality, avatars, Moore's law, how real world behaviors influence online reality, and societal manipulation through technology! >> Play video >> Read article >> See all videos