2014-11-23 56 views
0

所以,我在Notepad ++中做了一個非常簡單的應用程序,現在它只是像CMD一樣! 如何在沒有VISUAL STUDIO的情況下將UI添加到此C#應用程序中?谷歌給了我什麼,但Visual Studio教程,我希望能夠編程沒有IDE。 另外,給我一個在C#中添加簡單按鈕的例子。如何在沒有IDE的情況下添加UI?

+1

爲什麼你想不使用Visual Studio做到這一點?你可以免費獲得快遞版本。 – Tim 2014-11-23 19:04:20

+0

添加一個簡單的按鈕到什麼?你還沒有窗口可以添加它,你需要首先處理。 – hvd 2014-11-23 19:04:22

+0

爲什麼你不能使用visual studio? – thumbmunkeys 2014-11-23 19:04:26

回答

1

Visual Studio不是任何用於爲應用程序生成UI的插件,您也可以在Notepad ++中執行此操作。你需要使用或尋找的是一個允許你使用這種特性的框架。

在.NET框架中,您可以使用Windows窗體或Windows Presentation Foundation來創建帶有按鈕,文本框和TextBlock控件的應用程序。您將能夠獲得在您自己的IDE中使用此類框架所需的程序集。

在WPF或Windows窗體的按鈕很簡單,只要

// create the button instance for your application 
Button button = new Button(); 
// add it to form or UI element; depending on the framework you use. 

..但你需要是具有這些框架補充,你可以看看Web FromsWPF MSDN上。只需安裝框架,將它們添加到Notepad ++中即可在Notepad ++中使用它們。

3

您必須自己手動編寫所有表單/ UI代碼以及管理事件/邏輯代碼。

這裏用一個簡單的窗體顯示一個消息框。 您可以看到其他示例,如在stackoverflow herehere上回答的那樣。

using System; 
using System.Drawing; 
using System.Windows.Forms; 

namespace CSharpGUI { 
    public class WinFormExample : Form { 

     private Button button; 

     public WinFormExample() { 
      DisplayGUI(); 
     } 

     private void DisplayGUI() { 
      this.Name = "WinForm Example"; 
      this.Text = "WinForm Example"; 
      this.Size = new Size(150, 150); 
      this.StartPosition = FormStartPosition.CenterScreen; 

      button = new Button(); 
      button.Name = "button"; 
      button.Text = "Click Me!"; 
      button.Size = new Size(this.Width - 50, this.Height - 100); 
      button.Location = new Point(
       (this.Width - button.Width)/3 , 
       (this.Height - button.Height)/3); 
      button.Click += new System.EventHandler(this.MyButtonClick); 

      this.Controls.Add(button); 
     } 

     private void MyButtonClick(object source, EventArgs e) { 
      MessageBox.Show("My First WinForm Application"); 
     } 

     public static void Main(String[] args) { 
      Application.Run(new WinFormExample()); 
     } 
    } 
} 
相關問題