2017-01-19 4 views
-1

私は現在プログラムを作成中です。私はキーを押した後にアプリケーションをリフレッシュする方法を理解できません。キーを押した後、アプリケーションをリフレッシュする方法はありますか? C#

これまでのところ、私が持っている:

Console.WriteLine("Press Any Key To Refresh"); 

Console.ReadKey(); 

全コードブロック

class Program 
{ 
    static void Main(string[] args) 
    { 
     int userInput; 
     DirectoryInfo folderInfo = new DirectoryInfo("C:\\Windows"); 
     FileInfo[] files = folderInfo.GetFiles(); 


     Console.WriteLine("Welcome To File Manager"); 

     Console.WriteLine(""); 

     Console.WriteLine("Current Folder: C:\\Windows"); 

     Console.WriteLine(""); 

     Console.WriteLine("Please Select An Opion Between 1 To 4:"); // Displays Options for Main Menu. 
     Console.WriteLine("1. "); 
     Console.WriteLine("2. "); 
     Console.WriteLine("3. "); 
     Console.WriteLine("4. "); 
     userInput =int.Parse(Console.ReadLine()); 
     { 
      if (userInput == 1) 
      { 
       Console.WriteLine("Files in C:\\Windows:"); 
       for (int index = 0; index < files.Length; index++) // Lists The Files Within The Speficied Folder C:\\Windows - Also Assigns Numerical Value To Each File. 
       { 
        Console.WriteLine("{0}" , index + ". " + 1 + files[index].Name + " (" +(files[index].Length) + ")"); 


       } 
       Console.WriteLine("Press Any Key To Return To Main Menu"); 
       Console.ReadKey(); 



      } 

      else if (userInput == 2) 
      { 
       // code for option 2 
      } 
      else if (userInput == 3) 
      { 
       // Code for option 3 
      } 
      else if (userInput == 4) 
      { 
       // Closes Application. 
      } 
     } while (userInput != 4); 

オプション内の操作は、(1)、メッセージを走っていたら、 「すべてのキーを押して更新する」と表示されます - その後、キーを押すとアプリケーションを更新します。

私はこれが私が求めていたことを明確にしたいと思う!

多くのおかげ - ダン

+5

C#アプリケーションを「リフレッシュする」とはどういう意味ですか? –

+0

アプリケーションは、閉じたり開いたりすることなく元の状態に戻ります。これは可能ですか? –

+1

私はこれがプログラミングクラスのいくつかのイントロであると推測しています。すべてのものを 'while(refresh)loop'ループで囲み、リフレッシュをループ外のブール値として定義し、' true'に初期化します。上記の2行が定義されている 'while'ブロックの最後にある特定のキーをユーザが処理した場合にのみ、' refresh'を 'false'に設定してください。 – Igor

答えて

-1

私はあなたが達成したいものを正しく理解場合、これは役立つかもしれません。

 bool isClicked = true; 

     while(isClicked) 
     { 
      Console.WriteLine("Please Select An Opion Between 1 To 4:"); 
      int userInput = int.Parse(Console.ReadLine()); 

      switch (userInput) 
      { 
       case 1: 
        Console.WriteLine("Press Any Key To Return To Main Menu"); 
        Console.ReadKey(); 

        //isClicked = false;  // Used to suspend the operation 

        break; 
       case 2: 
        // code for option 2 
        break; 
       case 3: 
        // code for option 3 
        break; 
       case 4: 
        // code for option 4 
        break; 
       default: 
        Console.WriteLine("Error occured"); 
        break; 
      } 
     }  
関連する問題