如何在字符串中获取inputbox的结果 [英] How to get results of inputbox in a string

查看:72
本文介绍了如何在字符串中获取inputbox的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过添加visual basic reference为我的项目添加了一个输入框。

但是现在我不知道如何将它的结果存储在一个字符串中,这样当用户点击ok按钮时在这个输入框中,他发现了特定的匹配结果。

如果你能告诉我如何设置工具按钮只搜索单词,如果用户点击确定按钮,那将是非常有用的



我尝试了什么:



  private   void  findToolStripMenuItem_Click( object  sender,EventArgs e)
{
Microsoft.VisualBasic.Interaction.InputBox( 输入要搜索的字 查找 < span class =code-string>);
int value = 0 ;
string temp = Getnew()。Text;
Getnew()。文本= ;
Getnew()。Text = temp;
while (value< Getnew()。Text.LastIndexOf( 应包含带有inputbox结果的字符串变量))
{
// 搜索richtextbox中的文本
Getnew()。查找( 应包含字符串变量,其结果为inputbox value ,Getnew()。TextLength,RichTextBoxFinds.None);
// 找到匹配项时自动添加选择颜色
Getnew()。 SelectionBackColor = Color.LightYellow;
// 继续搜索单词
value = Getnew()。Text.IndexOf(Getnew()。Text, value )+ 1 ;
}

解决方案

除非你真的,否则不要使用InputBox或任何VB的东西必须 - 而且在这里你没有。



相反,为他创建一个新表单来输入他的数据,添加一个文本框,然后确定并取消按钮。

添加一个属性,让你获取并设置值,并在你的代码中使用它:

 MyInputForm mif =  new  MyInputForm(); 
mif.UserInput = 默认值;
if (mif.ShowDialog()== DialogResult.OK)
{
string userInput = mif.UserInput;
...
}

这样,你可以更加灵活 - 添加验证,搜索时输入而不是等待ENTER,加载东西。


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:

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;
           }

解决方案

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:

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.


这篇关于如何在字符串中获取inputbox的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