TextBox Focus

Discussion in 'Questions (Windows Mobile)' started by cdeane, Oct 15, 2008.

  1. cdeane

    cdeane Member

    I did not backup my souce file and now it's lost.
    Now I am trying to rewrite it but when I get to the point of "TextBox.BingToFront" then try "TextBox2.Focus" I dont get focus.
    I get TextBox.2 to the front but I have to click in texbox feild to get focus.

    Code:
    Sub Globals
       
    'Declare the global variables here.
    Dim focused 'saves the focused textbox name
    End Sub

    Sub App_Start
       Form1.Show
    ImageButtonExit.BringToFront   
       flib.new1(
    "form1",B4PObject(1))
     flib.fullscreen(CPPC)
      
    End Sub

    Sub InitializeControls

     alTextBox.Add(
    "textbox1")
     alTextBox.Add(
    "textbox2")
     alTextBox.Add(
    "textbox3")

    For i = 1 To 11 'Adds the click event to all regular number buttons.
      AddEvent("Button" & i, Click, "Numbers_Click")
     
    Next
     
    For i = 0 To altextbox.Count -1'Adds the gotfocus event to all textboxes.
      AddEvent(altextbox.Item(i),GotFocus, "TextBoxes_GotFocus")
     
    Next
     focused = altextbox.Item(
    0)
     
    Control(focused).Focus
    End Sub

    Sub TextBoxes_GotFocus
     focused = 
    Sender.Name
    End Sub

    Sub Numbers_Click 'Handles 0-9 and '.'
     st = Control(focused).SelectionStart
     txt = 
    Control(focused).Text 
     
    If Sender.Text = "." Then 'checks for multiple periods.
      i = StrIndexOf(txt,".",0)
      
    If i = -1 Then Goto ok
      sl = 
    Control(focused).SelectionLength
      
    If sl > 0 Then
       
    If   StrIndexOf(SubString(txt,st,sl),".",0) > -1 Then Goto ok
      
    End If
      
    Control(focused).Focus
      
    Return
     
    End If
     ok:
     
    If Control(focused).SelectionLength > 0 Then
      
    Control(focused).Text = StrRemove(txt,st, Control(focused).SelectionLength)
     
    End If
     
    Control(focused).Text = StrInsert(Control(focused).Text,st,Sender.Text)
     
    Control(focused).SelectionLength = 0
     
    Control(focused).SelectionStart = st + 1
     
    Control(focused).Focus

    End Sub

    Sub ButtonBS_Click 'Backspace
     st = Control(focused).SelectionStart
     txt = 
    Control(focused).Text 
     
    If Control(focused).SelectionLength > 0 Then
      
    Control(focused).Text = StrRemove(txt,st, Control(focused).SelectionLength)
      
    Control(focused).SelectionStart = st
     
    Else If st > 0 Then
      
    Control(focused).Text = StrRemove(txt,st-1,1)
      
    Control(focused).SelectionStart = st - 1
     
    End If
     
    Control(focused).SelectionLength = 0
     
    Control(focused).Focus
    End Sub

    Sub ImageButtonExit_Click
    Form1.Close
    End Sub

    Sub ImageButtonExitNum_Click
    PanelSum.BringToFront
    ImageButtonExit.BringToFront
    PanelBGH.BringToFront
    PanelFGH.BringToFront
    TextBox1.Text=
    ""
    TextBox2.Text=
    ""
    TextBox3.Text=
    ""
    End Sub

    Sub ButtonPPH_Click
    PanelBGH.BringToFront
    PanelFGH.BringToFront
    ButtonEnterPPH.BringToFront
    TextBox1.BringToFront            
    'TextBoxes 1,2 and 3 are on form1
    TextBox1.Focus
    PanelNumPad.BringToFront
    ImageButtonExitNum.BringToFront
    InitializeControls
    End Sub

    Sub ButtonLayer_Click
    PanelBGH.BringToFront
    PanelFGH.BringToFront
    ButtonEnterLayer.BringToFront
     TextBox2.BringToFront 
      TextBox2.Focus
    PanelNumPad.BringToFront
    ImageButtonExitNum.BringToFront
    InitializeControls

    End Sub

    Sub ButtonDos_Click
    PanelBGH.BringToFront
    PanelFGH.BringToFront
    TextBox3.BringToFront
    TextBox3.Focus
    PanelBGF.BringToFront
    PanelFGF.BringToFront
    PanelNumPad.BringToFront
    ImageButtonExitNum.BringToFront
    InitializeControls

    End Sub




    Sub ButtonEnterPPH_Click
    ButtonPPH.Text=TextBox1.Text


    PanelSum.BringToFront
    ImageButtonExit.BringToFront
    PanelBGH.BringToFront
    PanelFGH.BringToFront
    TextBox1.Text=
    ""
    TextBox2.Text=
    ""
    TextBox3.Text=
    ""

    End Sub

    Sub ButtonEnterLayer_Click
    ButtonLayer.Text=TextBox2.Text

    PanelSum.BringToFront
    ImageButtonExit.BringToFront
    PanelBGH.BringToFront
    PanelFGH.BringToFront
    TextBox1.Text=
    ""
    TextBox2.Text=
    ""
    TextBox3.Text=
    ""

    End Sub
     
  2. agraham

    agraham Expert Licensed User

    You need to post the actual sbp file so that we get the form and controls with their layout otherwise we can't see what is going on. I for one can't be bothered to add a form and all those controls by guesswork!
     
  3. taximania

    taximania Well-Known Member Licensed User

    As AGraham states, the sbp file allows other people to 'see' your application 'for real'.

    I noticed your original post had a spelling typo (mistake) in it. Does your code ? I didn't look. :sign0013:

    Ok. So I've looked at it. The only part of your code that isn't text formatted.

    Is there a LF missing in your code. Was it written on the device ?

    EDIT: It doesn't show here :-(
     
    Last edited: Oct 15, 2008
  4. cdeane

    cdeane Member

    This should get you were I need to be.
     

    Attached Files:

  5. cdeane

    cdeane Member

    What do you mean LF mssing?
     
  6. Cableguy

    Cableguy Expert Licensed User

    There are image files missig!!!!!
    Anyway....Every time you bring a control to front, it gets focused, so you should only set the focus as the LAST "action" statement in the sub...
    ie:
    Code:
    Sub ButtonPPH_Click
    PanelBGH.BringToFront
    PanelFGH.BringToFront
    ButtonEnterPPH.BringToFront
    TextBox1.BringToFront            
    'TextBoxes 1,2 and 3 are on form1
    TextBox1.Focus
    PanelNumPad.BringToFront [COLOR=
    "Red"]THIS STEALS THE FOCUS[/COLOR]
    ImageButtonExitNum.BringToFront[COLOR=
    "Red"]THIS STEALS THE FOCUS[/COLOR]
    InitializeControls[COLOR=
    "Red"]THIS STEALS THE FOCUS[/COLOR]
    End Sub
     
    Last edited: Oct 15, 2008
  7. cdeane

    cdeane Member

    I see.
    That should have been self exclamatory.Duuu on my part

    Thanks for all of your support.
    I will remember that I need to attach the sdp when I post code.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice