1.11M Members

New Line in RichTextBox

 
0
 

I just created 5 Rich text boxes in runtime through a subroutine as:

        Dim c As Control
        c = New RichTextBox()
        With c
            .Name = "VersesRTB" & VerseCount
            .Location = New Point(70, y)
            .Height = 100
            .Width = 580
            .Font = New Font("Microsoft Sans Serif", 12)
        End With

It successfully created my required number of text boxes. I was enjoying until I found that during typing, when I press Enter Key, the cursor doesnot seem to go to next line, rather it continues in the same line. However wrapping occurs (ie) when I finish the like till the end, the cursor automatically goes to next line. But how can I go to next line in the middle? Do i want to fill the spaces till the end by pressing spacebar? It seemed weird.

Also, I cannot paste the clipborad contents on to those Rich text boxes just by pressing ctrl+v. I have to write this code to paste them on to it:

        CType(ActiveControl, RichTextBox).Paste()

I would be grateful if my problem is solved. Thanks!

 
0
 

Hi,

You can try this:

RichTextBox1.AppendText(Environment.NewLine)

 
0
 

Can you clarify

However wrapping occurs (ie) when I finish the like till the end

The code you show to create the RichTextBox is incomplete so it is hard to give an informed answer. There should be no way to access the created control(s) through the GUI because you haven't added the new control to the form. I assume this code exists elsewhere. If so then you should include it in your posting.

You should also declare c as the correct control type as in

Dim c As New RichTextBox
 
0
 

its not like its line..... as soon as he reached the end of the line then it wraps.....

However wrapping occurs (ie) when I finish the like till the end

 
0
 

Here's the code which I mean to say:

Dim c As New RichTextBox()
        With c
            .Name = a 'declared as public as soon as the class is declared
            .Location = New Point(70, 10)
            .Height = 100
            .Width = 580
            .Font = New Font("Microsoft Sans Serif", 12)
        End With
Me.Controls.Add(c)

Here, I have no problem in creating the RichTextBox with Height 100 and Width 580. I can type inside it. The problem is that the cursor doesnot move to next line when Enter Key is Pressed. Say:

This is a sample line1 (here I press Enter to go to next line)
This is sample line2 (here I press Enter to go to next line)
blah.. blah..(here I press Enter to go to next line)
blah..blah..(here I press Enter to go to next line)

But the result is that:

This is a sample line1 (here I press Enter to go to next line)This is sample line2 (here I press Enter to go to next line)blah.. blah..(here I press Enter to go to next line)blah..blah..(here I press Enter to go to next line)

Also I cannot use ctrl+v to paste the clipboard content on to it. For that as I said before, I created a button with name "Paste" and used the following code to paste the content from the clipboard.

CType(ActiveControl, RichTextBox).Paste()

Hope you understood my problem.

 
0
 

I tried your code (after adding the control to the form) and it worked just fine. Newline and paste worked as expected. What version of VB are you using?

 
0
 

Hello....Even I tried the code as it worked absolutely fine....both the newline and the paste part is working for me....
I tried it is Microsoft visual studio 2010 professional version

 
0
 

Its working for me.. but not in the application that am creating. When I tried to create only Rich Text Box in a new window application, It works. But I used same coding in the application am creating but it doesn't. I think there is some fault in it. :(

 
0
 

Oops..Extremely sorry.. It was my problem! I figured out it.

Yet I explain the reason for not working so it may be helpful to someone facing same problem..

Reason for not working Enter Key :
I had created a button named "OK" and kept as the form's AcceptButton property to true. This button is kept hidden once my richtextboxes are created. Since I will specify the number of boxes to create in textfield and press enter key to generate the specified number of RichTextBoxes. So when Enter key is alloted to it, it doesnot work with these boxes.

Reason for not working default windows shortcuts to cut, copy, paste :
I created cut, copy, paste menu items in menu bar and assigned the shortcut key for it, but didn't give any codes for those menu item. So default shortcuts are bypassed with the application's unused shortcuts.

Anyhow thanks for @poojavb and @Reverend Jim. Daniweb is the forum that helps me to correct my problem either through the experts or strikes the necessary points to the mind... :)

Question Answered as of 2 Years Ago by Reverend Jim, poojavb and Luc001
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: