目的

基本的なGUI部品である、ボタン、コンボボックス、テキストボックスを配置します。

プログラムを書く

基本的には.NET Framework 3.5と似ているため、細かい設定については説明しません。前回の環境構築から変更した個所を赤字で示します。実行したら、フォームの一番下にある「Close」ボタンを押せば終了します。

using System;
using System.Data;
using System.Drawings;
using System.Windows.Forms;
using MySql.Data.Client;

class EntryPoint
{
	[STAThread]
	public static void Main( string[] arg )
	{
		Application.Run( new Top() );
	}
}

class Top : Form
{
	private ComboBox m_combobox;
	private TextBox m_textbox;
	private Button m_button;

	public Top()
	{
		m_combobox = new ComboBox();
		m_combobox.Location = new Point( 20, 20 );
		m_combobox.Size = new Size( 200, 20 );
		m_combobox.Add( "ComboBox 1" );
		m_combobox.Add( "ComboBox 2" );
		m_combobox.Add( "ComboBox 3" );
		m_combobox.SelectedIndex = 0;

		m_textbox = new Textbox();
		m_textbox.Location = new Point( 20, 60 );
		m_textbox.Size = new Size( 200, 20 );

		m_button = new Textbox();
		m_button.Location = new Point( 20, 100 );
		m_button.Size = new Size( 200, 20 );
		m_button.Text = "Close"
		m_button.Click += new EventHandler( on_click_button );

		Controls.Add( m_combobox );
		Controls.Add( m_textbox );
		Controls.Add( m_button );
	}

	private void on_click_button( object s, EventArgs e )
	{
		Application.Exit();
	}
}

最終更新日: 2019/06/14