Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C# RichTextBox strange behaviour

C# RichTextBox strange behaviour

Scheduled Pinned Locked Moved C#
csharpquestionwinformslinqgraphics
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    ikurtz
    wrote on last edited by
    #1

    greetings, for the first time ever im investigating RichTextBox control in C# windows forms. i know i need this control in my app as textBox is to simple for my needs. i have the followig code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace _19_richtextbox { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void richTextBoxHome_KeyDown(object sender, KeyEventArgs e) { if (e.KeyValue == (char)(Keys.Return)) { richTextBoxChat.AppendText("Home:" + richTextBoxHome.Text + "\n"); richTextBoxHome.Clear(); } } } } for the moment i just want whatever is typed in one richtextbox to be displayed on the other richtextbox on hitting return. the issue is everytime i hit return the data is being transfered to the other control but the first control is left with a carriage return before the cursor. this happens everytime i hit return. how do i make it stop doing this? both the controls accept multiline input. please advise if i need to provide more info. thank you for your time.

    OriginalGriffO 1 Reply Last reply
    0
    • I ikurtz

      greetings, for the first time ever im investigating RichTextBox control in C# windows forms. i know i need this control in my app as textBox is to simple for my needs. i have the followig code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace _19_richtextbox { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void richTextBoxHome_KeyDown(object sender, KeyEventArgs e) { if (e.KeyValue == (char)(Keys.Return)) { richTextBoxChat.AppendText("Home:" + richTextBoxHome.Text + "\n"); richTextBoxHome.Clear(); } } } } for the moment i just want whatever is typed in one richtextbox to be displayed on the other richtextbox on hitting return. the issue is everytime i hit return the data is being transfered to the other control but the first control is left with a carriage return before the cursor. this happens everytime i hit return. how do i make it stop doing this? both the controls accept multiline input. please advise if i need to provide more info. thank you for your time.

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      If you handle the return key and don't tell the OS you have done it, it passes it through to the default handler afterwards. Add "e.Handled = true;" to your code, all will be fine. [edit]I can't spell "the" correctly - fixed.[/edit]

      All those who believe in psycho kinesis, raise my hand.

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      I 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        If you handle the return key and don't tell the OS you have done it, it passes it through to the default handler afterwards. Add "e.Handled = true;" to your code, all will be fine. [edit]I can't spell "the" correctly - fixed.[/edit]

        All those who believe in psycho kinesis, raise my hand.

        I Offline
        I Offline
        ikurtz
        wrote on last edited by
        #3

        thank you for your response. it has solved my problem. may i introduce you to my new situation? i would like a way to make the "Home:" part in bold. i have found very little info on this on my searches. the following are the only actual code that i could understand. rtb1.Rtf = @"{\rtf1\ansi {\b hello} {\i World}}" ; richTextBox1.Rtf = @"{\rtf1\ansi This is in \b bold\b0.}"; ----------- im not sure how to proceed with this info. i just want the richtextbox to display "Home:" and "Away:" in bold and be able to handle URLs in text. please advise what should i specify when searching this potic on google or any reference your could think of would be of great help.

        OriginalGriffO 1 Reply Last reply
        0
        • I ikurtz

          thank you for your response. it has solved my problem. may i introduce you to my new situation? i would like a way to make the "Home:" part in bold. i have found very little info on this on my searches. the following are the only actual code that i could understand. rtb1.Rtf = @"{\rtf1\ansi {\b hello} {\i World}}" ; richTextBox1.Rtf = @"{\rtf1\ansi This is in \b bold\b0.}"; ----------- im not sure how to proceed with this info. i just want the richtextbox to display "Home:" and "Away:" in bold and be able to handle URLs in text. please advise what should i specify when searching this potic on google or any reference your could think of would be of great help.

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          You seem to have most of what you need there already, but have a look at this[^] - it's in VB, but it's pretty clear. Just think of rtf as an unreadable HTML file and you are just about there! :laugh:

          All those who believe in psycho kinesis, raise my hand.

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          I 1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            You seem to have most of what you need there already, but have a look at this[^] - it's in VB, but it's pretty clear. Just think of rtf as an unreadable HTML file and you are just about there! :laugh:

            All those who believe in psycho kinesis, raise my hand.

            I Offline
            I Offline
            ikurtz
            wrote on last edited by
            #5

            thank you!

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups