DoEasy. 控件 (第 10 部分): WinForms 对象 动画界面·进阶篇
(2/3)·静态拖拽早已不够用,本篇给按钮类对象装上悬停与按压的视觉反馈与事件雏形
◍ 鼠标状态与事件的枚举拆分
在 MT5 自定义面板开发里,先把光标位置和按键动作拆成两套枚举,逻辑才不会乱。一套描述「形态状态」MOUSE_FORM_STATE,另一套描述「鼠标事件」ENUM_MOUSE_EVENT,二者都按「窗体外 / 表单内 / 头部活动区 / 滚动区」四个空间维度来列值。 从代码可见,MOUSE_FORM_STATE 里光是滚动区就区分了未按键、已按键、滚轮滚动三种子状态;ENUM_MOUSE_EVENT 则把「左键释放」单独列在活动区下(MOUSE_EVENT_INSIDE_ACTIVE_AREA_RELEASED),说明释放动作和按压动作在事件流里是分开捕获的。 末尾用宏 ENUM_MOUSE_EVENT_NEXT_CODE 把最后一个事件值 +1,作为图表事件码的接续起点。你在写 CChartObject 派生类时,若自定义事件码从 CHART_OBJ_EVENTS_NEXT_CODE 往后排,可直接引用这个宏,避免手填数字撞车。外汇与贵金属图表上的自定义控件交互存在滑点误触等高风险,建议先在模拟盘窗体里跑通枚举再上实盘。
enum ENUM_MOUSE_EVENT { MOUSE_EVENT_NO_EVENT = CHART_OBJ_EVENTS_NEXT_CODE, class=class="str">"cmt">// No event class=class="str">"cmt">//--- MOUSE_EVENT_OUTSIDE_FORM_NOT_PRESSED, class=class="str">"cmt">// The cursor is outside the form, the mouse buttons are not clicked MOUSE_EVENT_OUTSIDE_FORM_PRESSED, class=class="str">"cmt">// The cursor is outside the form, the mouse button(any) is clicked MOUSE_EVENT_OUTSIDE_FORM_WHEEL, class=class="str">"cmt">// The cursor is outside the form, the mouse wheel is being scrolled class=class="str">"cmt">//--- Within the form MOUSE_EVENT_INSIDE_FORM_NOT_PRESSED, class=class="str">"cmt">// The cursor is inside the form, no mouse buttons are clicked MOUSE_EVENT_INSIDE_FORM_PRESSED, class=class="str">"cmt">// The cursor is inside the form, the mouse button(any) is clicked MOUSE_EVENT_INSIDE_FORM_WHEEL, class=class="str">"cmt">// The cursor is inside the form, the mouse wheel is being scrolled class=class="str">"cmt">//--- Within the window header area MOUSE_EVENT_INSIDE_ACTIVE_AREA_NOT_PRESSED, class=class="str">"cmt">// The cursor is inside the active area, the mouse buttons are not clicked MOUSE_EVENT_INSIDE_ACTIVE_AREA_PRESSED, class=class="str">"cmt">// The cursor is inside the active area, any mouse button is clicked MOUSE_EVENT_INSIDE_ACTIVE_AREA_WHEEL, class=class="str">"cmt">// The cursor is inside the active area, the mouse wheel is being scrolled MOUSE_EVENT_INSIDE_ACTIVE_AREA_RELEASED, class=class="str">"cmt">// The cursor is inside the active area, left mouse button is released class=class="str">"cmt">//--- Within the window scrolling area MOUSE_EVENT_INSIDE_SCROLL_AREA_NOT_PRESSED, class=class="str">"cmt">// The cursor is within the window scrolling area, the mouse buttons are not clicked MOUSE_EVENT_INSIDE_SCROLL_AREA_PRESSED, class=class="str">"cmt">// The cursor is within the window scrolling area, the mouse button(any) is clicked MOUSE_EVENT_INSIDE_SCROLL_AREA_WHEEL, class=class="str">"cmt">// The cursor is within the window scrolling area, the mouse wheel is being scrolled }; class="macro">#define ENUM_MOUSE_EVENT_NEXT_CODE(MOUSE_EVENT_INSIDE_SCROLL_AREA_WHEEL+class="num">1) class=class="str">"cmt">// The code of the next event after the last chart event code
图形对象事件与画布控件状态色枚举
在 MT5 自定义控件库里,图形对象的交互要先靠一套事件枚举来分流。下面这段枚举把「无事件 / 创建 / 属性变更 / 重命名 / 删除 / 随图表销毁」六类对象级事件码排好,起点接在鼠标事件枚举的下一个可用码 ENUM_MOUSE_EVENT_NEXT_CODE 之后,保证不和系统内置事件撞车。 事件码之后用宏 GRAPH_OBJ_EVENTS_NEXT_CODE 把末位事件 +1 作为预留边界,后续若扩展拖拽、双击等对象事件,直接从这个数往下排即可,不必动已有逻辑。 画布控件(Canvas Element)的整数属性枚举里,除了元素 ID、类型、前景色、背景色这些静态项,还细分了六种「状态相关前景色」:鼠标按下、悬停、开启态及其对应的按下/悬停色。这意味着按钮类控件在 hover 或 click 时变色,是枚举层就定义好的,不用自己在 OnEvent 里硬写判断。 外汇与贵金属图表上挂这类自绘面板属于高风险操作环境,MT5 终端崩溃或图表被关闭会触发 GRAPH_OBJ_EVENT_DEL_CHART,若你的 EA 依赖控件状态做下单确认,必须在该事件里清掉内存引用,否则可能残留野指针。
class=class="str">"cmt">//| List of possible graphical object events | class=class="str">"cmt">//+------------------------------------------------------------------+ enum ENUM_GRAPH_OBJ_EVENT { GRAPH_OBJ_EVENT_NO_EVENT = ENUM_MOUSE_EVENT_NEXT_CODE,class=class="str">"cmt">// No event GRAPH_OBJ_EVENT_CREATE, class=class="str">"cmt">// "Creating a new graphical object" event GRAPH_OBJ_EVENT_CHANGE, class=class="str">"cmt">// "Changing graphical object properties" event GRAPH_OBJ_EVENT_RENAME, class=class="str">"cmt">// "Renaming graphical object" event GRAPH_OBJ_EVENT_DELETE, class=class="str">"cmt">// "Removing graphical object" event GRAPH_OBJ_EVENT_DEL_CHART, class=class="str">"cmt">// "Removing a graphical object together with the chart window" event }; class="macro">#define GRAPH_OBJ_EVENTS_NEXT_CODE(GRAPH_OBJ_EVENT_DEL_CHART+class="num">1) class=class="str">"cmt">// The code of the next event after the last graphical object event code class=class="str">"cmt">//+------------------------------------------------------------------+ class=class="str">"cmt">//+------------------------------------------------------------------+ class=class="str">"cmt">//| Integer properties of the graphical element on the canvas | class=class="str">"cmt">//+------------------------------------------------------------------+ enum ENUM_CANV_ELEMENT_PROP_INTEGER { CANV_ELEMENT_PROP_ID = class="num">0, class=class="str">"cmt">// Element ID CANV_ELEMENT_PROP_TYPE, class=class="str">"cmt">// Graphical element type class=class="str">"cmt">//---... class=class="str">"cmt">//---... CANV_ELEMENT_PROP_FORE_COLOR, class=class="str">"cmt">// Default text class="type">color for all control objects CANV_ELEMENT_PROP_FORE_COLOR_OPACITY, class=class="str">"cmt">// Default text class="type">color opacity for all control objects CANV_ELEMENT_PROP_FORE_COLOR_MOUSE_DOWN, class=class="str">"cmt">// Default control text class="type">color when clicking on the control CANV_ELEMENT_PROP_FORE_COLOR_MOUSE_OVER, class=class="str">"cmt">// Default control text class="type">color when hovering the mouse over the control CANV_ELEMENT_PROP_FORE_COLOR_TOGGLE, class=class="str">"cmt">// Text class="type">color of the control which is on CANV_ELEMENT_PROP_FORE_COLOR_TOGGLE_MOUSE_DOWN, class=class="str">"cmt">// Default control text class="type">color when clicking on the control which is on CANV_ELEMENT_PROP_FORE_COLOR_TOGGLE_MOUSE_OVER, class=class="str">"cmt">// Default control text class="type">color when hovering the mouse over the control which is on CANV_ELEMENT_PROP_BACKGROUND_COLOR, class=class="str">"cmt">// Control background class="type">color CANV_ELEMENT_PROP_BACKGROUND_COLOR_OPACITY, class=class="str">"cmt">// Opacity of control background class="type">color CANV_ELEMENT_PROP_BACKGROUND_COLOR_MOUSE_DOWN, class=class="str">"cmt">// Control background class="type">color when clicking on the control CANV_ELEMENT_PROP_BACKGROUND_COLOR_MOUSE_OVER, class=class="str">"cmt">// Control background class="type">color when hovering the mouse over the control
「开关态与复选控件的枚举属性细节」
在自定义画布控件库里,开关类按钮(toggle)和带复选框的控件靠一组独立枚举值区分视觉与状态。被高亮的几个属性专门管“开启态”的背景色与悬停、按下反馈:CANV_ELEMENT_PROP_BACKGROUND_COLOR_TOGGLE 管开启时底色,TOGGLE_MOUSE_DOWN 与 TOGGLE_MOUSE_OVER 分别管点击和悬停时的底色偏移。 CANV_ELEMENT_PROP_BUTTON_TOGGLE 标记按钮是否具备开关特性,BUTTON_STATE 则是运行期读取当前开合状态的入口;配合 CANV_ELEMENT_PROP_CHECK_STATE 与 AUTOCHECK,可以实现勾选框被点选后自动翻转状态,不用在 EA 里手写事件分支。 整数属性总量由宏写死:CANV_ELEMENT_PROP_INTEGER_TOTAL 为 81,SKIP 为 0,说明全部 81 个整型属性都参与排序索引。排序枚举 ENUM_SORT_CANV_ELEMENT_MODE 里,SORT_BY_CANV_ELEMENT_ID = 0 打头,SORT_BY_CANV_ELEMENT_FORE_COLOR_MOUSE_DOWN 则允许按“点击时文字色”给控件阵列重排。 开 MT5 把这段枚举贴进自定义面板基类,改一下 TOGGLE 相关底色,就能直观看到开启态按钮在悬停时的色差变化,比纯逻辑调试更快定位绘制层 bug。外汇与贵金属图表上挂这类面板需注意,高频重绘可能拖慢 tick 响应,属于高风险定制组件。
CANV_ELEMENT_PROP_BACKGROUND_COLOR_TOGGLE, class=class="str">"cmt">// Background class="type">color of the control which is on CANV_ELEMENT_PROP_BACKGROUND_COLOR_TOGGLE_MOUSE_DOWN,class=class="str">"cmt">// Control background class="type">color when clicking on the control which is on CANV_ELEMENT_PROP_BACKGROUND_COLOR_TOGGLE_MOUSE_OVER,class=class="str">"cmt">// Control background class="type">color hovering the mouse over control which is on CANV_ELEMENT_PROP_BOLD_TYPE, class=class="str">"cmt">// Font width type CANV_ELEMENT_PROP_BORDER_STYLE, class=class="str">"cmt">// Control frame style class=class="str">"cmt">//---... class=class="str">"cmt">//---... CANV_ELEMENT_PROP_CHECK_STATE, class=class="str">"cmt">// Status of a control having a checkbox CANV_ELEMENT_PROP_AUTOCHECK, class=class="str">"cmt">// Auto change flag status when it is selected CANV_ELEMENT_PROP_BUTTON_TOGGLE, class=class="str">"cmt">// Toggle flag of the control featuring a button CANV_ELEMENT_PROP_BUTTON_STATE, class=class="str">"cmt">// Status of the Toggle control featuring a button CANV_ELEMENT_PROP_CHECK_BACKGROUND_COLOR, class=class="str">"cmt">// Color of control checkbox background CANV_ELEMENT_PROP_CHECK_BACKGROUND_COLOR_OPACITY, class=class="str">"cmt">// Opacity of the control checkbox background class="type">color class=class="str">"cmt">//---... class=class="str">"cmt">//---... CANV_ELEMENT_PROP_CHECK_FLAG_COLOR_MOUSE_DOWN, class=class="str">"cmt">// Color of control checkbox when clicking on the control CANV_ELEMENT_PROP_CHECK_FLAG_COLOR_MOUSE_OVER, class=class="str">"cmt">// Color of control checkbox when hovering the mouse over the control }; class="macro">#define CANV_ELEMENT_PROP_INTEGER_TOTAL(class="num">81) class=class="str">"cmt">// Total number of integer properties class="macro">#define CANV_ELEMENT_PROP_INTEGER_SKIP(class="num">0) class=class="str">"cmt">// Number of integer properties not used in sorting class=class="str">"cmt">//+------------------------------------------------------------------+ class=class="str">"cmt">//+------------------------------------------------------------------+ class=class="str">"cmt">//| Possible sorting criteria of graphical elements on the canvas | class=class="str">"cmt">//+------------------------------------------------------------------+ class="macro">#define FIRST_CANV_ELEMENT_DBL_PROP(CANV_ELEMENT_PROP_INTEGER_TOTAL-CANV_ELEMENT_PROP_INTEGER_SKIP) class="macro">#define FIRST_CANV_ELEMENT_STR_PROP(CANV_ELEMENT_PROP_INTEGER_TOTAL-CANV_ELEMENT_PROP_INTEGER_SKIP+CANV_ELEMENT_PROP_DOUBLE_TOTAL-CANV_ELEMENT_PROP_DOUBLE_SKIP) enum ENUM_SORT_CANV_ELEMENT_MODE { class=class="str">"cmt">//--- Sort by integer properties SORT_BY_CANV_ELEMENT_ID = class="num">0, class=class="str">"cmt">// Sort by element ID SORT_BY_CANV_ELEMENT_TYPE, class=class="str">"cmt">// Sort by graphical element type class=class="str">"cmt">//---... class=class="str">"cmt">//---... SORT_BY_CANV_ELEMENT_FORE_COLOR, class=class="str">"cmt">// Sort by class="kw">default text class="type">color for all control objects SORT_BY_CANV_ELEMENT_FORE_COLOR_OPACITY, class=class="str">"cmt">// Sort by class="kw">default text class="type">color opacity for all control objects SORT_BY_CANV_ELEMENT_FORE_COLOR_MOUSE_DOWN, class=class="str">"cmt">// Sort by control text class="type">color when clicking on the control
◍ Canvas控件排序枚举里的颜色与状态维度
在MT5自定义图形界面库里,控件集合的排序并非只能按坐标或ID,而是暴露了一组极细的枚举值,让你可以依据画布元素在交互过程中的视觉属性做排序。上面这段枚举节选里,前景色、背景色、边框样式、字体宽度都被拆成了独立常量。 被高亮的几个枚举专门描述『开关态(Toggle)』与鼠标行为叠加时的颜色:例如 SORT_BY_CANV_ELEMENT_FORE_COLOR_TOGGLE_MOUSE_OVER 表示当控件处于开启状态且鼠标悬停时,按默认文字色排序;SORT_BY_CANV_ELEMENT_BACKGROUND_COLOR_TOGGLE_MOUSE_DOWN 则是开启态下按下鼠标时按背景色排序。这类细分在制作多按钮面板时,能直接按视觉反馈状态归类控件。 字符串类属性排在枚举尾部,以 FIRST_CANV_ELEMENT_STR_PROP 为基准偏移:SORT_BY_CANV_ELEMENT_NAME_OBJ 按元素对象名排,SORT_BY_CANV_ELEMENT_TEXT 按图形元素所显示文本排。若你在EA里动态生成了几十个Canvas按钮,用 SORT_BY_CANV_ELEMENT_TEXT 配合 CArrayObj 的排序方法,可以在调试时快速按标签找对象。 实际验证方式:打开MT5的 MetaEditor,在 Standard Library 的 Canvas 相关头文件里全局搜索 SORT_BY_CANV_ELEMENT_FORE_COLOR_TOGGLE,确认枚举定义顺序与上面一致,再写一段测试代码对10个以上按钮按开启态前景色排序,观察返回的控件指针数组顺序变化。外汇与贵金属图表上挂此类面板属于高风险操作环境,排序逻辑错误只影响界面不影响报价,但误触交易按钮可能引发行情波动下的错单。
SORT_BY_CANV_ELEMENT_FORE_COLOR_MOUSE_OVER, class=class="str">"cmt">// Sort by control text class="type">color when hovering the mouse over the control SORT_BY_CANV_ELEMENT_FORE_COLOR_TOGGLE, class=class="str">"cmt">// Sort by control text class="type">color when the control is on SORT_BY_CANV_ELEMENT_FORE_COLOR_TOGGLE_MOUSE_DOWN, class=class="str">"cmt">// Sort by the class="kw">default control text class="type">color when clicking on the control class="kw">while it is on SORT_BY_CANV_ELEMENT_FORE_COLOR_TOGGLE_MOUSE_OVER, class=class="str">"cmt">// Sort by the class="kw">default control text class="type">color when hovering the mouse over the control class="kw">while it is on SORT_BY_CANV_ELEMENT_BACKGROUND_COLOR, class=class="str">"cmt">// Sort by control background text class="type">color SORT_BY_CANV_ELEMENT_BACKGROUND_COLOR_OPACITY, class=class="str">"cmt">// Sort by control background class="type">color opacity SORT_BY_CANV_ELEMENT_BACKGROUND_COLOR_MOUSE_DOWN, class=class="str">"cmt">// Sort by control background text class="type">color when clicking on the control SORT_BY_CANV_ELEMENT_BACKGROUND_COLOR_MOUSE_OVER, class=class="str">"cmt">// Sort by control background text class="type">color when hovering the mouse over the control SORT_BY_CANV_ELEMENT_BACKGROUND_COLOR_TOGGLE, class=class="str">"cmt">// Sort by control background class="type">color when the control is on SORT_BY_CANV_ELEMENT_BACKGROUND_COLOR_TOGGLE_MOUSE_DOWN,class=class="str">"cmt">// Sort by control background class="type">color when clicking on the control class="kw">while it is on SORT_BY_CANV_ELEMENT_BACKGROUND_COLOR_TOGGLE_MOUSE_OVER,class=class="str">"cmt">// Sort by control background class="type">color when hovering the mouse over the control class="kw">while it is on SORT_BY_CANV_ELEMENT_BOLD_TYPE, class=class="str">"cmt">// Sort by font width type SORT_BY_CANV_ELEMENT_BORDER_STYLE, class=class="str">"cmt">// Sort by control frame style SORT_BY_CANV_ELEMENT_CHECK_STATE, class=class="str">"cmt">// Sort by status of a control having a checkbox SORT_BY_CANV_ELEMENT_AUTOCHECK, class=class="str">"cmt">// Sort by auto change flag status when it is selected SORT_BY_CANV_ELEMENT_BUTTON_TOGGLE, class=class="str">"cmt">// Sort by the Toggle flag of the control featuring a button SORT_BY_CANV_ELEMENT_BUTTON_STATE, class=class="str">"cmt">// Sort by the status of the Toggle control featuring a button SORT_BY_CANV_ELEMENT_CHECK_BACKGROUND_COLOR, class=class="str">"cmt">// Sort by class="type">color of control checkbox background SORT_BY_CANV_ELEMENT_CHECK_BACKGROUND_COLOR_OPACITY, class=class="str">"cmt">// Sort by opacity of control checkbox background class="type">color SORT_BY_CANV_ELEMENT_CHECK_FLAG_COLOR_MOUSE_DOWN, class=class="str">"cmt">// Sort by class="type">color of control checkbox when clicking on the control SORT_BY_CANV_ELEMENT_CHECK_FLAG_COLOR_MOUSE_OVER, class=class="str">"cmt">// Sort by class="type">color of control checkbox when hovering the mouse over the control SORT_BY_CANV_ELEMENT_NAME_OBJ = FIRST_CANV_ELEMENT_STR_PROP,class=class="str">"cmt">// Sort by an element object name SORT_BY_CANV_ELEMENT_NAME_RES, class=class="str">"cmt">// Sort by the graphical resource name SORT_BY_CANV_ELEMENT_TEXT, class=class="str">"cmt">// Sort by graphical element text }; MSG_CANV_ELEMENT_PROP_FORE_COLOR, class=class="str">"cmt">// Default text class="type">color for all control objects
Canvas 控件的状态色与勾选属性枚举
在 MT5 的 Canvas 图形库里,控件元素的大量外观属性通过 MSG_CANV_ELEMENT_PROP_* 枚举常量来定义,其中文本与背景的前景色、透明度都区分了常态、按下(MOUSE_DOWN)、悬停(MOUSE_OVER)三种鼠标交互状态。 对于带开关(toggle)状态的控件,还额外定义了 FORE_COLOR_TOGGLE / BACKGROUND_COLOR_TOGGLE 及其对应的 MOUSE_DOWN、MOUSE_OVER 分支,这意味着一个按钮在“开”和“关”两种状态下可以完全独立配色,而不需要在代码里手动切换画刷。 勾选框(checkbox)相关属性单独成组:从 MSG_CANV_ELEMENT_PROP_CHECK_BACKGROUND_COLOR 到 CHECK_FORE_COLOR_MOUSE_OVER,覆盖了背景色、前景框线色以及各自的透明度与交互态颜色,共 10 个枚举项。 如果你在做自定义面板,直接引用这些枚举给 CCanvas 的控件对象赋值即可,不必自己维护状态映射表;外汇与贵金属图表上的自定义控件同样受平台渲染限制,高频重绘可能拖慢 tick 响应,属于高风险环境下的性能权衡。
MSG_CANV_ELEMENT_PROP_FORE_COLOR_OPACITY, class=class="str">"cmt">// Default text class="type">color opacity for all control objects MSG_CANV_ELEMENT_PROP_FORE_COLOR_MOUSE_DOWN, class=class="str">"cmt">// Default control text class="type">color when clicking on the control MSG_CANV_ELEMENT_PROP_FORE_COLOR_MOUSE_OVER, class=class="str">"cmt">// Default control text class="type">color when hovering the mouse over the control MSG_CANV_ELEMENT_PROP_FORE_COLOR_TOGGLE, class=class="str">"cmt">// Text class="type">color of the control which is on MSG_CANV_ELEMENT_PROP_FORE_COLOR_TOGGLE_MOUSE_DOWN, class=class="str">"cmt">// Default control text class="type">color when clicking on the control which is on MSG_CANV_ELEMENT_PROP_FORE_COLOR_TOGGLE_MOUSE_OVER, class=class="str">"cmt">// Default control text class="type">color when hovering the mouse over the control which is on MSG_CANV_ELEMENT_PROP_BACKGROUND_COLOR, class=class="str">"cmt">// Control background class="type">color MSG_CANV_ELEMENT_PROP_BACKGROUND_COLOR_OPACITY, class=class="str">"cmt">// Opacity of control background class="type">color MSG_CANV_ELEMENT_PROP_BACKGROUND_COLOR_MOUSE_DOWN, class=class="str">"cmt">// Control background class="type">color when clicking on the control MSG_CANV_ELEMENT_PROP_BACKGROUND_COLOR_MOUSE_OVER, class=class="str">"cmt">// Control background class="type">color when hovering the mouse over the control MSG_CANV_ELEMENT_PROP_BACKGROUND_COLOR_TOGGLE, class=class="str">"cmt">// Background class="type">color of the control which is on MSG_CANV_ELEMENT_PROP_BACKGROUND_COLOR_TOGGLE_MOUSE_DOWN, class=class="str">"cmt">// Control background class="type">color when clicking on the control which is on MSG_CANV_ELEMENT_PROP_BACKGROUND_COLOR_TOGGLE_MOUSE_OVER, class=class="str">"cmt">// Control background class="type">color when hovering the mouse over control which is on MSG_CANV_ELEMENT_PROP_BOLD_TYPE, class=class="str">"cmt">// Font width type MSG_CANV_ELEMENT_PROP_BORDER_STYLE, class=class="str">"cmt">// Control frame style MSG_CANV_ELEMENT_PROP_CHECK_STATE, class=class="str">"cmt">// Status of a control having a checkbox MSG_CANV_ELEMENT_PROP_AUTOCHECK, class=class="str">"cmt">// Auto change flag status when it is selected MSG_CANV_ELEMENT_PROP_BUTTON_TOGGLE, class=class="str">"cmt">// Toggle flag of the control featuring a button MSG_CANV_ELEMENT_PROP_BUTTON_STATE, class=class="str">"cmt">// Status of the Toggle control featuring a button MSG_CANV_ELEMENT_PROP_CHECK_BACKGROUND_COLOR, class=class="str">"cmt">// Color of control checkbox background MSG_CANV_ELEMENT_PROP_CHECK_BACKGROUND_COLOR_OPACITY, class=class="str">"cmt">// Opacity of the control checkbox background class="type">color MSG_CANV_ELEMENT_PROP_CHECK_BACKGROUND_COLOR_MOUSE_DOWN, class=class="str">"cmt">// Color of control checkbox background when clicking on the control MSG_CANV_ELEMENT_PROP_CHECK_BACKGROUND_COLOR_MOUSE_OVER, class=class="str">"cmt">// Color of control checkbox background when hovering the mouse over the control MSG_CANV_ELEMENT_PROP_CHECK_FORE_COLOR, class=class="str">"cmt">// Color of control checkbox frame MSG_CANV_ELEMENT_PROP_CHECK_FORE_COLOR_OPACITY, class=class="str">"cmt">// Opacity of the control checkbox frame class="type">color MSG_CANV_ELEMENT_PROP_CHECK_FORE_COLOR_MOUSE_DOWN, class=class="str">"cmt">// Color of control checkbox frame when clicking on the control MSG_CANV_ELEMENT_PROP_CHECK_FORE_COLOR_MOUSE_OVER class=class="str">"cmt">// Color of control checkbox frame when hovering the mouse over the control
「控件状态与配色属性的枚举映射」
在 MT5 的 Canvas 界面库里,图形控件把「勾选框颜色」「文本色」「背景色」都拆成了带状态后缀的枚举常量。比如 MSG_CANV_ELEMENT_PROP_CHECK_FLAG_COLOR 管勾选框基础色,而 MSG_CANV_ELEMENT_PROP_CHECK_FLAG_COLOR_MOUSE_DOWN 专门管鼠标按下时的勾选框颜色,这种拆分让悬停、点击、启用三态可以独立换色。 下面这段枚举定义直接给出了俄英双语文案,对应控件在「On 状态」「鼠标悬停」「鼠标按下」下的文本与背景色。你在 MQl5 里 include 了 Canvas 头文件后,搜 MSG_CANV_ELEMENT_PROP_CHECK_FLAG_COLOR 就能看到完整列表,目前原文节选里仅勾选框相关就列了 4 个独立常量。 实际做面板时,若不给 _MOUSE_OVER 和 _MOUSE_DOWN 单独赋值,控件视觉反馈会退化成单一色,盯盘时容易点空。打开 MT5 的 MetaEditor,定位到 Canvas 枚举区,把背景色三态都填上,是验证这套属性是否生效的最快办法。
MSG_CANV_ELEMENT_PROP_CHECK_FLAG_COLOR, class=class="str">"cmt">// Color of control checkbox MSG_CANV_ELEMENT_PROP_CHECK_FLAG_COLOR_OPACITY, class=class="str">"cmt">// Opacity of the control checkbox class="type">color MSG_CANV_ELEMENT_PROP_CHECK_FLAG_COLOR_MOUSE_DOWN, class=class="str">"cmt">// Color of control checkbox when clicking on the control MSG_CANV_ELEMENT_PROP_CHECK_FLAG_COLOR_MOUSE_OVER, class=class="str">"cmt">// Color of control checkbox when hovering the mouse over the control class=class="str">"cmt">//--- Real properties of graphical elements class=class="str">"cmt">//--- String properties of graphical elements MSG_CANV_ELEMENT_PROP_NAME_OBJ, class=class="str">"cmt">// Graphical element object name MSG_CANV_ELEMENT_PROP_NAME_RES, class=class="str">"cmt">// Graphical resource name MSG_CANV_ELEMENT_PROP_TEXT, class=class="str">"cmt">// Graphical element text {"Цвет текста по умолчанию для всех объектов элемента управления","Default text class="type">color for all objects in the control"}, {"Непрозрачность цвета текста по умолчанию для всех объектов элемента управления","Default text class="type">color opacity for all objects in the control"}, {"Цвет текста элемента по умолчанию при нажатии мышки на элемент управления","The class="kw">default text class="type">color of an element when the mouse is pressed on the control"}, {"Цвет текста элемента по умолчанию при наведении мышки на элемент управления","The class="kw">default text class="type">color of an element when hovering over the control"}, {"Цвет текста элемента управления в состоянии \"включено\"","The text class="type">color of a control in the enabled state"}, {"Цвет текста элемента управления по умолчанию в состоянии \"включено\" при нажатии мышки на элемент управления","The class="kw">default text class="type">color of the control in the \"On\" state when the mouse is pressed on the control"}, {"Цвет текста элемента управления по умолчанию в состоянии \"включено\" при наведении мышки на элемент управления","The class="kw">default text class="type">color of a control in the \"On\" state when hovering the mouse over the control"}, {"Цвет фона элемента управления","Background class="type">color of the control"}, {"Непрозрачность цвета фона элемента управления","Opacity of the control&class="macro">#x27;s background class="type">color"}, {"Цвет фона элемента управления при нажатии мышки на элемент управления","Background class="type">color of the control when the mouse is clicked on the control"}, {"Цвет фона элемента управления при наведении мышки на элемент управления","Background class="type">color of the control when hovering the mouse over the control"}, {"Цвет фона элемента управления в состоянии \"включено\"","Background class="type">color of the control in the enabled state"}, {"Цвет фона элемента управления в состоянии \"включено\" при нажатии мышки на элемент управления","The background class="type">color of the control in the \"On\" state when the mouse is pressed on the control"}, {"Цвет фона элемента управления в состоянии \"включено\" при наведении мышки на элемент управления","The background class="type">color of a control in the \"On\" state when the mouse is over the control"}, {"Тип толщины шрифта","Font weight type"}, {"Стиль рамки элемента управления","Control&class="macro">#x27;s border style"}, {"Состояние элемента управления, имеющего флажок проверки","The state of a control that has a checkbox"}, {"Автоматическое изменение состояния флажка при его выборе","Automatically change the state of the checkbox when it is selected"}, {"Флаг \"Переключатель\" элемента управления, имеющего кнопку","\"Button-toggle\" flag of a control"}, {"Состояние элемента управления \"Переключатель\", имеющего кнопку","The \"Toggle-button\" control state"}