▼ ps.bat ( PowerShell をそのまま使えない場合は以下のバッチファイルを作成して使用します )
@powershell -NoProfile -ExecutionPolicy Unrestricted "./%1.ps1"✅ build.ps1 exe 作成用 PowerShell スクリプト ✅ Program.cs アプリケーション開始 ✅ Form1.cs Form コントロール ✅ Form1.Designer.cs 画面定義 ▼ build.ps1
Add-Type -path "Program.cs", "Form1.cs", "Form1.Designer.cs" ` -ReferencedAssemblies System.Windows.Forms, System.Drawing ` -OutputAssembly form-01.exe ` -OutputType WindowsApplication Read-Host "何かキーを押してください"
プログラムは、入力した内容をボタンをクリックした後 MessageBox で表示するだけのものです。つまりは、Form アプリケーションを テキストエディタのみで作成するテンプレートでもあります。
▼ Program.cs
using System;
using System.Windows.Forms;
namespace form_01
{
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
▼ Form1.cs
using System;
using System.Windows.Forms;
namespace form_01
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(textBox1.Text);
}
}
}
▼ Form1.Designer.cs
namespace form_01
{
partial class Form1
{
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(65, 48);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(243, 19);
this.textBox1.TabIndex = 0;
//
// button1
//
this.button1.Location = new System.Drawing.Point(64, 94);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(243, 28);
this.button1.TabIndex = 1;
this.button1.Text = "実行";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(534, 290);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "タイトル";
this.ResumeLayout(false);
this.PerformLayout();
}
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
}
}
|
|
【PowerShell + C#の最新記事】
- nuget.exe CLI を使用してパッケージをダウンロードし、C# のソースコードで利用して PowerShell でビルドする
- PowerShell を使用して、C# のコンソールアプリ用のソースコードから exe を作成する( WebClient で wget.exe ) / ビルドせずに PowerShell で実行
- PowerShell で VisualStudio で作成した Form アプリケーションをビルドする( DataGridView に select 文の結果を表示する / MySQL )
- TKMP + imap + C# + PowerShell : メールボックス(階層)の一覧表示
- nuget.exe + SMO + PowerShell + C# : テーブルの CREATE TABLE 文 を取得
- PowerShell( 実質C# )を使用して、ファイルの分割を行う
- PowerShell( 実質C# )を使用して、MessageBox の応答でバッチファイルの処理を変化させる
- PowerShell で C# のソースコード(get_rec_mysql.cs) を使用して System.Data.Odbc で MySQL のデータを一覧表示( csv )


▼ ps.bat ( PowerShell をそのまま使えない場合は以下のバッチファイルを作成して使用します )




