TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Guest User
Tech Writer
48
12k
RichTextBox Find and SelectionFont not working.
Jun 27 2019 10:09 AM
Using: Windows 10, C# on Visual Studio 2017, WinForms.
I am attempting to format each line of a RichTextBox seperately, but have had some issues. Here is my current code method to create a "bold" a line:
// Adds a single line to the top of the RichTextBox every time a button is pressed.
messageCounter++;
DateTime dt = DateTime.Now;
string
time = dt.ToString(
"hh:mm tt"
);
string
message =
"A BOLD message."
;
string
statusText =
"Message #"
+ messageCounter +
"\t"
+ time +
"\t\t"
+ message +
"\n"
;
StatusRichTextBox.Text = StatusRichTextBox.Text.Insert(0, statusText);
StatusRichTextBox.Find(statusText);
StatusRichTextBox.SelectionFont =
new
System.Drawing.Font(StatusRichTextBox.Font, System.Drawing.FontStyle.Bold);
// The following part is for viewing the found string length and will be removed later.
string
howBig = StatusRichTextBox.SelectionLength.ToString();
StatusRichTextBox.Text = StatusRichTextBox.Text.Insert(0, howBig);
My problem is that the Find will find the message variable, but not the time one or the statusText. And even when it finds the message variable, it won't make it bold, however I was able to make it bold in the past, but I forgot what I changed to do it.
If anyone could help me figure out why find isn't working for the two strings, that would be great. In addition, any hints on how to get the bold to work or even how to change the color of the selected text would be most appreciated.
Thank you.
Reply
Answers (
1
)
Jquery Datatable In Winform
GridView with checkboxes coloumns