2014-01-24 18 views
-1

我有興趣開發文本編輯器等軟件。在沒有窗體設計器的情況下開發UI軟件?

我現在知道如何開發C#軟件的唯一方法是使用Visual Studio的窗體設計器:http://i.imgur.com/oRAd6M4.png

在Java中有可能(我知道如何)做到這一點。

是否有可能在C#中開發軟件,比如它是如何在Java中完成的(通過100%的代碼)。

+2

咦? 「形式」是什麼意思?你問是否可以在沒有UI的情況下製作UI? – SLaks

+0

請勿使用窗體,請使用Windows(WPF):P – Habib

+2

您是否在詢問控制檯UI?是的,這是可能的。 –

回答

1

是的,這是非常可能的。表單設計器只是一個在後臺生成代碼的視覺包裝器。您可以使用WPF,這是一種聲明式的UI設計方法。你可以用WinForms做同樣的事情。這是一個用手寫的簡單表單示例。除了練習,我不明白你爲什麼要這樣做的不平凡的UI應用程序。

namespace MyTestApp 
{ 
    public static class Program 
    { 
     [System.STAThread] 
     private static void Main() 
     { 
      System.Windows.Forms.Application.EnableVisualStyles(); 
      System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false); 

      System.Windows.Forms.Application.Run(new MyForm()); 
     } 

     public class MyForm: System.Windows.Forms.Form 
     { 
      private System.Windows.Forms.Button ButtonClose { get; set; } 
      private System.Windows.Forms.RichTextBox RichTextBox { get; set; } 

      public MyForm() 
      { 
       this.ButtonClose = new System.Windows.Forms.Button(); 
       this.RichTextBox = new System.Windows.Forms.RichTextBox(); 

       this.ButtonClose.Text = "&Close"; 
       this.ButtonClose.Click += new System.EventHandler(ButtonClose_Click); 

       this.Controls.Add(this.ButtonClose); 
       this.Controls.Add(this.RichTextBox); 

       this.Load += new System.EventHandler(MyForm_Load); 
      } 

      private void MyForm_Load (object sender, System.EventArgs e) 
      { 
       int spacer = 4; 

       this.RichTextBox.Location = new System.Drawing.Point(spacer, spacer); 
       this.RichTextBox.Size = new System.Drawing.Size(this.ClientSize.Width - this.RichTextBox.Left - spacer, this.ClientSize.Height - this.RichTextBox.Top - spacer - this.ButtonClose.Height - spacer); 

       this.ButtonClose.Location = new System.Drawing.Point(this.ClientSize.Width - this.ButtonClose.Width - spacer, this.ClientSize.Height - this.ButtonClose.Height - spacer); 
      } 

      private void ButtonClose_Click (object sender, System.EventArgs e) 
      { 
       this.Close(); 
      } 
     } 
    } 
} 

或者,使用設計器時,請查看FormName.Designer.cs文件,其中包含與上面相同的初始化代碼。

相關問題