Hide

SftDirectory 3.5 - ActiveX File/Folder Control

Display
Print

Using SftDirectory with .NET

Adding SftDirectory To The Toolbox
Adding SftDirectory To A Project
Adding The SftHelperComponent To A Project
Preparing a Project
Special Considerations
- Indexed Properties
- Picture Properties
- Font Properties
- Color Properties
- Object vs. Interface

Adding SftDirectory To The Toolbox

The controls are automatically added to the Visual Studio Toolbox in the toolbox group "Softel vdm, Inc.", except for Visual Studio .NET 2002 and all Visual Studio Express Editions. For these, the controls have to be added "manually" using the simple procedure outlined in "Adding Controls To The Visual Studio Toolbox".

If you are using Visual Studio .NET 2002 or any of the Visual Studio Express Editions, please take a moment to add the controls using the simple procedure outlined in "Adding Controls To The Visual Studio Toolbox" before continuing.

Adding SftDirectory To A Project

The SftDirectory 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 SftDirectory button of the toolbox, then clicking on the form or by dragging the SftDirectory button of the toolbox to the form.

Adding SftDirectory To A Project

Adding The SftHelperComponent To A Project

In order to be able to use color and font properties, a small helper component must be added to each project that uses SftDirectory. This helper component assists in to converting OLE types to .NET types.

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.

Adding The SftHelperComponent To A Project

The component will not appear on the form, but will instead be shown as a component used by the form.

Preparing a Project

Add the following Imports and using statements to your project source file(s). This simplifies name resolution, makes most enumerated constants available and provides access to the OLECvt class.

VB

Imports AxSftDirectoryLib35
Imports SftDirectoryLib35
Imports Softelvdm.OLEConvert

C#

using SftDirectoryLib35;
using AxSftDirectoryLib35;
using Softelvdm.OLEConvert;

All required steps have now been completed to use SftDirectory.

For a complete example, add the following sample code to initialize the control:

VB

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    AxSftDirectory1.TopMostFolder = "C:\"
    AxSftDirectory1.Headers.Style = SftDirectoryHeadersStyleConstants.headersSftDirectoryButton
    AxSftDirectory1.get_ColumnEntry(0).HeaderText = "Folders"
End Sub

C#

private void Form1_Load(object sender, System.EventArgs e) {{
    axSftDirectory1.TopMostFolder = "C:\\";
    axSftDirectory1.Headers.Style = SftDirectoryHeadersStyleConstants.headersSftDirectoryButton;
    axSftDirectory1.get_ColumnEntry(0).HeaderText = "Folders";
}}

In this example, the control is 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 select the Properties... entry of the popup menu.

You can run the sample application and it displays a list of folders located on your C: drive.

After adding the control to the form, right click on the control and select the Properties... entry of the popup menu. This displays the Property Dialog for the control.

Please note that you can right-click on a property or double-click on the description of a property to access its complete help information.

This control has many properties and methods which you can use. This is a very simple example and doesn't even begin to exploit the capabilities of this control. Please take a moment to familiarize yourself with the objects offered by the SftDirectory control. Each object represents a specific area of the control and can be fully customized. Also make sure to run the demo which is included with this product and take a look at the included samples.

Special Considerations

When adding SftDirectory to a project, Visual Studio .NET generates a class wrapper to fully support an ActiveX control such as SftDirectory. Unfortunately, this class wrapper is slightly incomplete and generates initially unexpected function names for certain properties. However, these issues are easily resolved.

Indexed Properties

Indexed properties (i.e., properties which require additional parameters, such as an index) are converted into method calls with a get_ and set_ prefix.

For example, the ColumnEntry property, which requires a subscript (or index), is used as follows:

AxSftDirectory1.get_ColumnEntry(0).HeaderText = "Folders"

All other properties with additional parameters use a get_ and set_ prefix.

The Syntax portion of each method, property and event shows the full syntax, including any prefix (such as get_ and set_, etc.).

Picture Properties

While some graphics properties are generated to use an Image type, many properties and methods do not. These use the OLE picture type stdole.IPictureDisp instead, which 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).

The Image type can easily be converted into a stdole.IPictureDisp type using the provided class OLECvt. This class is added to each project using SftDirectory (see Adding The SftHelperComponent To A Project above).

VB

Public Shared Function ToIPictureDisp(ByVal i As Image) As stdole.IPictureDisp
Public Shared Function ToImage(ByVal pic As stdole.IPictureDisp) As Image

C#

public static stdole.IPictureDisp ToIPictureDisp(Image i);
public static Image ToImage(stdole.IPictureDisp pic);

ToIPictureDisp returns a stdole.IPictureDisp pointer given an Image object.

With this helper class in place, the Folder.Picture property (for example) can now be used as follows:

VB

AxSftDirectory1.CurrentFolder.Picture = OLECvt.ToIPictureDisp(PictureBox1.Image)

C#

axSftDirectory1.CurrentFolder.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 systems 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.

Font Properties

While some font properties are generated to use a Font type, many properties and methods do not. These 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).

