2014-11-23 54 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()); 
     } 
    } 
} 
相关问题