GetFontName - MetaTrader 5 Library | Forex Indicators Download - MT4/MT5 Resources


When using text graphics in an indicator, it is often necessary to implement the possibility to change its font type in the indicator input parameters.
In this case, the most obvious solution is to manually enter the font name as a line in the input parameter, but this is not very convenient and error-prone. A more efficient approach is to use custom variables based on enumerations and dropdown lists. The proposed functional module is designed to solve this task.
An example is enough to be able to be used with this library. Suppose we have an indicator that displays a text label in the corner of the chart (ChartInfo_Old.mq5). The following are its input parameters:
//+------------------------------------------------------------------------+ //|Indicator input parameters | //+------------------------------------------------------------------------+ input string text = "real" ; // text label content Input color text color = red; // text label color Input integer font size = 24 ; // font size Input type_font FontType=Font7; // Font type Input ENUM_BASE_CORNER what corner = corner lower left corner ; // position corner Input unit Y_= 1 ; // vertical position
Using such a code, the indicator input parameters window will have the following appearance:

In order for indicator users to not have to enter the font name manually, we should make some changes to the code:
1. With the help of the #include directive, add the contents of the GetFontName.mqh file before the declaration of the indicator input parameters:
//+------------------------------------------------------------------------+ // type_font enumeration description | // CFontName class description | //+------------------------------------------------------------------------+ #include
2. Replace the FontType input parameter line:
Input string font type = "Express New" ; // font type
with line
Input type_font FontType=Font7; // Font type
Therefore, we slightly changed the meaning of variable usage. The meaning of the previous variable must be implemented in the new string variable to be declared at global level
string s font type;Then the variable in the font type indicator code must be replaced with s font type . This operation must be done in one place only:
Set T label ( 0 , "information_label" , 0 , what corner, ENUM_ANCHOR_POINT ( 2 * what corner), 5 , Y_, text, text color, sFontType, font size);
Now, the font type variable must be blocked in OnInit() . This can be done with just a few lines of code:
CFontName FONT; sFontType=FONT.GetFontName(FontType);
The modified ChartInfo.mq5 indicator can then be compiled.
Now you can see the changes in the indicator input parameters window:

It became more convenient to use fonts in indicator input parameters.
Attachment download
📎 getfontname.mqh (5.12 KB)
📎 chartinfo_old.mq5 (6.01 KB)
📎 chartinfo.mq5 (6.32 KB)
Source: MQL5 #644
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •