Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Bug or am i not understanding something?

If e.KeyCode = Keys.Enter Then

SendChatMessage()

' RTBMessage.Text = ""

RTBMessage.Clear()

RTBMessage.Lines = RTBMessage.Text.Split(New Char() {ControlChars.Lf}, StringSplitOptions.RemoveEmptyEntries)

RTBMessage.Focus()

Im writing a program i thought i would use VB as microsoft were kind and gave me 2013 ultimate for free.

Only when a user clicks enter on the richtext box, it leaves a line at the top, hence i tried adding a bit to take the rogue line out but it didnt work

so i end up with a stuck blank line.

Any ideas what the code should be, is it a bug or me simply misunderstanding how the control works under vb?

Update:

@cougars and texans, its a richtextbox when the user clicks return its supposed to do its event and then clear the richtextbox - but whats happening is it does the event, deletes the text but for some reason then adds a blank line.

its almost like at the very end its adding the enter the user pressed. (even though its clearly told to not do that)

I also tried your code didnt make any difference.

Update 2:

For example this is the textbox

User sends "TEST"

so textbox looks like

TEST

Then it clears itself as its suppsed to

[] < represents a blank line

| < Cursor focus, now 1 line into the control where its not supposed to be, its as if the enter was added AFTER the code ran.

Update 3:

I have solved it,

Private Sub RTBMessage_KeyDown(sender As Object, e As KeyEventArgs) Handles RTBMessage.KeyDown

If e.KeyCode = Keys.Enter Then

SendChatMessage()

RTBMessage.Clear()

SendKeys.Send(vbBack) ' Get rid of enter key being added regardless of being told not to.

RTBMessage.Focus()

End If

End Sub

I still have no idea why im not seeing something, thanks for the reply guys,

2 Answers

Relevance
  • 6 years ago
    Favorite Answer

    Not a lot of details here, but it looks like your code is in an event handler.

    Instead of splitting on line feed alone, try splitting on Carriage Return Line Feed.

    ControlChars.CrLF

    Edit...

    I was able to get rid of it by changing the "Multiline" Property to "False", but this would probably break a copy and paste.

    But whatever works is fine.

  • 6 years ago

    ?

Still have questions? Get your answers by asking now.