The Font type can easily be converted into a stdole.IFontDisp type using the provided class OLECvt. This class is added to each project using SftDirectory (see Adding The SftHelperComponent To A Project above).

VB

Public Shared Function ToIFontDisp(ByVal f As Font) As stdole.IFontDisp

C#

public static stdole.IFontDisp ToIFontDisp(Font f);

ToIFontDisp returns an stdole.IFontDisp pointer given a Font object.

With this helper class in place, the SftDirectoryFolder.Font property (for example) can now be used as follows:

VB

Dim NewFont As New Font("Times New Roman", 16, FontStyle.Regular)
AxSftDirectory1.CurrentFolder.Font = OLECvt.ToIFontDisp(NewFont)

C#

Font NewFont = new Font("Times New Roman", 16, FontStyle.Regular);
axSftDirectory1.CurrentFolder.Font = OLECvt.ToIFontDisp(NewFont);

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 systems 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.

Color Properties

Color properties of the SftDirectory object use the .NET Color structure, but all other properties and objects (such as SftDirectoryFolder, etc.) use the native type UInt32 (uint). Converting a .NET Color structure color to a UInt32 (OLE color value) and vice versa is easily accomplished using the provided class OLECvt. This class is added to each project using Softelvdm.OLEConvert (see Adding The SftHelperComponent To A Project and Preparing a Project above).

VB

Public Shared Function ToOleColor(ByVal clr As System.Drawing.Color) As UInt32
Public Shared Function ToColor(ByVal clr As UInt32) As System.Drawing.Color

C#

public static uint ToOleColor(System.Drawing.Color clr);
public static System.Drawing.Color ToColor(uint clr);

The valid range for a color value is 0 to 16,777,215 (&HFFFFFF). The high order byte of a number in this range equals 0; the lower 3 bytes, from least to most significant byte, determine the amount of red, green, and blue, respectively. The red, green, and blue components are each represented by a number between 0 and 255 (&HFF). If the high byte is not 0, the system colors as defined in Control Panel's settings are used. The Windows API GetSysColor defines all valid constants. Please see your development environment's documentation for applicable color constants.

The Syntax portion of each method and property shows whether a Color structure or an OLE color value is used.

Color Structure - VB

AxSftDirectory1.BackColor = SystemColors.Highlight
AxSftDirectory1.BackColor = Color.Red
AxSftDirectory1.BackColor = OLECvt.ToColor(&HFF) ' red

Dim c As Color
c = AxSftDirectory1.BackColor

Color Structure - C#

axSftDirectory1.BackColor = SystemColors.Highlight;
axSftDirectory1.BackColor = Color.Red;
axSftDirectory1.BackColor = OLECvt.ToColor(0x00000ff); // red
Color c = axSftDirectory1.BackColor;

OLE Color Value - VB

AxSftDirectory1.CurrentFolder.BackColor = OLECvt.ToOleColor(SystemColors.Highlight)
AxSftDirectory1.CurrentFolder.BackColor = OLECvt.ToOleColor(Color.Red)
AxSftDirectory1.CurrentFolder.BackColor = &HFF ' red

Dim c As Color
c = OLECvt.ToColor(AxSftDirectory1.CurrentFolder.BackColor)

OLE Color Value - C#

axSftDirectory1.CurrentFolder.BackColor = OLECvt.ToOleColor(SystemColors.Highlight);
axSftDirectory1.CurrentFolder.BackColor = OLECvt.ToOleColor(Color.Red);
axSftDirectory1.CurrentFolder.BackColor = 0x00000ff; // red
Color c = OLECvt.ToColor(axSftDirectory1.CurrentFolder.BackColor);

Object vs. Interface

The main control is represented by an object of the SftDirectory class, but can also be represented by its ISftDirectory interface. The ISftDirectory" interface can be retrieved using the Direct property.

Certain methods and properties have different names and return types, based on how they are accessed. While (for example) an object based on the SftDirectory class is mostly equivalent to the ISftDirectory interface exposed by the control, .NET can introduce minor differences. Such differences are shown in the Syntax section of the affected methods and properties. All other classes are identical to their interfaces and no distinction is made.

The Syntax portion shows both forms, the class member and the interface method (the interface method is always marked with a Note indicator). If both forms are identical, only one entry is shown.

VB, C#

Some properties (particularly font and picture properties) may require different types. For example, the Font property accepts a System.Drawing.Font when accessed through a SftDirectory class object, but uses a stdole.IFontDisp interface pointer when accessed directly though the ISftDirectory interface pointer. stdole.IFontDisp can be provided using the OLECvt class.

Some properties or methods use different names, depending on how they are accessed. For example, the Refresh method is named CtlRefresh when accessed through a SftDirectory class object. When accessed directly though the ISftDirectory interface pointer it is named Refresh.

Other classes, such as SftDirectoryFolder and SftDirectoryHeaders, make no distinction between the class and interface. The classes SftDirectoryFolder and SftDirectoryHeaders are equivalent to their respective interfaces ISftDirectoryFolder and ISftDirectoryHeaders.


Last Updated 08/13/2020 - (email)
© 2024 Softel vdm, Inc.