.NET Framework and .NET 10
Adding SftDate/OCX To The Toolbox
Adding SftDate/OCX To A Project
Adding The SftHelperComponent To A Project
Preparing a Project
Special Considerations
- Renamed Members
- Dates and Null Values
- Indexed Properties
- Picture Properties
- Font Properties
- Color Properties
- Object vs. Interface
- Scaling
- Accessible Names
SftDate/OCX can be used in both classic .NET Framework and .NET 10 (or later) Windows Forms applications. In all cases the controls are added to a form using the wrapper classes Visual Studio generates, AxSftDateLib20.AxSftDate for the date field control and AxSftDateLib20.AxSftCalendar for the month calendar control, and the complete property, method and event API, including the property pages, is available. The C# and VB.NET samples are .NET Framework 4.8 applications.
One difference applies to .NET 10 projects: the SftHelperComponent and the OLECvt conversion class described below are provided for .NET Framework only. In .NET 10 applications, convert colors using ColorTranslator.ToOle, as the samples do, and define pictures using the methods and properties of the SftPictureObject, for example SetColorSample, LoadImage or BitmapHandle. An OLE font object for the font properties of the SftDateCalendar object can be obtained from a class derived from AxHost, using the protected static method AxHost.GetIFontDispFromFont.
See also Visual Studio 2026 Notes for designer behaviors specific to Visual Studio 2026.
The controls are automatically added to the Visual Studio Toolbox in the toolbox group "Softel vdm, Inc.", as SftDate/OCX 2.0 Date Field Control and SftDate/OCX 2.0 Month Calendar Control. If you ever need to add them to the toolbox by hand, use the simple procedure outlined in "Adding Controls To The Visual Studio Toolbox".
The SftDate/OCX controls can be added to a form by locating them in the toolbox group "Softel vdm, Inc.". A control can be added to a form by clicking on its button in the toolbox, then clicking on the form, or by dragging the button of the toolbox to the form.
When the first control is added, Visual Studio generates the assemblies AxInterop.SftDateLib20.dll (the wrapper classes AxSftDate and AxSftCalendar in the namespace AxSftDateLib20) and Interop.SftDateLib20.dll (the objects, interfaces and constants in the namespace SftDateLib20) and adds references to them to the project.
The SftHelperComponent is only needed by applications that assign .NET images using the NETImageObject property, or that use the OLECvt class described below to convert .NET images, fonts and colors to OLE types. Adding the component to a form also adds a reference to its assembly Softelvdm.OCXHelperV2.dll, which contains the OLECvt class. The samples don't use it.
The SftHelperComponent control can be added to a form by locating the control in the toolbox group "Softel vdm, Inc.". It can be added to a form by clicking on the SftHelperComponent button of the toolbox, then clicking on the form or by dragging the SftHelperComponent button of the toolbox to the form.
The component will not appear on the form, but will instead be shown as a component used by the form.
Add the following using statements to your source file(s) (Imports in VB.NET). This simplifies name resolution and makes the enumerated constants available. Softelvdm.OLEConvert is only needed for the OLECvt class.
using SftDateLib20; using AxSftDateLib20; using Softelvdm.OLEConvert;
All required steps have now been completed to use SftDate/OCX.
Add the following sample code to initialize a date field control named sftDate1 and a month calendar control named sftCalendar1:
private void Form1_Load(object sender, EventArgs e)
{
sftDate1.Format = SftDateFormatConstants.formatSftDateLongDate;
sftDate1.Value = DateTime.Today;
sftDate1.CtlAccessibleName = "Appointment date";
sftCalendar1.SelectionMode = SftDateSelectionModeConstants.selectionSftDateRange;
sftCalendar1.Calendar.MonthsAcross = 2;
sftCalendar1.Calendar.ShowWeekNumbers = true;
sftCalendar1.SetRange(DateTime.Today, DateTime.Today.AddDays(6));
sftCalendar1.CtlAccessibleName = "Travel dates";
}You can run the application: it shows a date field with today's date in the long date format and a month calendar showing two months with week numbers, with the seven days starting today selected.
Events are handled like the events of any other control, by adding a handler in the Events view of the Properties window. The following handler shows the range the user selects in the form's title:
private void sftCalendar1_RangeChanged(object sender, EventArgs e)
{
if (sftCalendar1.RangeStart is DateTime && sftCalendar1.RangeEnd is DateTime)
Text = ((DateTime)sftCalendar1.RangeStart).ToShortDateString() + " - " + ((DateTime)sftCalendar1.RangeEnd).ToShortDateString();
}In this example, the controls are initialized at run time using code. Of course it is also possible (and much easier) to set up all properties using the property pages. You can access the property pages by right-clicking on the control and selecting the Properties... entry of the popup menu.
Please note that you can right-click on a property in a Property Dialog or double-click on the description of a property to access its complete help information.
These controls have many properties and methods which you can use. This is a very simple example and doesn't even begin to exploit the capabilities of the controls. Please take a moment to familiarize yourself with the objects offered by SftDate/OCX. Also make sure to run the demo which is included with this product and take a look at the included samples.
When adding SftDate/OCX to a project, Visual Studio generates a wrapper class for each control, AxSftDate and AxSftCalendar, both derived from System.Windows.Forms.AxHost. The wrapper renames some members and converts some types. The C# and VB.NET syntax description of properties, methods and events shows the complete .NET syntax.
Properties and events whose names are already used by the Windows Forms Control class are renamed by the wrapper:
| Control | Windows Forms Wrapper |
|---|---|
| SftDate.AutoSize, SftCalendar.AutoSize | CtlAutoSize |
| SftDate.AccessibleName, SftCalendar.AccessibleName | CtlAccessibleName |
| SftDate.RightToLeft, SftCalendar.RightToLeft | CtlRightToLeft |
| SftDate.BackColor | CtlBackColor |
| SftDate.ForeColor | CtlForeColor |
| KeyDown, KeyPress and KeyUp events (SftDate, SftCalendar) | KeyDownEvent, KeyPressEvent and KeyUpEvent |
| MouseDown, MouseMove and MouseUp events (SftDate, SftCalendar) | MouseDownEvent, MouseMoveEvent and MouseUpEvent |
The event handlers receive the event's arguments as members of an object whose class is generated with the wrapper (see .NET Event Types), for example e.newValue and e.cancel in a ValueValidating event handler:
private void sftDate1_ValueValidating(object sender, _ISftDateEvents_ValueValidatingEvent e)
{
if (e.newValue is DateTime && ((DateTime)e.newValue).DayOfWeek == DayOfWeek.Sunday)
e.cancel = true;
}Date properties that always hold a date, such as MinDate and MaxDate of both controls, or FocusedDate and DisplayStart of the month calendar control, are DateTime values.
The properties that can hold no date, Value, RangeStart and RangeEnd of both controls and TodayDate of the SftDateCalendar object, are of type object. They return a DateTime, or DBNull.Value when there is no date. Setting DBNull.Value or null empties the value (see Values).
object value = sftDate1.Value; if (value is DateTime) MessageBox.Show(((DateTime)value).ToLongDateString()); else MessageBox.Show("No date"); sftDate1.AllowEmpty = true; sftDate1.Value = DBNull.Value;
The Item property of the SftDateSpecialDates collection is its default property, which C# uses as an indexer. The collection can also be enumerated using foreach.
SftDateSpecialDates dates = sftCalendar1.Calendar.SpecialDates; for (int i = 0; i < dates.Count; ++i) dates[i].Bold = true;
The pictures of special dates (SftDateSpecialDate.Picture) and of the days formatted in the DayFormatting event (SftDateDayFormatting.Picture) are SftPictureObject objects. A picture is defined using the methods and properties of this object, for example as a color sample (SetColorSample, as the DemoSample does), a GDI+ image loaded from a file (LoadImage), a bitmap or icon handle (BitmapHandle, IconHandle), a .NET image (NETImageObject) or an OLE Picture object (Picture).
SftDateSpecialDate day = sftCalendar1.Calendar.SpecialDates.Add(new DateTime(2026, 12, 25), SftDateRecurrenceConstants.recurrenceSftDateAnnually); day.ToolTip = "Christmas Day"; day.Picture.SetColorSample((uint)ColorTranslator.ToOle(Color.Firebrick), (uint)ColorTranslator.ToOle(Color.Firebrick));
The OLE Picture object type stdole.IPictureDisp cannot directly be used with an Image type. The Syntax portion of each method, property and event shows the full syntax and required picture type (Image or stdole.IPictureDisp). An Image is converted into a stdole.IPictureDisp using the provided class OLECvt (see Adding The SftHelperComponent To A Project above).
public static stdole.IPictureDisp ToIPictureDisp(Image i); public static Image ToImage(stdole.IPictureDisp pic);
ToIPictureDisp returns a stdole.IPictureDisp pointer given an Image object:
day.Picture.Picture = OLECvt.ToIPictureDisp(pictureBox1.Image);
In this example, pictureBox1 is a PictureBox control, part of the form, containing an image.
If you are using the same image many times, make sure to convert it once only and use the saved stdole.IPictureDisp. Converting the same image many times will create multiple OLE Picture objects, which can deplete virtual storage and available system resources.
The Syntax section of picture properties typically shows Get, Put and PutRef forms. If both Put and PutRef are available, PutRef is the preferred form as it conserves resources and assigns a picture object reference to the control. Put causes the control to completely copy the picture object.
The MouseIcon property of the controls is an Image in the wrapper class.
The Font property of the controls uses the .NET Font type. The fonts of the SftDateCalendar object (Font, TitleFont) and of the days formatted in the DayFormatting event (SftDateDayFormatting.Font) use the OLE font type stdole.IFontDisp instead, which cannot directly be used with a Font type. The Syntax portion of each method, property and event shows the full syntax and required font type (Font or stdole.IFontDisp).
A Font is converted into a stdole.IFontDisp using the provided class OLECvt (see Adding The SftHelperComponent To A Project above).
public static stdole.IFontDisp ToIFontDisp(Font f);
ToIFontDisp returns an stdole.IFontDisp pointer given a Font object:
sftDate1.Font = new Font("Segoe UI", 10); Font titleFont = new Font("Segoe UI", 12, FontStyle.Bold); sftCalendar1.Calendar.TitleFont = OLECvt.ToIFontDisp(titleFont);
If you are using the same font many times, make sure to convert it once only and use the saved stdole.IFontDisp. Converting the same font many times will create multiple OLE Font objects, which can deplete virtual storage and available system resources.
The Syntax section of font properties typically shows Get, Put and PutRef forms. If both Put and PutRef are available, PutRef is the preferred form as it conserves resources and assigns a font object reference to the control. Any change to the font object is reflected in the control also. Put on the other hand causes the control to completely copy the font object.
The colors of the date field control itself (BackColor, ForeColor, BorderColor, PlaceholderForeColor, SegmentHighlightBackColor and SegmentHighlightForeColor) use the .NET Color structure; BackColor and ForeColor are named CtlBackColor and CtlForeColor. All other colors, those of the SftDateCalendar object, of special dates (SftDateSpecialDate) and of the days formatted in the DayFormatting event (SftDateDayFormatting), use the native OLE color type UInt32 (uint). The Syntax portion of each property shows whether a Color structure or an OLE color value is used.
The samples convert a Color structure to an OLE color value using ColorTranslator.ToOle; the OLECvt class offers the same conversion:
public static uint ToOleColor(System.Drawing.Color clr); public static System.Drawing.Color ToColor(uint clr);
An OLE color value holds the red, green and blue components in its lower three bytes, from least to most significant byte (0x00bbggrr). A value with the high bit set (0x80000000 plus the index used with the Windows API GetSysColor) is a system color as defined in the Windows settings; ColorTranslator.ToOle returns such a value for the members of SystemColors.
sftDate1.CtlBackColor = Color.LightYellow; sftDate1.BorderColor = SystemColors.Highlight; sftDate1.Calendar.TitleBackColor = (uint)ColorTranslator.ToOle(Color.Teal); sftDate1.Calendar.TitleForeColor = (uint)ColorTranslator.ToOle(SystemColors.HighlightText); Color title = ColorTranslator.FromOle((int)sftDate1.Calendar.TitleBackColor);
Every color property defaults to colorSftDateDefault (-1), a color that follows the system colors, dark mode and high contrast (see Colors). The uint color properties are set back to the default using the converted constant, which the samples declare once:
private const uint DefaultColor = unchecked((uint)SftDateColorConstants.colorSftDateDefault);
The Color properties of the wrapper class cannot hold -1, so the default of a color of the control itself is set through the control's interface, which the wrapper's GetOcx method returns:
sftDate1.Calendar.TitleBackColor = DefaultColor; ISftDate ocx = (ISftDate)sftDate1.GetOcx(); ocx.BackColor = DefaultColor; ocx.SegmentHighlightBackColor = DefaultColor;
The controls are represented by objects of the wrapper classes AxSftDate and AxSftCalendar, but can also be represented by the interfaces they implement, ISftDate and ISftCalendar. The GetOcx method of the wrapper class returns the control, which is cast to its interface.
Most members are identical in both forms. The differences are the renamed members listed above and some types: for example, the BackColor property of the date field control is a Color named CtlBackColor in the wrapper class but an OLE color value (uint) named BackColor in the ISftDate interface, and the Font property is a System.Drawing.Font in the wrapper class but a stdole.IFontDisp in the interface. Such differences are shown in the Syntax section of the affected properties.
The Direct property returns the ISftDateVTable interface (ISftCalendarVTable for the month calendar control, Direct), which is identical to the ISftDate (ISftCalendar) interface and offers vtable binding to development tools that otherwise use dispatch interface binding.
Other classes, such as SftDateCalendar, SftDateSpecialDates, SftDateSpecialDate and SftDateDayFormatting, are equivalent to their respective interfaces ISftDateCalendar, ISftDateSpecialDates, ISftDateSpecialDate and ISftDateDayFormatting.
Windows Forms scales a form and its controls when the form is shown at another DPI than the one it was designed at, but ActiveX controls (AxHost) don't take part in this automatic scaling and keep their positions and widths. The samples override the form's ScaleControl method to scale the positions and widths of the ActiveX controls; their heights are left to the controls, which size themselves (CtlAutoSize) for their font and the DPI of their monitor (see Per-Monitor DPI).
protected override void ScaleControl(SizeF factor, BoundsSpecified specified)
{
base.ScaleControl(factor, specified);
foreach (Control c in Controls)
if (c is AxHost)
c.SetBounds((int)Math.Round(c.Left * factor.Width), (int)Math.Round(c.Top * factor.Height), (int)Math.Round(c.Width * factor.Width), c.Height);
}Screen readers announce a control by its accessible name. In a dialog resource, a static text control (a label) that comes right before the control names it, but a Windows Forms Label is not such a control, so each date field and month calendar control on a form needs an accessible name, defined using CtlAccessibleName (AccessibleName in the property pages). The samples define it at design time (see Accessibility).