如何在没有 IDE 的情况下添加 UI

本文关键字:情况下 添加 UI IDE | 更新日期: 2023-09-27 18:31:32

所以,我正在记事本++中制作一个非常简单的应用程序,现在,它就像CMD一样!如何在没有VISUAL STUDIO的情况下将UI添加到此C#应用程序?谷歌只给了我Visual Studio教程,我希望能够在没有IDE的情况下编程。另外,给我一个在 C# 中添加简单按钮的示例。

如何在没有 IDE 的情况下添加 UI

您必须自己手动编写所有表单/UI 代码以及管理事件/逻辑代码。

下面是一个简单的窗体,其中包含一个显示消息框的按钮。您可以在此处和此处查看其他示例,如堆栈溢出的答案。

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());
        }
    }
}

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

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

WPF 或 Win 窗体中的按钮非常简单:

// 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 Froms或WPF。只需安装框架,将它们添加到记事本++即可在记事本++中使用它们。