【问题标题】:How to add UI without IDE? [duplicate]如何在没有 IDE 的情况下添加 UI? [复制]
【发布时间】:2014-11-23 19:02:05
【问题描述】:

所以,我在 Notepad++ 中制作了一个非常简单的应用程序,而现在,它就像 CMD! 如何在没有 VISUAL STUDIO 的情况下向这个 C# 应用程序添加 UI? Google 只给了我 Visual Studio 教程,我希望能够在没有 IDE 的情况下进行编程。 另外,举个例子,在 C# 中添加一个简单的按钮。

【问题讨论】:

  • 为什么要在不使用 Visual Studio 的情况下执行此操作?您可以免费获得快速版本。
  • 添加一个简单的按钮到什么?您还没有窗口可以添加它,您需要先处理它。
  • 为什么不能使用visual studio?
  • 一个非常简单的应用程序变得不那么简单了,所以如果你手动编写 UI 代码;创建一个表单,初始化它,创建一个按钮,将它添加到表单等

标签: c# user-interface notepad++


【解决方案1】:

您必须自己手动编写所有表单/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());
        }
    }
}

【讨论】:

    【解决方案2】:

    Visual Studio 不是为您的应用程序生成 UI 的任何插件,您也可以在 Notepad++ 中执行此操作。您需要使用或寻找的是一个允许您使用此类功能的框架。

    在 .NET 框架中,您可以使用 Windows 窗体或 Windows Presentation Foundation 来创建具有 Buttons、TextBox 和 TextBlock 控件的应用程序。您也可以在自己的 IDE 中获得使用此类框架所需的程序集。

    WPF 或 Win Forms 中的按钮很简单

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

    .. 但是您需要添加这些框架,您可以查看 MSDN 上的 Web FromsWPF。只需安装框架,将它们添加到 Notepad++ 以在 Notepad++ 中使用它们。

    【讨论】:

      猜你喜欢
      • 2015-09-14
      • 1970-01-01
      • 2013-06-30
      • 2012-07-09
      • 2022-11-22
      • 2014-12-21
      • 2013-05-24
      • 2016-05-24
      • 2015-03-12
      相关资源
      最近更新 更多