- Object types and features of specifying their coordinates
- Time and price bound objects
- Objects bound to screen coordinates
- Creating objects
- Deleting objects
- Finding objects
- Overview of object property access functions
- Main object properties
- Price and time coordinates
- Anchor window corner and screen coordinates
- Defining anchor point on the object
- Managing the object state
- Priority of objects (Z-Order)
- Object display settings: color, style, and frame
- Font settings
- Rotating text at an arbitrary angle
- Determining object width and height
- Visibility of objects in the context of timeframes
- Assigning a character code to a label
- Ray properties for objects with straight lines
- Managing object pressed state
- Adjusting images in bitmap objects
- Cropping (outputting part) of an image
- Input field properties: alignment and read-only
- Standard deviation channel width
- Setting levels in level objects
- Additional properties of Gann, Fibonacci, and Elliot objects
- Chart object
- Moving objects
- Getting time or price at the specified line points
Font settings
All types of objects enable the setting of certain texts for them (OBJPROP_TEXT). Many of them display the specified text directly on the chart, for the rest it becomes an informative part of the tooltip.
When text is displayed inside an object (for types OBJ_TEXT, OBJ_LABEL, OBJ_BUTTON, and OBJ_EDIT), you can choose a font name and size. For objects of other types, the font settings are not applied: their descriptions are always displayed in the chart's standard font.
Identifier |
Description |
Type |
---|---|---|
OBJPROP_FONTSIZE |
Font size in pixels |
int |
OBJPROP_FONT |
Font |
string |
You cannot set the font size in printing points here.
The test script ObjectFont.mq5 creates objects with text and changes the name and font size. Let's use the ObjectBuilder class from the previous script.
At the beginning of OnStart, the script calculates the middle of the window both in screen coordinates and in the time/price axes. This is required because objects of different types participating in the test use different coordinate systems.
void OnStart()
|
The list of tested object types is specified in the types array. For some of them, in particular OBJ_HLINE and OBJ_VLINE, the font settings will have no effect, although the text of the descriptions will appear on the screen (to ensure this, we turn on the CHART_SHOW_OBJECT_DESCR mode).
ChartSetInteger(0, CHART_SHOW_OBJECT_DESCR, true);
|
The t variable will be used to sequentially switch from one type to another.
The fonts array contains the most popular standard Windows fonts.
string fonts[] =
|
We will iterate over them using the f variable.
Inside the demo loop, we instruct ObjectBuilder to create an object of the current type types[t] in the middle of the window (for unification, the coordinates are specified in both coordinate systems, so as not to make differences in the code depending on the type: coordinates not supported by the object simply will not have an effect).
while(!IsStopped())
|
Next, we set up the text and font (the size is chosen randomly).
const int size = rand() * 15 / 32767 + 8;
|
For the next pass, we move the cursors in the arrays of object types and font names.
t = ++t % ArraySize(types);
|
Finally, we update the chart, wait 1 second, and delete the object to create another one.
ChartRedraw();
|
The image below shows the moment the script is running.
Button with custom font settings