Get selected HTML from ComponentOne RichTextBox? - c#

I have a C# Windows Phone 8 app with a ComponentOne RichTextBox contorl. How do I get the selected HTML that corresponds to the current value of a RichTextBox control's SelectedText property? (the current selection)
For example, suppose I have the current HTML in the RichTextbox:
<p>Some text</p><p><i>italicized text</i></p><p>Text not selected</p>
And the user selects "Some text" and "italicized text" by tapping. The SelectedText property will be "some text italicized text" and what I want to back as the selected HTML is:
<p>Some text</p><p><i>italicized text</i></p>
Is there a way to do this without doing some really messy operation walking the HTML while accumulating tags until the accumulated text matches the SelectedText property?

Related

Over come placeholder text with innerText

What I want to do is to fill it with text programatically.
webBrowser1.Document.GetElementById("textBox").InnerText = "foo";
This code works but some websites have a placeholder text. This code will not allow me to fill this as value but instead it as a placeholder text.
Strangely in some text box, it will be paste as value when there are a placeholder text. But some text box it wont.
Another scenario is that when it is innerText is placed as a placeholder text, all I have to do is click on that text box and write something next to it. This will act as a text box values.
Is there another way around this?
You need to set the value attribute of the <input id='textBox'> elment not the innertext.
webBrowser1.Document.GetElementById("textBox").SetAttribute("value", "text text text");

Bootstrap Wysiwyg Editor: Saved Data in HTML to Database, trying to send the HTML back to the editor in richtextbox format

So, I have the rich text box editor from Bootstrap-Wysiwyg.
If the textbox contains:
This is a bold statement.
Then my DB will save the text as:
(using a hidden tab where I insert the editor.html())
<b>This is a bold statement.<b>
If I save the file again, the RTF will convert it to:
<b>This is a bold statement.<b>
When I put the this text back into the editor using a Model.Value, it does not convert it to rich text but instead keeps the text as though it were a string and states it exactly as it is saved in the DB.
How can I convert the text in my model to show up in the rich text editors format?
I've been searching the net quite a bit, and most functionality refers to files. This is a new subject to me, so any insight is appreciated on how to fix this. (Editing text without formatting is obnoxious!) Thanks in advance!
Just in case someone else gets stuck, I was able to resolve this issue by doing the following:
I created a hidden div (which I populate first with my Model):
<textarea style="display: none;" id="editorCopy" name="body">#Model.Body</textarea>
and left my editor div empty:
<div id="editor" contenteditable="true">
</div>
and in my JQuery:
I set my editors text to my hidden divs value, and on submit, I replace the hidden div with my editor text:
$('#editor').html($('#editorCopy').val());
$('#postSubmit').click(function () {
$('#editorCopy').val($('#editor').html());
});
This allowed my rich text to show on edit. There might be a better solution, but at least this works! :]

text with quotes in html textbox

I have a text box on an html form that I set with a value from the server. But if the value contains an quotation mark, it breaks things. So I html encode it to produce the quote entity, but now this entity shows up in the text box on the page.

Multiple occurrence of regular expression in a multiline textbox

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.

Need to automatically Highlight the keywords in the text box using code behind c#

I m retrieving a text from SQL DB based on the Search criteria i give and displaying in the Textbox in asp.net. I need to highlight the words given in the search criteria in the displayed text.
For example : If i give "need" all the word "need" in textbox that is retrieved and displayed should be highlight in yellow color. Provide me some code snippets too.
An asp.net TextBox renders as either an html <input type="text"> or a <textarea> neither of which support formatting of the text inside.
If you were to display the text in a Label or LiteralControl it would be easy to just do a yourString.Replace(searchTerm, "<span style=\"color:yellow\">" + searchTerm + "</span>"); or something similar.

Categories

Resources