Wednesday, September 18, 2013

How to replace all occurrences of a string with a specified string from rich text box in c#?

Respected Madam, being more succinct, just look at this screenshot illustrating the objective i want to achieve:



The code i am working with is as follows:


When user clicks on "Change All", this code runs to achieve the objective:



private void button5_Click(object sender, EventArgs e)
{

String selectedWord = this.suggest_list.SelectedItem.ToString();
String word123 = this.NIDict_list.SelectedItem.ToString();
String abc = Regex.Replace(this.TextContent, word123, selectedWord);
this.FirstForm = new spellChecker_frm(abc);
// i am throwing the result to the first form into //TextSpelling form. I just want that //as i am still working in TextSpelling Form so what should be done to reflect the result in rich text //box without closing up the TextSpelling form.


//the rich text box which is behind


//TextSpelling form. I just want that //as i am still working in TextSpelling Form so what should be done to reflect the result in rich text //box without closing up the TextSpelling form.


}





The code for the Form1 where rich text box exists:




public spellChecker_frm() // Default constructor called when program starts.
{
InitializeComponent();
i = 0 ;
}
public spellChecker_frm(String content)// overloaded constructor i made.
{
InitializeComponent();
this.textContainer_rtb.Text = content; // content thrown from TextSpelling Form using avove code.
}



Now this overloaded constructor is expected to again fill the rich text box with the content being thrown from TextSpelling form but i don't know why not it doing that because i reckon that the form 1 is not being called again?


Secondly, i ain't getting the 3rd option as it seem to me a bit alien because it s incomplete as i want a full fledged example.


No comments:

Post a Comment