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
Stephen Walsh
NA
15
15.4k
Replace text in RichTextBox
Apr 17 2013 10:39 AM
I am creating a word pad style text editor & I am having problems trying to replace text.
Rather than having a separate form for this I have created a toolstrip with a find textbox (tstxtSearchText), a find button (tsbtnFind), a replace text box (tstxtReplaceText) & a replace button (tsbtnReplace). My find function works fine but I cannot figure out replace.
Here is my find code:
private void tsbtnFind_Click(object sender, EventArgs e)
{
int length = txtMain.TextLength;
int index = 0;
int lastIndex = txtMain.Text.LastIndexOf(this.tstxtSearchText.Text);
while (index < lastIndex)
{
txtMain.Find(tstxtSearchText.Text, index, length, RichTextBoxFinds.None);
txtMain.SelectionBackColor = Color.Yellow;
index = txtMain.Text.IndexOf(tstxtSearchText.Text, index) + 1;
}
}
I have tried the following code for the Replace click event:
private void tsbuttonReplace_Click(object sender, EventArgs e)
{
if (tstxtReplaceText.SelectionLength > 0)
{
int start = tstxtReplaceText.SelectionStart;
int len = tstxtReplaceText.SelectionLength;
tstxtReplaceText.Text = tstxtSearchText.Text.Remove(start, len);
txtMain.Text = tstxtReplaceText.Text.Insert(start, tstxtReplaceText.Text);
txtMain.Focus();
}
}
* txtMain is the text editor of the form.
This appears to do nothing. If anyone can see where I am going any help would be greatly appreciated. Thanks in advance.
Reply
Answers (
10
)
from my SPoutput, thestudid,namecolumncannot be repeat
serialPort1.WriteLine error