none
Stop Insert on Text Box RRS feed

  • Question

  • Hi all , I apologize for my English , it is possible that after a certain number of characters I can not insert characters into the text box?

    T.U.

    Monday, May 25, 2015 10:34 AM

Answers

  • Hello Carmenello,

    How many characters do you want to insert into a text box?  Following code is a sample for a text box.

    Controls.AddTextBox(10, 10)


    Nonki Takahashi

    Tuesday, May 26, 2015 12:18 AM
    Moderator

All replies

  • A sample to Input max 6 sigh is here MNL418.

    Best Regards Martin

    Monday, May 25, 2015 12:55 PM
  • Hello Carmenello,

    How many characters do you want to insert into a text box?  Following code is a sample for a text box.

    Controls.AddTextBox(10, 10)


    Nonki Takahashi

    Tuesday, May 26, 2015 12:18 AM
    Moderator
  • Here's a solution with LDControls.SetCursorPosition:

    ' -------  SNIP  ---------

    maxChars = 6       ' set max. characters in TB here
    tb = Controls.AddTextBox(10,10)

    Controls.TextTyped = OnTextTyped

    Sub OnTextTyped
      'LDControls.SetCursorToEnd(tb)     '' does NOT work as expected, (textbox.ScrollToEnd())
      LDControls.SetCursorPosition(tb, maxChars)
     
      tbTxt = Controls.GetTextBoxText(tb)
      len = Text.GetLength(tbTxt)
     
      If len > maxChars Then
        Controls.SetTextBoxText(tb, Text.GetSubText(tbTxt, 1,maxChars))
      EndIf
     
      'LDControls.SetCursorToEnd(tb)       ''  ...   same if on this position
    EndSub

    ' -------  SNAP  ----------

    PS: Also tried with LDControls.SetCursorToEnd, which did'nt work as expected !!

    Maybe LitDev can take a look at this:

    tb = Controls.AddTextBox(10,10)
    Controls.SetTextBoxText(tb, "Hallo SmallBasic")
    LDFocus.SetFocus(tb)

    Program.Delay(1000)
    LDControls.SetCursorPosition(tb, 5)
    GraphicsWindow.Title = "Cursor should be after Pos 5"

    Program.Delay(2000)
    LDControls.SetCursorToEnd(tb)   ' !!!
    GraphicsWindow.Title = "Cursor should be at TB EOL"   '' Should'nt it be at the EndOfLine or EndOfText ??


    Tuesday, May 26, 2015 7:43 PM
    Answerer
  • @Pappa,

    I also tried LDControls.SetCursorToEnd and if you check the source it uses textbox.ScrollToEnd(); which only seems to be useful for multi-line textboxes or ichtextboxes, so use SetCursorPosition as you did, a large value for position, e.g.1000 will always be at the end in a single line textbox.

    Tuesday, May 26, 2015 8:12 PM
    Moderator
  • Ja, i looked at the source and at TextBox Class, down to 'ScrollToEnd' method, which scrolls down the view, not the cursor as i thought.

    "Scrolls the view of the editing control to the end of the content. (Inherited from TextBoxBase.)"All's clear, Thanks and 'll update it in the xml to be unequivocally.

    Tuesday, May 26, 2015 9:35 PM
    Answerer