Need help for first project
#1
Posted 21 July 2009 - 08:39 PM
I'm currently working on a really advanced notepad. I've read the tutorial made by Xav I think on how to make a simple notepad and want to know how to add a feature. I have everything all set-up, design wise. So I was wondering how to add a "Find" function for the notepad where it could find the specific text in the body of the written. Something like that of the normal Notepad that comes with Windows. Also if anyone can, please show me how to add a "Replace" and "Go-To" feature. I would be really happy :). I might be asking for a lot but I really just need a explanation of how it works and I can then create it on my own.
|
|
|
#2
Posted 21 July 2009 - 09:37 PM
How to: Search for Text in Documents
private void SelectionFind()
{
object findText = "find me";
Application.Selection.Find.ClearFormatting();
if (Application.Selection.Find.Execute(ref findText,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing))
{
MessageBox.Show("Text found.");
}
else
{
MessageBox.Show("The text could not be located.");
}
}
All you would have to change is the MessageBox.Show function to whatever you want. Maybe you could have it highlight the text?
Wait, this is even better since it has Search and Replace;
private void SearchReplace()
{
object replaceAll = Word.WdReplace.wdReplaceAll;
Application.Selection.Find.ClearFormatting();
Application.Selection.Find.Text = "find me";
Application.Selection.Find.Replacement.ClearFormatting();
Application.Selection.Find.Replacement.Text = "Found";
Application.Selection.Find.Execute(
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref replaceAll, ref missing, ref missing, ref missing, ref missing);
}
Link: How to: Search for and Replace Text in DocumentsThere you actually have search and then another one as search and replace. For the search, as I mentioned all you would have to do is maybe highlight the text and get it to go there. This link should help you with that too;
.NET - Search and Highlight Text in a RichTextBox
Just read through those links and you should be right :)
Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!
#3
Posted 21 July 2009 - 11:31 PM
EDIT: Sorry, look below, I did something wrong.
Edited by Nickalbokid96, 22 July 2009 - 12:09 AM.
#4
Posted 21 July 2009 - 11:38 PM
Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!
#5
Posted 22 July 2009 - 12:09 AM
Error 1 The name 'Word' does not exist in the current context C:\Users\Nick\Documents\Visual Studio 2008\Projects\MyNotePad\MyNotePad\Form1.cs 134 25 MyNotePad Error 2 'System.Windows.Forms.Application' does not contain a definition for 'Selection' C:\Users\Nick\Documents\Visual Studio 2008\Projects\MyNotePad\MyNotePad\Form1.cs 136 17 MyNotePad Error 3 'System.Windows.Forms.Application' does not contain a definition for 'Selection' C:\Users\Nick\Documents\Visual Studio 2008\Projects\MyNotePad\MyNotePad\Form1.cs 137 17 MyNotePad Error 4 'System.Windows.Forms.Application' does not contain a definition for 'Selection' C:\Users\Nick\Documents\Visual Studio 2008\Projects\MyNotePad\MyNotePad\Form1.cs 139 17 MyNotePad Error 5 'System.Windows.Forms.Application' does not contain a definition for 'Selection' C:\Users\Nick\Documents\Visual Studio 2008\Projects\MyNotePad\MyNotePad\Form1.cs 140 17 MyNotePad Error 6 'System.Windows.Forms.Application' does not contain a definition for 'Selection' C:\Users\Nick\Documents\Visual Studio 2008\Projects\MyNotePad\MyNotePad\Form1.cs 142 17 MyNotePad Error 7 The name 'missing' does not exist in the current context C:\Users\Nick\Documents\Visual Studio 2008\Projects\MyNotePad\MyNotePad\Form1.cs 143 13 MyNotePad Error 8 The name 'missing' does not exist in the current context C:\Users\Nick\Documents\Visual Studio 2008\Projects\MyNotePad\MyNotePad\Form1.cs 143 26 MyNotePad Error 9 The name 'missing' does not exist in the current context C:\Users\Nick\Documents\Visual Studio 2008\Projects\MyNotePad\MyNotePad\Form1.cs 143 39 MyNotePad Error 10 The name 'missing' does not exist in the current context C:\Users\Nick\Documents\Visual Studio 2008\Projects\MyNotePad\MyNotePad\Form1.cs 143 52 MyNotePad Error 11 The name 'missing' does not exist in the current context C:\Users\Nick\Documents\Visual Studio 2008\Projects\MyNotePad\MyNotePad\Form1.cs 143 65 MyNotePad Error 12 The name 'missing' does not exist in the current context C:\Users\Nick\Documents\Visual Studio 2008\Projects\MyNotePad\MyNotePad\Form1.cs 144 13 MyNotePad Error 13 The name 'missing' does not exist in the current context C:\Users\Nick\Documents\Visual Studio 2008\Projects\MyNotePad\MyNotePad\Form1.cs 144 26 MyNotePad Error 14 The name 'missing' does not exist in the current context C:\Users\Nick\Documents\Visual Studio 2008\Projects\MyNotePad\MyNotePad\Form1.cs 144 39 MyNotePad Error 15 The name 'missing' does not exist in the current context C:\Users\Nick\Documents\Visual Studio 2008\Projects\MyNotePad\MyNotePad\Form1.cs 144 52 MyNotePad Error 16 The name 'missing' does not exist in the current context C:\Users\Nick\Documents\Visual Studio 2008\Projects\MyNotePad\MyNotePad\Form1.cs 144 65 MyNotePad Error 17 The name 'missing' does not exist in the current context C:\Users\Nick\Documents\Visual Studio 2008\Projects\MyNotePad\MyNotePad\Form1.cs 145 29 MyNotePad Error 18 The name 'missing' does not exist in the current context C:\Users\Nick\Documents\Visual Studio 2008\Projects\MyNotePad\MyNotePad\Form1.cs 145 42 MyNotePad Error 19 The name 'missing' does not exist in the current context C:\Users\Nick\Documents\Visual Studio 2008\Projects\MyNotePad\MyNotePad\Form1.cs 145 55 MyNotePad Error 20 The name 'missing' does not exist in the current context C:\Users\Nick\Documents\Visual Studio 2008\Projects\MyNotePad\MyNotePad\Form1.cs 145 68 MyNotePad
Heres my code
private void Replace_Click(object sender, EventArgs e)
{
private void SearchReplace()
{
object replaceAll = Word.WdReplace.wdReplaceAll;
Application.Selection.Find.ClearFormatting();
Application.Selection.Find.Text = "find me";
Application.Selection.Find.Replacement.ClearFormatting();
Application.Selection.Find.Replacement.Text = "Found";
Application.Selection.Find.Execute(
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref replaceAll, ref missing, ref missing, ref missing, ref missing);
}
}
}
}
If someone could point out, what "The name 'missing' does not exist in the current context" means, that would be greatly appreciated or "'System.Windows.Forms.Application' does not contain a definition for 'Selection'
"
..I feel stupid =l
#6
Posted 22 July 2009 - 01:09 AM
Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!
#7
Posted 22 July 2009 - 08:57 AM
Edited by Nickalbokid96, 22 July 2009 - 10:00 AM.
#8
Posted 22 July 2009 - 04:09 PM
Then you would do something like this is IF the variable for user input was userInput;
Application.Selection.Find.Execute(userInPut)
#9
Posted 22 July 2009 - 05:13 PM
#10
Posted 22 July 2009 - 05:16 PM
Care letting us know on your progress from learning C#? Maybe a blog about what you learn?
Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!
#11
Posted 22 July 2009 - 05:56 PM
By the way, do you recommend any books I should buy or read online? I'm just browsing a few of the Dummies.com ones lol
#12
Posted 22 July 2009 - 05:59 PM
Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!


Sign In
Create Account


Back to top









