2011-03-05 85 views
0
private void buttonPlay_Click(object sender, EventArgs e)//This is the the button. 
{ 
    //This is the class that I want to throw to another window and run at the same time. 
    //I want this class to pop up in another window. How would I do this? 
    Matrix.MatrixEffect();  
} 

這是矩陣類:你怎麼做一個類時彈出按鈕被按下

using System; 

namespace JasonsMatrix 
{ 
    class Matrix 
    { 
     internal static void MatrixEffect() 
     { 

      Console.Title = "The Matrix (Remember It's a Secret)"; 
      Console.ForegroundColor = ConsoleColor.DarkGreen; 
      Console.WindowLeft = Console.WindowTop = 0; 
      Console.WindowHeight = Console.BufferHeight = Console.LargestWindowHeight; 
      Console.WindowWidth = Console.BufferWidth = Console.LargestWindowWidth; 

#if readkey 
      Console.WriteLine("H1T 7NY K3Y T0 C0NT1NU3 =/"); 
      Console.ReadKey(); 
#endif 

      Console.CursorVisible = false; 
      int width, height; 
      int[] y; 
      int[] l; 
      Initialize(out width, out height, out y, out l); 
      int ms; 

      while (true) 
      { 
       DateTime t1 = DateTime.Now; 
       MatrixStep(width, height, y, l); 
       ms = 10 - (int)((TimeSpan)(DateTime.Now - t1)).TotalMilliseconds; 

       if (ms > 0) 
        System.Threading.Thread.Sleep(ms); 

       if (Console.KeyAvailable) 
        if (Console.ReadKey().Key == ConsoleKey.F5) 
         Initialize(out width, out height, out y, out l); 
      } 
     } 

     static bool thistime = false; 

     private static void MatrixStep(int width, int height, int[] y, int[] l) 
     { 
      int x; 
      thistime = !thistime; 

      for (x = 0; x < width; ++x) 
      { 
       if (x % 11 == 10) 
       { 
        if (!thistime) 
         continue; 

        Console.ForegroundColor = ConsoleColor.White; 
       } 
       else 
       { 
        Console.ForegroundColor = ConsoleColor.DarkGreen; 
        Console.SetCursorPosition(x, inBoxY(y[x] - 2 - (l[x]/40 * 2), height)); 
        Console.Write(R); 
        Console.ForegroundColor = ConsoleColor.Green; 
       } 
       Console.SetCursorPosition(x, y[x]); 
       Console.Write(R); 
       y[x] = inBoxY(y[x] + 1, height); 
       Console.SetCursorPosition(x, inBoxY(y[x] - l[x], height)); 
       Console.Write(' '); 
      } 
     } 

     private static void Initialize(out int width, out int height, out int[] y, out int[] l) 
     { 
      int h1; 
      int h2 = (h1 = (height = Console.WindowHeight)/2)/2; 
      width = Console.WindowWidth - 1; 
      y = new int[width]; 
      l = new int[width]; 
      int x; 
      Console.Clear(); 
      for (x = 0; x < width; ++x) 
      { 
       y[x] = r.Next(height); 
       l[x] = r.Next(h2 * ((x % 11 != 10) ? 2 : 1), h1 * ((x % 11 != 10) ? 2 : 1)); 
      } 
     } 

     static Random r = new Random(); 

     static char R 
     { 
      get 
      { 
       int t = r.Next(10); 
       if (t <= 2) 
        return (char)('0' + r.Next(10)); 
       else if (t <= 4) 
        return (char)('a' + r.Next(27)); 
       else if (t <= 6) 
        return (char)('A' + r.Next(27)); 
       else 
        return (char)(r.Next(32, 255)); 
      } 
     } 

     public static int inBoxY(int n, int height) 
     { 
      n = n % height; 
      if (n < 0) 
       return n + height; 
      else 
       return n; 
     } 



    } 
} 
+1

這是什麼(除C#這是顯而易見的):ASP.NET,Silverlight中,的WinForms,WPF,Windows手機,Xbox 360遊戲機,Zune播放器, ...? – 2011-03-05 18:05:44

+0

Mercer,所以你有一個控制檯應用程序。它也使用表單。所以當你運行它時,會出現一個控制檯窗口,並且在某個時候,窗體也會出現。那是對的嗎?現在,當您按下按鈕時,是否要將效果顯示在原始控制檯窗口中?或新窗口?或者你是否想要在表單中顯示它(這將需要更改Matrix類)? – 2011-03-06 00:29:50

回答

1

(我假設的WinForms,但沒有特別的理由 - 事情會完全不同以ASP.NET爲例。)

您應該創建一個新表單來託管矩陣效果,並在該表單中顯示矩陣效果。在不知道Matrix.MatrixEffect究竟是什麼的情況下,很難詳細說明細節。你不要把課程「扔」到另一個窗口......

你還應該考慮是否通過「彈出」你是指一個模式對話框,或者只是一個額外的窗口,它將同時「運行」你現有的。

+0

這將是一個額外的窗口,將與現有的窗口一起運行。 – 2011-03-05 18:10:36

+0

@James Mercer,你好像忽略了這些問題:請定義* Window *。這是什麼類型的應用程序? – 2011-03-05 18:13:12

+0

Matrix是一個控制檯應用程序,並且該按鈕位於窗體上。 – 2011-03-05 18:29:03

0

看起來這是一個控制檯應用程序。如果你想打開一個新的控制檯窗口,你必須使用System.Diagnostics.Process類生成一個新的進程。您可以使用命令行參數或環境變量將數據傳遞給新應用程序。對於更高級的方法,您可以使用標準輸入和輸出來回傳遞數據。

您將無法使用單個類來完成此操作,這些更改將爲您的解決方案提供新的體系結構。

+0

我不知道你在說什麼。你能解釋一下,對我來說這是愚蠢的條款。 – 2011-03-05 18:47:38

0
process.start(@"something.exe"); 

//被所有的一切需要的是說

相關問題