0

So, I am making a very simple application in Notepad++ and right now, it is only like CMD! How do I add UI to this C# Application WITHOUT VISUAL STUDIO? Google gives me nothing but Visual Studio tutorials and I want to be able to program without an IDE. Also, just give me an example of adding a simple button in C#.

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
MrStank
  • 314
  • 4
  • 10

2 Answers2

3

You'll have to write all the Forms/UI code yourself manually as well as manage your events / logic code.

Here goes a simple Form with a Button that shows a Message Box. You can see other examples, as answered on stackoverflow here and here.

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());
        }
    }
}
Community
  • 1
  • 1
Abdullah Leghari
  • 2,332
  • 3
  • 24
  • 40
1

Visual Studio is not any plugin to generate a UI for your application, you can do that in your Notepad++ too. What you need to be using or looking for is a framework which would allow you to use such feature.

In .NET framework, you can use Windows Forms or Windows Presentation Foundation to create the applications with Buttons, TextBox and TextBlock controls. You would be able to get the assemblies required to work with such frameworks in your own IDE too.

The button in WPF or Win Forms is as simple as

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

.. but you need to be having those frameworks added, you can look into Web Froms or WPF on MSDN. Just install the frameworks, add them to the Notepad++ to use them in Notepad++.

Afzaal Ahmad Zeeshan
  • 15,669
  • 12
  • 55
  • 103