【问题标题】:Using TAB to move between fields in Red language使用 TAB 在 Red 语言的字段之间移动
【发布时间】:2017-10-25 01:18:02
【问题描述】:

我有以下简单代码:

Red []
view [
    text "Value of x:"  f1: field "" return
    text "Value of y:"  f2: field "" return
    text "Read Sum:"    tt: text ""  return
    button "Calculate" [
        tt/text: to-string ((to-integer f1/text) + (to-integer f2/text)) ]
    button "Quit" [quit]  ]

如何添加代码以便可以使用 TAB 键在不同字段之间移动?显然,这在 Rebol (http://www.rebol.com/how-to/fields.html) 中有效,但在这里不起作用。

【问题讨论】:

    标签: user-interface textbox rebol red


    【解决方案1】:

    根据gitter archive

    handle-key: function [e prev-fld next-fld][
        k: e/key
        if k = tab [
            either e/shift? [win/selected: prev-fld][win/selected: next-fld]
        ]
    ]
    view [
        text "Value of x:"  f1: field "" on-key [handle-key event tt  f2] return
        text "Value of y:"  f2: field "" on-key [handle-key event f1  tt] return
        text "Read Sum:"    tt: text ""  on-key [handle-key event f2  f1] return
        button "Calculate" [
            tt/text: to-string ((to-integer f1/text) + (to-integer f2/text))      
        ]
        button "Quit" [quit]  
        do [win: self win/selected: f1]
    ]
    

    【讨论】:

    • View 现在可以为您处理textfield 内容的转换,因此您可以使用button "Calculate" [tt/data: f1/data + f2/data] 简化代码。
    • 您可以直接从handle-key 中的事件中获取窗口,以避免在整个代码中使用win:。在handle-key中添加win: e/window
    猜你喜欢
    • 1970-01-01
    • 2012-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多