Maybe some of you can help me with the following problem. I want some words bolded in a textbox(winforms).
I have a string _descripton variable containing some description text. For example:
“ this is a description of a \b car \b0………… ”. Im trying to replace the string format with richtextformat like:
string _makebold = _description.Replace("\b", #"{\rtf1\ansi \b").Replace("\b0", " \b0.}");
to get the following result: this is a description of a #"{\rtf1\ansi \b car\b0.}"……….
And finally setting the text property of the richtextbox1:
richTextBox1.Text = _makebold;
I cant get that specific word bolded in a richTextbox and textbox doenst work either.
can anyone help me with a solution?
Thanks!
You can use Rtf property of the rich text box control.
For example, the following text adds the text "This text is in bold." to an existing RichTextBox control.
See this MSDN link.
richTextBox1.Rtf = #"{\rtf1\ansi This is in \b bold\b0.}";
Related
I have a string builder where value is appending at runtime via placeholder. Once string builder has appended, it is assigned to a text box (not rich txt) to show up in UI.
I want part of the text to be bold.
sb.AppendFormat("Added {0} by {1}:\n{2}", DateTime.ToString(), userName, note);
txt.Text = sb.ToString();
Expected output:
Added 9/01/2016 8:47:19 PM by Vinoth: Testing Purpose
How can I achieve this? Is there anyway of looping over words with the : symbol until I want it to be bold?
You will have to build up the text in sections.
Either as different TextBoxes/TextBlocks or as a single RichTextBox with separate Runs for the sections you want in a different style.
There is a richTextBox that has string. I want to select a few characters on the richTexBox by mouse and save them in a variable. I use this method:
richTextBox1.SelectedRtf;
It shows me selected characters but is has some additional string and i don't want them. How can I remove them?
This is additional string:
{\rtf1\fbidis\ansi\ansicpg1256\deff0\deflang1065\uc1 }
try
richTextBox1.SelectedText
Here is the msdn link for more information
http://msdn.microsoft.com/en-us/library/system.windows.forms.richtextbox.selectedtext(v=vs.110).aspx
Selection.Text property will return the selected text of Rich Edit Text box.
richTextBox1.Selection.Text
RichTextBox.SelectedText? may be?
http://msdn.microsoft.com/en-us/library/system.windows.forms.richtextbox.selectedtext(v=vs.110).aspx
use this
richTextBox1.SelectedText (property)
I am developing a windows application using c#. I am loading a file (html, txt, xhtml) to the text box. I want to test the occurrence of following cases in my text box.
,(comma) with closeup text (ex. text1,text2)
.(dot) with closeup text (ex. text1.text2)
:(colon) with closeup text (ex. text1:text2)
,(comma) with closeup ' i.e (left single quotation mark)
"(doublequote) with closeup text
'(single quote) with closeup text
</i> with closeup text (ex. </i>text)
</span> with closeup text.
For all the occurrences of the above condition I want to highlight the particular found text in the textbox. I am trying to use the regular expression. I am inserting all the cases in the array list and checking one by one. For the first case if the text in the textbox is like hjhdf, dfsjf then it will show the message box, if any text before and after this particular text then it will not show the messagebox.
string regexerror = wordToFind;
Regex myregex = new Regex("^[,]*[a-zA-Z]*$");
bool isexist = myregex.IsMatch(rtbFileDisplay.Text);
if (isexist)
{
MessageBox.Show("Hi");
}
At the moment you're only matching the beginning of the entire text with ^. You need to get it to match the beginning of a line instead.
Look at this link: http://msdn.microsoft.com/en-us/library/yd1hzczs.aspx. This explains use of the MultiLine property:
myregex.MultLine=true;
This should do the job.
I have a textbox multiline for insert text in my db.
This text is viewed in a div, but without newlines.
How can I view the newline in my text?
thanks
Put your text inside <div><pre>... text ...</pre></div>. pre tag preserves line breaks.
Use the following:
myText = myText.Replace(Environment.NewLine, "<br />");
to replace newline characters with proper HTML line-breaks.
Best wishes,
Fabian
I am trying to figure out a simple way of making a text box equal all letters to the left of a "-" in another text box. Basically, if an end-user types blah-test in textbox1, I would like textbox2 to equal blah. I have tried if statements and substrings based off of letter position count (i.e. substring(0, 5); however, this got very lengthy and impractical, since the words entered into textbox1 can be any length.
Thank you,
DFM
Try this:
if(textbox2.text.Contains("-"))
{
textbox1.text = textbox2.text.Split("-")[0];
}
Here we first check if textbox2 contains the - character and if it does we split the text in two parts and set the text of textbox1 to the part that is left of the first - character.
it's very simple
select and double click on the OnTextChange event on textbox1
Write this code inside textbox1_OnTextChange:
string text = textbox1.Text;
textbox2.text = text.Substring(0, text.indexOf("-"));
and you're done!