Textbox and carriage return question



  • The line feed character should still be in the string unless you are performing a trim or a string cleanup.  The following example is tested with the SL3 Textbox.  I don't recall whether SL2 had that problem.


        <TextBox x:Name="txt" Width="400" Height="400" AcceptsReturn="True" TextChanged="TextBox_TextChanged" />
        <TextBlock x:Name="result" Width="400" Height="400"   />


    private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        result.Text = (sender as TextBox).Text;
    6 สิงหาคม 2552 9:43
  • The only thing I do to clean up the data is the following code:

    Public Shared Function PrepString(ByVal InString As Object) As String
            Dim sStr As String = ""
            Dim i As Long

            If InString Is DBNull.Value Then
                PrepString = ""
                Exit Function
            End If

            If InStr(1, InString, "'") = 0 Then
                PrepString = InString
                Exit Function
            End If

            For i = 1 To Len(InString)
                If Mid(InString, i, 1) = "'" Then
                    sStr = sStr & "'"
                End If
                sStr = sStr & Mid(InString, i, 1)

            PrepString = Trim$(sStr)
        End Function

    So the Line feed should still be there.  If we type text into notepad and then paste it into the textbox it works.  But if we type direcly into the textbox and hit the enter key it does not include the line feed. 

    6 สิงหาคม 2552 9:45
  • You don't see the CrLf but it is there... Same with saving such a string to the database, if you look in the table you just see a simple string, but as soon as you fetch the string and put it into the textbox the formatting is back. I don't know how that works, but more important, it works...

    6 สิงหาคม 2552 11:14
  • That is the strange thing. When we look at the values coming back it only as a Chr(13).  That is the carriage return.  It does not includ ethe line feed.  Char(10) I beleive.

    6 สิงหาคม 2552 11:33
  • Did you set the TextMode property to MultiLine ?

    Edit: Nevermind... I was thinking for a second. But the only thing I do is setting TextWrap to Wrap and AceptsReturn to true. Works like a charm

    6 สิงหาคม 2552 11:37
  • I do nto see a TextMode property.  Here is how it is defined:

    <TextBox x:Name="txtPMMultiText" Text="" HorizontalAlignment="Stretch" AcceptsReturn="True" VerticalAlignment="Stretch" FontFamily="Arial"  TextWrapping="Wrap" FontSize="13" VerticalScrollBarVisibility="Auto"/>

    6 สิงหาคม 2552 11:49