Linebreak in TextBox

The place for threads about TimoSoft EditControls.
Post Reply
hermie
Cadet
Posts: 9
Joined: 11 Jun 2015, 15:35

Linebreak in TextBox

Post by hermie » 14 May 2019, 18:52

Hello!

In Microsoft Word, a line break is defined by Chrw(13).

In order to show a line break in your textbox control, it's however necessary to have Chrw(13) + Chrw(10).

Else, no linebreak will be displayed.

I imagined I should play around with "SoftLineBreak" in order to provoke / show a linebreak at Chrw(13) only, but that wouldn't help.

Can anybody tell me how I could make it so that Chrw(13) is shown as a line break?

I wouldn't want to alter the text (for example by replacing Chrw(13) with Chrw(13) + Chrw(10)), as I don't think this would be the correct way to handle this.

Thank you for the help!

User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: Unterföhring
Contact:

Re: Linebreak in TextBox

Post by TiKu » 17 May 2019, 19:40

Which version of Word do you use?
I can test only with Word 2010. I open Word, write "Line 1", press Enter, write "Line 2". Then I select all text, press Ctrl+C, go to a VB6 form with my Unicode TextBox on it (with the default properties, only Multiline set to True), set the focus to this text box and press Ctrl+V. It displays "Line 1" and "Line 2" on separate lines, just as expected.

Am I missing anything?

Best regards
TiKu
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!

hermie
Cadet
Posts: 9
Joined: 11 Jun 2015, 15:35

Re: Linebreak in TextBox

Post by hermie » 04 Sep 2019, 12:19

Yes, you're missing something. :-)

I'm using Word 2007.

I'm using the following code to get the text:

Code: Select all

Private Function GetText(ByVal uFile As String) As String

        Dim nWord As Object ' Word.Application
        Set nWord = CreateObject("Word.Application")
        
        'set some settings/properties
        With nWord
            .Visible = False
            .DisplayAlerts = 0   'wdAlertsNone
        End With
        
        'open the document
        Dim nDoc  As Object 'Word.document
        Set nDoc = nWord.Documents.Open(uFile)
        
        If nDoc Is Nothing Then
            Debug.Assert False
            'unable to get the document contents
            'handle this condition here...
        Else
            'read the contents from the Doc object
            GetText = nDoc.Content
        End If
        
        nDoc.Close
        Set nDoc = Nothing
        nWord.Quit False

        Set nWord = Nothing

End Function
If you get the text this way, the line break is represented by Chrw(13) only, not by vbCrLf.

hermie
Cadet
Posts: 9
Joined: 11 Jun 2015, 15:35

Re: Linebreak in TextBox

Post by hermie » 04 Sep 2019, 14:56

I thought that "InsertSoftLinebreaks" would achieve what I want, but obviously not.
I can replace Chrw(13) with vbNewLine of course, but I thought that you would perhaps handle this case.

User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: Unterföhring
Contact:

Re: Linebreak in TextBox

Post by TiKu » 04 Sep 2019, 20:27

Ok, I see. I cannot find a better solution other than parse the text and replace any vbCr. I could implement this in the control, but why? I would do the same as you currently already do in VB6. Unfortunately the Windows Edit control API does not seem to have any built-in feature that we could use here.
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!

hermie
Cadet
Posts: 9
Joined: 11 Jun 2015, 15:35

Re: Linebreak in TextBox

Post by hermie » 05 Sep 2019, 09:59

Thank you! Yes, I totally agree.
I have checked the .NET textbox control, and it behaves just like that as well.

User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: Unterföhring
Contact:

Re: Linebreak in TextBox

Post by TiKu » 11 Sep 2019, 20:46

Maybe I have found something. Starting with Windows 10 1809 it seems to be possible to configure the native edit control in a way that allows a single CR or a single LF for line breaks.
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!

Post Reply