Ziff-Davis Enterprise 
DevSource: Microsoft Developer Resource
Add OnsArchitectureLanguagesTechniquesUsing VSForums
 
Home arrow Add Ons arrow Adding Application Calendars with Calendar Go! 4.0
Adding Application Calendars with Calendar Go! 4.0
By John Mueller

Rate This Article:
Add This Article To:
Adding Application Calendars with Calendar Go! 4.0
( Page 1 of 2 )

Review: Calendars are a necessary feature of so many applications that it's hard to list them all. That's why this Visual Studio .NET add-on is so impressive: it makes it easy to add several layers of feature depth.

You've probably used the MonthCalendar and DateTimePicker controls in an application and wondered if there's a better way to get the job done. Yes, these controls can do the job, but they often require a lot of programming, and you only get one calendar view. The Calendar Go! Bundle from Component Go! provides a better solution. Not only do you get six controls that help you work with different date aspects, but each control also provides a different view of the calendar, making it much easier to create custom applications.

I spent quite a few hours with the demonstration program before I moved on the professional version. What you see in the demo is effectively what you get with the professional version; the main difference is that the professional version comes with source code. That's right: this vendor isn't afraid to let you loose with source code. The product is that good.

ADVERTISEMENT

A Demo Version That Teaches

The best way to get started using the Calendar Go! Bundle is by exploring the various demonstrations that it provides. All work perfectly, and you can view their source code in the \Program Files\ComponentGo\CalendarGo \CalendarGo Source folder on your hard drive. The combination of the demonstrations and their code makes it easy to begin writing your first application.

The Calendar Demo demonstration takes the unusual course of displaying a Properties window, as shown in Figure 1.

Figure 1: No one else makes demonstration programs like this one. Try the Properties window to see for yourself.

I found the addition a little confusing, at first, because no one else creates demonstrations like this one. You can view the various properties to see how the vendor created the display elements. More importantly, you can modify the properties to see what happens. That's right, you can play with the demo just as you would with a real application in Visual Studio .NET. Consequently, this isn't just a demonstration; it's a programmer's training tool as well.

Using the MonthlyCalendar, WeeklyCalendar, and DailyCalendar Controls

The Calendar Go! Bundle comes with three periodic calendars: monthly, weekly, and daily. You can combine the calendars or use them separately. I found it quite easy to link them together, as shown in Figure 2. Listing 1 shows the simple code that I used.

Listing 1: Connecting Calendars Together

private void mcTest_Click(object sender, System.EventArgs e)
{
   // Change the dates on the other to entries to match.
   wcTest.FirstDate = mcTest.SelectedDateBegin;
   dcTest.FirstDate = mcTest.SelectedDateBegin;

   // Adjust the selection.
   wcTest.SelectedDateBegin = mcTest.SelectedDateBegin;
   wcTest.SelectedDateEnd = mcTest.SelectedDateEnd;
}

private void wcTest_Click(object sender, System.EventArgs e)
{
   // Change the dates on the other to entries to match.
   mcTest.FirstDate = wcTest.SelectedDateBegin;
   dcTest.FirstDate = wcTest.SelectedDateBegin;

   // Adjust the selection.
   mcTest.SelectedDateBegin = wcTest.SelectedDateBegin;
   mcTest.SelectedDateEnd = wcTest.SelectedDateEnd;
}

private void dcTest_Click(object sender, System.EventArgs e)
{
   // Change the dates on the other to entries to match.
   mcTest.FirstDate = dcTest.SelectedDateBegin;
   wcTest.FirstDate = dcTest.SelectedDateBegin;

   // Adjust the selection.
   wcTest.SelectedDateBegin = dcTest.FirstDate;
   wcTest.SelectedDateEnd = dcTest.FirstDate.AddDays(1);
   mcTest.SelectedDateBegin = dcTest.FirstDate;
   mcTest.SelectedDateEnd = dcTest.FirstDate.AddDays(1);
}

Figure 2: Combine the calendars or use them separately as needed.

As you can see, the glue code required to link calendars together is quite simple. All you need to do is select a starting point, and then highlight the target dates, as shown in Figure 2.

At first, I was concerned that the FirstDate property would skew the calendar output — that you might see weeks starting on Wednesday instead of Sunday. However, the controls automatically adjust the FirstDate property to match the standard week that you set up.

Highlighting the same dates in other calendars that you selected in a target calendar is relatively easy when using the MonthlyCalendar and WeeklyCalendar controls. You just match the SelectedDateBegin and SelectedDateEnd properties. The DailyCalendar doesn't include this feature, because you're working with a single date at a time.

To highlight dates in the other calendars when using this control, you need to perform a little calendar math. That's made easy with the AddDays() method, as shown in the example code. In short, you can match things up very easily.

You can use this series of controls as a simple calendar (I've added them to more than one application), but the tool's main emphasis is on enabling you to track things. The calendar controls offer a vast array of events, methods, and properties to perform this task. The two main collections are Appointments (to schedule something personally) and Resources (to interact with other people). Listing 2 shows one way to add a new appointment.

Listing 2: Adding an Appointment

private void dcTest_DoubleClick(object sender, System.EventArgs e)
{
   frmAppt  GetAppt = new frmAppt();  // Appointment entry form
   Appointment Appt = new Appointment();     // New appointment

   // Display the appointment entry form.
   if (GetAppt.ShowDialog(this) == DialogResult.OK)
   {
      // Get the information from the form and place it in the
      // new appointment.
      Appt.DateBegin = Convert.ToDateTime(
         GetAppt.txtDate.Text + " " + GetAppt.txtStartTime.Text);
      Appt.DateEnd = Convert.ToDateTime(
         GetAppt.txtDate.Text + " " + GetAppt.txtEndTime.Text);
      Appt.Text = GetAppt.txtText.Text;
      Appt.ToolTip = GetAppt.txtComment.Text;

      // Add the appointement to the daily calendar.
      dcTest.Appointments.Add(Appt);
   }
}



 
 
>>> More Add Ons Articles          >>> More By John Mueller
 



DevSource video
Devsource Video Series
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
DevLife Blog

Julia explores the Robotics Studio! (It's for more than you think.)

MSDev Blog

Messages for Bill Gates!

Make it Work
.NET makes runtime type checking a breeze. See what Peter has to say about it in this week's tips!
News
Microsoft Counts on App Support for Vista
Microsoft has taken pains to demonstrate that Windows Vista will have ample application support.
DevSource RSS FEEDS
XML Want an easy way to keep up with breaking tech news? And the Get DevSource headlines delivered to your desktop with RSS.