示例#1
0
	static Control FormWidget(Racr.AstNode n) {
		var form = new System.Windows.Forms.Form();
		form.Text = "Questionnaire";
		var file = new MenuItem("&File");
		var open = new MenuItem("&Open");
		var save = new MenuItem("&Save");
		var quit = new MenuItem("&Quit");
		open.Click += (object sender, EventArgs e) => {
			var ofd = new OpenFileDialog();
			if (ofd.ShowDialog() == DialogResult.OK) {
				var parser = new Parser(QL.Ql, File.ReadAllText(ofd.FileName));
				var ast = parser.ParseAst();
				ast.Render();
				Questionnaire.UpdateQuestions(ast);
				form.Closed -= FormClosed;
				form.Close();
			}
		};
		save.Click += (object sender, EventArgs e) => {
			var sfd = new SaveFileDialog();
			if (sfd.ShowDialog() == DialogResult.OK && sfd.FileName != "") {
				File.WriteAllText(sfd.FileName, n.SExpr());
			}
		};
		quit.Click += (object sender, EventArgs e) => form.Close();
		form.Closed += FormClosed;

		file.MenuItems.Add(open);
		file.MenuItems.Add(save);
		file.MenuItems.Add(quit);
		form.Menu = new MainMenu();
		form.Menu.MenuItems.Add(file);

		var panel = new FlowLayoutPanel();
		panel.AutoSize = true;
		panel.AutoScroll = true;
		panel.Dock = DockStyle.Fill;
		panel.FlowDirection = FlowDirection.TopDown;
		panel.WrapContents = false;
		form.Controls.Add(panel);
		form.Show();
		return panel;
	}