About MultiLineTextBox

Palma Colapietro 136 Reputation points
2022-04-23T17:12:37.373+00:00

Hello

How do you insert lines into the MuliLineTextBox control ?

Thanks

Small BASIC
Small BASIC
A programming language created by Microsoft that serves a stepping stone for beginners from block-based coding languages to more complex text-based languages.
277 questions
0 comments No comments
{count} votes

6 answers

Sort by: Most helpful
  1. JR 126 Reputation points
    2022-04-23T17:25:17.397+00:00

    Code snippet:

    Box1=Controls.AddMultiLineTextBox(10,10)
    Controls.SetSize(Box1,600,400)
    Controls.SetTextBoxText(Box1,"How's this? Also, you can just type in what you want in the box.")

    JR

    0 comments No comments

  2. Palma Colapietro 136 Reputation points
    2022-04-23T20:25:45.797+00:00

    in the case of multiline how do I go to the next line ?

    BS

    0 comments No comments

  3. JR 126 Reputation points
    2022-04-24T14:48:42.68+00:00

    Code snippet:

    tb=Controls.AddMultiLineTextBox(20,0)
    Controls.SetSize(tb,500,400)
    Return=text.GetCharacter(10)
    Controls.SetTextBoxText(tb,"This and that"+return+return)
    LDFocus.SetFocus(tb)
    LDControls.SetCursorPosition(tb,100)

    If you are manually entering data in the multiline textbox just hit the return key. It will take you to the next line. If you are entering it through your program then you need to add the return as I did in the above snippet. This is more complex as you need to have the LitDev extension loaded.

    Here's a way to get to the next line without using an extension.

    tb=Controls.addmultilinetextbox(10,0)
    Controls.SetTextBoxText(tb,"This and That")
    Text=Controls.GetTextBoxText(tb)
    return=text.GetCharacter(10)
    Controls.SetTextBoxText(tb,text.Append(text,return+"Now This"))

    JR

    0 comments No comments

  4. Scout 541 Reputation points
    2022-04-24T15:59:03.047+00:00

    195846-multilinetextboxdemo.jpg

    GraphicsWindow.Title = "Single / Multi Line Text Box  Demo"  
    GraphicsWindow.BackgroundColor = "darkgray"  
    GraphicsWindow.FontSize = 20  
    GraphicsWindow.BrushColor = "Black"  
    txtBox = Controls.AddMultiLineTextBox(10, 10)  ' MultiLine text box'  
    'txtBox = Controls.AddTextBox(10, 10) ' 'SingleLine text box'  
    Controls.SetSize(txtBox,333,77)  
    txtboxshape = Shapes.AddText("-------")  
    Controls.Move(txtboxshape, 200,100)  
    txtcharshape = Shapes.AddText("-")  
    Controls.Move(txtcharshape, 150,200)  
    txtkeyshape = Shapes.AddText("---")  
    Controls.Move(txtkeyshape, 100,250)  
    txtboxreturn = Shapes.AddText("")  
    Controls.Move(txtboxreturn , 200,150)  
    hexBox = Controls.AddMultiLineTextBox(10, 300)     
    Controls.SetSize(hexBox,590,130)  
      
    Controls.TextTyped = OnTextTyped  ' subroutine to handle textbox events'  
    GraphicsWindow.TextInput = OnTextInput  
    GraphicsWindow.KeyUp = InKey  
      
    Sub OnTextTyped ' msb requires one routine to handle all textboxes'  
      If (Controls.LastTypedTextBox = txtBox) then ' action for text box '  
        buf = Controls.GetTextBoxText(txtBox)  
        Shapes.SetText(txtboxshape , buf)   
        GraphicsWindow.DrawText(10, 100, "Text boxed typed:")  
        buf2 = ""  
        For i = 1 to Text.GetLength(buf)  
         buf2 = Text.Append(buf2, Text.GetCharacterCode(Text.GetSubText(buf, i,1)) +" " )   
        EndFor  
        Controls.SetTextBoxText(hexBox , buf2)   
      EndIf  
    EndSub    
      
    Sub OnTextInput  ' Only at Start without Focus to TextBox'  
      GraphicsWindow.DrawText(10, 200, "Character: ")   
      Shapes.SetText(txtcharshape, GraphicsWindow.LastText)   
    EndSub  
      
    Sub InKey    
      key = GraphicsWindow.LastKey  
      GraphicsWindow.DrawText(10, 250, "Key: ")   
      Shapes.SetText(txtkeyshape, key)   
      if key = "Return" Then  
            GraphicsWindow.DrawText(10, 150, "Text boxed return: ")   
            Shapes.SetText(txtboxreturn, Controls.GetTextBoxText(txtbox))   
      EndIf  
    EndSub  
    

  5. Small Visual Basic 411 Reputation points
    2022-09-16T21:05:55.203+00:00

    If you use small Visual Basic, you can drag a textBox from the toolbox and drop it on the form, and use this line of code in the code editor:
    TextBox1.MultiLine = True
    you can use the move to previous and next lines by such code:

       TextBox1.MuliLine = True  
         
       '------------------------------------------------  
         
       Sub BtnNextLine_OnClick()  
          pos = TextBox1.CaretIndex  
          txt = TextBox1.Text  
          For i = pos To txt.Length  
             If txt[i] = Chars.Cr Then  
                If txt[i + 1] = Chars.Lf Then  
                   TextBox1.CaretIndex = i + 1  
                Else  
                   TextBox1.CaretIndex = i  
                EndIf  
                ExitLoop  
             EndIf  
          Next  
          TextBox1.Focus()  
       EndSub  
         
         
       '------------------------------------------------  
       Sub BtnPrevLine_OnClick()  
          pos = TextBox1.CaretIndex  
          txt = TextBox1.Text  
          For i = pos To 1 Step -1  
             If txt[i] = Chars.Lf Then  
                If txt[i - 1] = Chars.Cr Then  
                   TextBox1.CaretIndex = i - 1  
                Else  
                   TextBox1.CaretIndex = i  
                EndIf  
                ExitLoop  
             EndIf  
          Next  
          TextBox1.Focus()  
       EndSub  
    

    You can try this code in the TextBox Lines sample in the samples folders.

    0 comments No comments