Visual Basic: RichTextBox Control

Visual Studio 6.0

SelPrint Method

See Also    Example    Applies To

Sends formatted text in a RichTextBox control to a device for printing.


object.SelPrint(hdc [,vStartDoc])

The SelPrint method syntax has these parts:

Part Description
object An object expression that evaluates to an object in the Applies To list.
hdc The device context of the device you plan to use to print the contents of the control.
vStartDoc Boolean. Specifies the behavior of the control regarding startdoc and enddoc printer control operations, as shown in settings.


The settings for vStartDoc are:

Constant Value Description
True -1 (Default) The control retains its original behavior and sends startdoc and enddoc commands to the printer.
False 0 The control doesn't send startdoc and enddoc commands, but sends only startpage and endpage commands to the printer.


If text is selected in the RichTextBox control, the SelPrint method sends only the selected text to the target device. If no text is selected, the entire contents of the RichTextBox are sent to the target device.

The SelPrint method does not print text from the RichTextBox control. Rather, it sends a copy of formatted text to a device which can print the text. For example, you can send the text to the Printer object using code as follows:


Notice that the hDC property of the Printer object is used to specify the device context argument of the SelPrint method.

Note   If you use the Printer object as the destination of the text from the RichTextBox control, you must first initialize the device context of the Printer object by printing something like a zero-length string.

The vStartDoc argument remedies situations when printers do not print with the default behavior. When the SelPrint method is invoked, both Visual Basic and the RichTextBox control send startdoc and enddoc commands to the printer resulting in a nested pair of startdoc/enddoc commands. Some printers respond only to the first pair of commands and thereby become disabled when the RichTextbox control sends the second pair. In that case, setting the vStartDoc argument to False prevents the second pair of commands from being sent.