Hide

SftPrintPreview/OCX 1.0 - ActiveX Print Preview Control

Display
Print

Using SftPrintPreview/OCX with .NET

Adding SftPrintPreview/OCX to Visual Studio .NET
Adding SftPrintPreview/OCX To A Project
Special Considerations
- Indexed Properties
- Color Properties
- Object vs. Interface

Adding SftPrintPreview/OCX to Visual Studio .NET

The SftPrintPreview/OCX control must be added to the Toolbox before it can be used in a project. The Toolbox normally displays the standard Visual Studio .NET controls and any other controls that have been added previously.

Using the Tools, Choose Toolbox Items... (Visual Studio 2005 and above), Tools, Add/Remove Toolbox Items... (Visual Studio 2003) or Tools, Customize Toolbox... (Visual Studio 2002) menu command, the Customize Toolbox dialog is displayed.

Once this dialog is displayed, click on the COM Components tab:

Select the control "SftPrintPreview/OCX 1.0 Print Preview Control" by placing a check mark next to it and click OK. Make sure to select "SftPrintPreview/OCX 1.0 Print Preview Control" and not the control named "SftPrintPreview/OCX 1.0 Print Preview Control (IE)" as that control is specific to Internet Explorer and HTML pages.

This adds the control to the Toolbox.

  • for use with .NET (and other development tools)
If the icon appears with a small "e" in the top left corner as shown on the right, you have accidentally added the wrong control to the Toolbox. Remove the control, then add the correct control by following the above instructions.

If you don't see the control in the list or once you click OK an error message is displayed, the product SftPrintPreview/OCX is not correctly installed or the control may have been unregistered accidentally. Quit Visual Studio .NET and use the entry Maintenance, Register SftPrintPreview OCX in Windows Registry in the SftPrintPreview/OCX 1.0 program group to register the control. Restart Visual Studio .NET and try to add the control to the Toolbox again.

Adding SftPrintPreview/OCX To A Project

Once the control has been added to the Toolbox, it can be added to a form by clicking on the SftPrintPreview/OCX button of the Toolbox.

In order to be able to use font and picture properties, a small helper class must be added to each project that uses SftPrintPreview/OCX. This helper class OLECvt is used to convert OLE types to .NET types.

Use the Project, Add Existing Item... menu command and add the file OLEConvert.vb (VB) or OLEConvert.cs (C#) to your project. This file is located in the product directory \Program Files\Softelvdm\SftPrintPreview OCX 1.0\dotNET.

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 AxSftPrintPreviewLib10
Imports SftPrintPreviewLib10
Imports yourprojectname.OLEConvert ' substitute actual project name

C#

using SftPrintPreviewLib10;
using AxSftPrintPreviewLib10;
using OLEConvert;

All required steps have now been completed to use SftPrintPreview/OCX.

For a complete example, please consult the topics "SftTree/DLL and SftTree/OCX", and "RichEdit Control" or "Application-Generated Output".

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 in a Property Dialog 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 SftPrintPreview/OCX 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 SftPrintPreview/OCX to a project, Visual Studio .NET generates a class wrapper to fully support an ActiveX control such as SftPrintPreview/OCX. 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 VisitedPageInfo property, which requires a subscript (or page index), is used as follows:

AxSftPrintPreview1.get_VisitedPageInfo(pageNumber)

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

Color Properties

Color properties of the SftPrintPreview object use the .NET Color structure. 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.

Color Structure - VB

AxSftPrintPreview1.PaperColor = SystemColors.Highlight
AxSftPrintPreview1.ShadowColor = Color.Red
AxSftPrintPreview1.SelectedColor = ColorTranslator.FromWin32(&HFF) ' red

Dim c As Color
c = AxSftPrintPreview1.PaperColor

Color Structure - C#

AxSftPrintPreview1.PaperColor = SystemColors.Highlight;
AxSftPrintPreview1.ShadowColor = Color.Red;
AxSftPrintPreview1.SelectedColor = ColorTranslator.FromWin32(0x00000ff); // red
Color c = AxSftPrintPreview1.PaperColor;

Object vs. Interface

The main control is represented by an object of the SftPrintPreview class, but can also be represented by its ISftPrintPreview interface. The ISftPrintPreview 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 SftPrintPreview class is mostly equivalent to the ISftPrintPreview 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 HeaderFont property accepts a System.Drawing.Font when accessed through a SftPrintPreview class object, but uses a stdole.IFontDisp interface pointer when accessed directly though the ISftPrintPreview 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 SftPrintPreview class object. When accessed directly though the ISftPrintPreview interface pointer it is named Refresh.

Other classes, such as SftPrintPreviewPrinter, make no distinction between the class and interface. The class SftPrintPreviewPrinter is equivalent to its interface ISftPrintPreviewPrinter.


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