CanvasDrawText
int CanvasDrawText (int panelHandle, int controlID, char text[], char metaFont[], Rect bounds, int alignment);
Purpose
Draws a text string within a specified rectangular area on the canvas control. You can set the alignment of the string within the rectangle. If the string exceeds the size of the rectangle, CanvasDrawText clips the string.
CanvasDrawText draws the text using the current value of ATTR_PEN_COLOR.
CanvasDrawText draws the background rectangle using the current value of the following attributes:
ATTR_PEN_FILL_COLOR
ATTR_PEN_MODE
ATTR_PEN_PATTERN
If you do not want to draw the background of the rectangle, set the ATTR_PEN_FILL_COLOR attribute of the canvas control to VAL_TRANSPARENT.
Supported Controls
You can use CanvasDrawText with canvas controls.
Parameters
Input | ||||||||||||||||||||
Name | Type | Description | ||||||||||||||||||
panelHandle | int | Specifier for a particular panel that is currently in memory. You can obtain this handle from functions such as LoadPanel and NewPanel. | ||||||||||||||||||
controlID | int | The defined constant, located in the .uir header file, that you assigned to the control in the User Interface Editor, or the ID returned by functions such as NewCtrl and DuplicateCtrl. | ||||||||||||||||||
text | char [] | Text string to draw within the rectangle. | ||||||||||||||||||
metaFont | char [] | The font to use for the text string. metaFont can be a predefined NI metafont or a user-defined metafont saved by a previous call to functions such as CreateMetaFont and CreateMetaFontEx. The following are NI metafonts: Predefined metafonts—Contain typeface information, point size, and text styles such as bold, underline, italic, and strikeout. These metafonts are used in the LabWindows/CVI environment. The predefined metafonts are VAL_MENU_META_FONT, VAL_DIALOG_META_FONT, VAL_EDITOR_META_FONT, VAL_APP_META_FONT, and VAL_MESSAGE_BOX_META_FONT. LabWindows/CVI-supplied metafonts—Use typefaces that are not native to the operating system. These metafonts are installed while LabWindows/CVI is running. The LabWindows/CVI-supplied metafonts are VAL_7SEG_META_FONT and VAL_SYSTEM_META_FONT. |
||||||||||||||||||
bounds | Rect | Rect structure specifying the location and size of the background rectangle within which to draw the text. Specify values in the bounds parameter in terms of pixel coordinates, with the origin (0,0) at the upper left corner of the canvas control. The Rect structure is defined as follows: typedef struct { int top; int left; int height; int width; } Rect; You can create a Rect without having to declare a variable by using the following function: Rect MakeRect (int top, int left, int height, int width); If you want the size of the background rectangle to adjust automatically to the display size of the text string, set the height and width of the rectangle to VAL_KEEP_SAME_SIZE. ExampleCanvasDrawText (panelHandle, controlID, "sample text" VAL_APP_META_FONT, MakeRect(20,30,150,200), VAL_CENTER); |
||||||||||||||||||
alignment | int | Determines the placement of the text string within the background rectangle.
If the background rectangle you specify in bounds is smaller than the text display size, the function clips the text to the rectangle and ignores the alignment parameter. If the rectangle width is smaller than the text display width, the text starts from the left. If the rectangle height is smaller than the text display height, the text starts from the top. |
Return Value
Name | Type | Description |
status | int | Return value indicating whether the function was successful. A negative number indicates that an error occurred. |
Additional Information
Library: User Interface Library
Include file: userint.h
LabWindows/CVI compatibility: LabWindows/CVI 4.0 and later
Example
Refer to userint\canvas.cws for an example of using the CanvasDrawText function.