Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / October 2006

Tip: Looking for answers? Try searching our database.

C# Question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Irfan faruki - 11 Oct 2006 11:49 GMT
Hi
I am learning C# at the moment and is trying to recreate Notepad. I have
some question in regards to it so it will be nice if someone can answer them
for me pleaes. They are as below

1: Should i use Multiline Textbox or a Richtext control?

2: How do i go about creating something like Find & Replace ( Just like
Notepad)

3: 2: How do i go about creating something like Go To ( Just like Notepad)

Thanks
Irfan
Bryan - 11 Oct 2006 17:47 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.