Maintain Focus with two textbox and button using Brightscript

拟墨画扇 提交于 2019-12-11 08:48:32

问题


I created a one Login Form in the bright script. It's following

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

TextBox 1 ' Here the focus is active I set by default in TextBox field active = true

TextBox 2 ' Here the press down key to active true

Button 1 ' Here again press down key to focus true

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Here, I maintain the 3 Items using 3 different key. Now I want to maintain the single key for all 3 items using the down key. Anyone idea to How to maintain Focus using Brightscript.

I used the one function for key handling It's here

function onKeyEvent(key as String, press as Boolean) as Boolean

.................

end function

Now, I maintained the key like I set TextBox Focus active in ByDefault to XML File.Now I apply Logic to below. First item focus set on XML file by default.

if key = "down" then 
       'Here Second item focus
       m.keypass.active = true ' Here work successfully First time
       if key = "down" and m.keypass.active = true and m.btnsub.active = false then
          'Here not maintain successfully its directly call here I press the down key.       
           m.keypass.active = false    
           m.btnsub.active = true 'Here third item focus is not maintained 

       end if
end if

I first-time press the down key It's working fine But its second time How handling the Focus. I used the same thing in Up key.

Here I am using "and" then the issue will happen is there any idea.

Pls, Check Here's an image really what I want to do.

Edited Post:

I handle with up and down key with below code. It's working But, Its only work in a single time.

 if key = "up" or key = "down"  
        if key = "down" 

          ?"here down key"

            if m.keypass.id = "instructpass" and m.keypass.active = true
                  ? "down key if part"
                  m.btngrp.setFocus(true)
                  m.keypass.active = false         
                  handled = true
            else if m.keyid.id = "instructid" and m.keyid.active = true 
                ?" down key else part"     
                m.keypass.active = true
                m.keyid.active = false
                handled = true
            else if m.btngrp.buttonSelected = 0
                m.keyid.active = true
                m.btngrp.setFocus(false)
                handled = true              
            end if 

            handled = true

       else if key = "up" 

         ? "here up key"

           if  m.keypass.active = true
                  ?"up key if part"
                  m.keyid.active = true
                  m.keypass.active = false
                  handled = true
           else if  m.keyid.active = true
                  ?"id key"
                  m.btngrp.setFocus(true)
                  m.btngrp.focusButton = 1
                  m.keyid.active = false        
                  handled = true

           else if m.btngrp.focusButton = 0 and m.btngrp.buttonSelected = 0
                ?"up key else part"
                m.keypass.active = true
                m.keypass.setFocus(true)     
                m.btngrp.setFocus(false)
                handled = true

            end if

                handled = true
        end if
        handled = true
end if   

Thank you.


回答1:


Check here.

You should use .setFocus(true) and .hasFocus(), which are available to most renderable nodes such as TextEditBox and Button.

E.g.

if key = "down" then 
    if textBox1.hasFocus() then 
        textBox2.setFocus(true)
    elseif textBox2.hasFocus() then 
        button.setFocus(true)
    end if
end if

if key = "up" then 
    if button.hasFocus() then 
        textBox2.setFocus(true)
    elseif textBox2.hasFocus() then 
        textBox1.setFocus(true)
    end if
end if


来源:https://stackoverflow.com/questions/56967997/maintain-focus-with-two-textbox-and-button-using-brightscript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!