###検証環境
・Windows10 64bit 1909 build 18363.1082
・DotnetFramework x64 v4.0.30319
###参考(というかほとんどパクリ…)
https://qiita.com/toshirot/items/dcf7809007730d835cfc
###手順
①下記のサンプルcsファイルを作成
test.cs
using System;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Reflection;
using System.Windows.Forms;
using System.Drawing;
class Neko : Form {
[STAThread]
public static void Main() {
GeneratedCodeAttribute generatedCodeAttribute = new GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator","10.0.0.0);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run( new Neko());
}
Neko(){
Text = "Button Click Sample";
ClientSize = new Size(200, 200);
Button btn1 = new Button();
TextBox txb1 = new TextBox();
Label lb1 = new Label();
btn1.Location = new Point(50, 50);
txb1.Location = new Point(100,100);
lb1.Location = new Point(150,150);
btn1.Text = "Click!";
btn1.Click += btn1_Click;
lb1.Text = "test";
Controls.AddRange(new Control[] { btn1 });
Controls.AddRange(new Control[] { txb1 });
Controls.AddRange(new Control[] { lb1 });
}
void btn1_Click(object sender, System.EventArgs e) {
MessageBox.Show("こんにちはにゃー", "挨拶");
}
}
②コマンドプロントを起動し下記コードを実行
実行
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe D:\test\test.cs