Click here to Skip to main content
15,900,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've added a input box to my project by adding visual basic reference.
but now I don't know how to get it's result stored in a string so that when user hits ok button on this inputbox he finds that particular matching result.
Also it will be very helpful if you can tell me how to set the tool button to only search for words if user hits ok button

What I have tried:

C#
private void findToolStripMenuItem_Click(object sender, EventArgs e)
       {
           Microsoft.VisualBasic.Interaction.InputBox("Enter Word to Search for", "Find","");
           int value = 0;
           string temp = Getnew().Text;
           Getnew().Text = "";
           Getnew().Text = temp;
           while(value<Getnew().Text.LastIndexOf("should contain the string variable with results of inputbox"))
           {
               // searches the text in richtextbox
               Getnew().Find("should contain the string variable with results of inputbox", value, Getnew().TextLength, RichTextBoxFinds.None);
               //selection colour added automatically when match is found
               Getnew().SelectionBackColor = Color.LightYellow;
               // continue searching for words
               value = Getnew().Text.IndexOf(Getnew().Text, value) + 1;
           }
Posted
Updated 31-May-18 2:30am

1 solution

Don't use InputBox, or any of the VB stuff unless you really, really have to - and here you don't.

Instead, create a new form for him to input his data, add a textbox to that, and an OK and Cancel button.
Add a property to let you get and set the value, and use it in your code:
C#
MyInputForm mif = new MyInputForm();
mif.UserInput = "Default value";
if (mif.ShowDialog() == DialogResult.OK)
   {
   string userInput = mif.UserInput;
   ...
   }
That way, you can be a lot more flexible - add validation, searching while he types instead of waiting for ENTER, loads of stuff.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900