Think of it like this:
Multiline TextBox = Notepad
RichTextBox = Wordpad
So if you are really going for the simple look/feel of notepad, then
multiline TextBox is the way to go. This will not allow formatting, font
changes, etc. It is very simple; just like notepad.
To implement Find and Replace, you can use IndexOf on the TextBox.Text
property to find the index of what you are trying to find. Then you can use
TextBox.Select() to highlight the text and maybe prompt the user if they want
to replace that instance. Then use Replace on the TextBox.Text string to
change the text. It is just a bunch of string manipulation with the
TextBox.Text property.
Goto whould be done the same way, just don't replace any text.
Hope that helps.
> Hi
> I am learning C# at the moment and is trying to recreate Notepad. I have
[quoted text clipped - 10 lines]
> Thanks
> Irfan
Irfan faruki - 11 Oct 2006 18:06 GMT
Thanks a lot Bryan. Will give it a try
> Think of it like this:
> Multiline TextBox = Notepad
[quoted text clipped - 29 lines]
> > Thanks
> > Irfan
Irfan faruki - 11 Oct 2006 19:18 GMT
Got another question guys...
I have created a new form for Find and replace ( just like in notepad). Now
how do i get the string thats entered in that form to search for?
> Think of it like this:
> Multiline TextBox = Notepad
[quoted text clipped - 29 lines]
> > Thanks
> > Irfan
Bryan - 11 Oct 2006 21:24 GMT
You need to have a reference to that form in your main form. Then when you
select the menu option to show that form, you can create a new instance and
assign it to that variable. Then call Show(). You should also create a few
events in that form so you can handle the button clicks in the main form.
Attach all of these before you call Show(). Here is some sample code of what
I mean:
This goes in the FindReplaceForm:
public event EventHandler<FindEventArgs> Find;
protected virtual void OnFind(FindEventArgs e)
{
if ( this.Find != null )
{
this.Find(this, e);
}
}
Then create the FindEventArgs class:
public sealed class FindEventArgs : EventArgs
{
private readonly string find;
private readonly string replace;
public FindEventArgs(string find, string replace)
{
this.find = find;
this.replace = replace;
}
public string Find
{
get
{
return this.find;
}
}
public string Replace
{
get
{
return this.replace;
}
}
}
In the button click handlers on the FindReplace form you will create an
instance of the FindEventArgs class, and then call OnFind() to trigger the
event.
Your event handlers in the main form will be able to use the FindEventArgs
instance and get the information you need. You might need more than just one
event and the EventArgs might change depending on what you want to do. This
just gives you a start.
> Got another question guys...
> I have created a new form for Find and replace ( just like in notepad). Now
[quoted text clipped - 33 lines]
> > > Thanks
> > > Irfan
Irfan faruki - 11 Oct 2006 21:52 GMT
Thanks Bryan
> You need to have a reference to that form in your main form. Then when you
> select the menu option to show that form, you can create a new instance and
[quoted text clipped - 91 lines]
> > > > Thanks
> > > > Irfan