0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

cscの作法 その651

0
Posted at

概要

cscの作法、調べてみた。
Neo.IronLua、見つけたので、やってみた。
luaでformを生成する。

サンプルコード

using System;
using System.Windows.Forms;
using Neo.IronLua;

class Program {
	[STAThread]
	static void Main() {
		using (Lua lua = new Lua())
		{
			LuaGlobal global = lua.CreateEnvironment();
			Form mainForm = new Form {
				Text = "NeoLua GUI App",
				Width = 400,
				Height = 250,
				StartPosition = FormStartPosition.CenterScreen
			};
			global["AddButton"] = new Action<string, string>((buttonText, messageToShow) => {
				Button btn = new Button {
					Text = buttonText,
					Dock = DockStyle.Fill
				};
				btn.Click += (sender, e) => {
					MessageBox.Show(messageToShow, "通知");
				};
				mainForm.Controls.Add(btn);
			});
			global["ShowForm"] = new Action(() => {
				mainForm.ShowDialog();
			});
			try
			{
				global.DoChunk("wnd.lua");
			}
			catch (Exception ex)
			{
				Console.WriteLine("エラーが発生しました: " + ex.Message);
			}
		}
	}
}


luaコード

print("シンプルなGUI画面を表示します...")
AddButton("ここをクリックして挨拶", "こんにちは!NeoLuaからForms画面が動いています!")
ShowForm()

写真

image.png

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?