2017-08-17 37 views
1

我是C#编程新手。目前,我使用下面的代码来获取用户输入,并在用户键入文本框内并按下Ok后,整个输入框关闭。用户必须每次运行该程序以获取输入框。如何保持输入框始终打开?这是一个C#程序,我使用了Microsoft.VisualBasic参考来运行代码。即使在用户按下确定按钮后,如何保持Microsoft.VisualBasic.Interaction.InputBox打开?

using System; 
using System.Linq; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Text; 
using System.IO; 

namespace Text 
{ 
class Program 
{ 
    static void Main(string[] args) 
    { 
     string input = Microsoft.VisualBasic.Interaction.InputBox("Please Type In The Number", "Type"); 

     if (input == "") 
     { 
     } 
     bool valid = false; 

    } 
} 
} 

回答

0

你需要把它放在某种循环中。输入框的工作方式是打开它,获取用户输入关闭并传递输入的数据。我想你想是有它重新每次用户点击好吗

试试这个代码时,它应该是类似于你想要

using System; 
using System.Linq; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Text; 
using System.IO; 

namespace Text 
{ 
class Program 
{ 
    static void Main(string[] args) 
    { 
    //create variable 
    bool valid = false; 
    //start loop 
    //when ever the valid boolean evaluates as false the loop continues 
    // when its true it will kick out of the loop 
    while(valid == false) 
    { 
     \\create input box and store variable 
     string input = Microsoft.VisualBasic.Interaction.InputBox("Please Type In The Number", "Type"); 

     \\check if variable is 'exit' if it is set boolean to true 
     if (input == "exit") 
     { 
       valid = true; 
     } 
     \\otherwise its false and the loop will continue 
     else 
     { 
       valid = false 
     } 
     } 
    } 
} 
} 

此代码什么创造终止时,一个简单的while循环用户输入退出到输入框

相关问题