概要
cscの作法、調べてみた。
vbsから操れるUIコンポーネント(DLL)をC#で書いてみた。
環境
windows 11
サンプルコード
using System;
using System.Windows.Forms;
using System.Drawing;
namespace Ohi
{
public class Compo7: Form {
private static string retValue = String.Empty;
private TextBox textBox1;
private TextBox textBox2;
private Button button1;
private Button button2;
private Button button3;
private Button button4;
public Compo7() {
Text = "Ohicompo7";
ClientSize = new Size(550, 550);
textBox1 = new TextBox();
textBox1.Location = new Point(30, 30);
textBox1.Multiline = true;
textBox1.Size = new Size(400, 400);
textBox1.TabIndex = 2;
textBox1.Text = retValue;
textBox2 = new TextBox();
textBox2.Location = new Point(30, 450);
textBox2.Size = new Size(400, 40);
textBox2.Text = "";
button1 = new Button();
button1.Location = new Point(450, 50);
button1.Text = "0";
button1.Click += new EventHandler(button1_Click);
button2 = new Button();
button2.Location = new Point(450, 100);
button2.Text = "1";
button2.Click += new EventHandler(button2_Click);
button3 = new Button();
button3.Location = new Point(450, 150);
button3.Text = "2";
button3.Click += new EventHandler(button3_Click);
button4 = new Button();
button4.Location = new Point(450, 450);
button4.Text = "send";
button4.Click += new EventHandler(button4_Click);
Controls.AddRange(new Control[] {
textBox1,
textBox2,
button1,
button2,
button3,
button4
});
}
private void button1_Click(object sender, EventArgs e) {
retValue = "0";
this.Close();
}
private void button2_Click(object sender, EventArgs e) {
retValue = "1";
this.Close();
}
private void button3_Click(object sender, EventArgs e) {
retValue = "2";
this.Close();
}
private void button4_Click(object sender, EventArgs e) {
retValue = textBox2.Text;
this.Close();
}
public void Put(string str) {
retValue = str;
}
[STAThread]
public string Open() {
Application.EnableVisualStyles();
Application.Run(new Compo7());
return retValue;
}
}
}
コンパイル手順
>set PATH=C:\Windows\Microsoft.NET\Framework\v4.0.30319;%PATH%
>csc /target:library /platform:anyCPU ohicompo7.cs
>regasm /codebase ohicompo7.dll
以上。