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.
new to this hopefully the code is readable.
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.
thank you again for taking interest.
i have made progress on my issue and thought to share.
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_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)(Keys.Enter))
{
e.Handled = true;
// richTextBoxChat.Rtf = @"{\rtf1 \b Home: \bO}" + @richTextBoxHome;
// do not delete next 2 lines
//string test = @"{\rtf1 \b Home: \b0";
//test = test + richTextBoxHome.Rtf + "}";
string chatBuffer = richTextBoxChat.Rtf;
string buffer = @"{\rtf1";
buffer = buffer + chatBuffer;
buffer = buffer + @"\b Home:\b0";
buffer = buffer + richTextBoxHome.Rtf + "}";
// MessageBox.Show(buffer);
richTextBoxChat.Rtf = buffer;
//do not delete the following 2 lines
//richTextBoxChat.AppendText("Home:" + richTextBoxHome.Text);
richTextBoxHome.Clear();
}
}
}
}
just need to figure out how to get rid of the new lines/carriage returns in the text.
any tips most welcome.
thanks.
that did not workout so well. ended up using the below instead.
this.richTextBoxChat.SelectionFont = new Font(this.richTextBoxChat.Font.FontFamily, this.Font.Size, FontStyle.Bold);
richTextBoxChat.AppendText("Home: ");
this.richTextBoxChat.SelectionFont = new Font(this.richTextBoxChat.Font.FontFamily, this.Font.Size, FontStyle.Regular);
richTextBoxChat.AppendText(richTextBoxHome.Text);
richTextBoxChat.ScrollToCaret();
richTextBoxHome.Clear();
thanks for all the help.