// --------------------------- top of file MyForm.cs ---------------------------- using System.Windows.Forms; using System.Drawing; using System; public class MyForm : Form { private Button genuinebutton; private Button1_Imitated imitatedbutton; private Button2_Pusheffective pusheffectivebutton; private Button3_Automatic automaticbutton; private Button4_Direction Wbutton, Ebutton, Nbutton, Sbutton; private int m_value, x_value=0, y_value=0, xmax=100, ymax=100; private int y1 = 224; [System.STAThread] static void Main() { Application.Run(new MyForm()); } public MyForm() { ClientSize = new Size(390, 370); Text = "Buttons"; BackColor=Color.Beige; ForeColor = Color.DarkOrchid; int x0 = 30; // Label label; Controls.Add( label = new Label() ); label.Text = "本来のボタン(離した時機能する)"; label.SetBounds(x0, 10, 190, 14); Controls.Add( genuinebutton = new Button() ); Color c0 = BackColor; genuinebutton.SetBounds(x0, 24, 150, 24); genuinebutton.Click += new EventHandler(countup); genuinebutton.Text = "genuine button"; // Controls.Add( label = new Label() ); label.Text = "自作のボタン(離した時機能する)"; label.SetBounds(x0, 60, 190, 14); Controls.Add( imitatedbutton = new Button1_Imitated() ); imitatedbutton.SetBounds(x0, 74, 150, 24); imitatedbutton.Click += new EventHandler(countup); imitatedbutton.Text = "imitated button"; // Controls.Add( label = new Label() ); label.Text = "自作のボタン(押した時機能する)"; label.SetBounds(x0, 110, 190, 14); Controls.Add( pusheffectivebutton = new Button2_Pusheffective() ); pusheffectivebutton.SetBounds(x0, 124, 150, 24); pusheffectivebutton.Click += new EventHandler(countup); pusheffectivebutton.Text = "pusheffective button"; // Controls.Add( label = new Label() ); label.Text = "自作のボタン(押した時と、連続動作)"; label.SetBounds(x0, 160, 220, 14); Controls.Add( automaticbutton = new Button3_Automatic() ); automaticbutton.SetBounds(x0, 174, 150, 24); automaticbutton.Click += new EventHandler(countup); automaticbutton.Text = "automatic button"; // --------------------- Controls.Add( label = new Label() ); label.Text = "自作の方向指定ボタン(押した時と、連続動作)"; label.SetBounds(x0, y1-14, 240, 14); // Controls.Add( Wbutton = new Button4_Direction() ); Wbutton.SetBounds(x0, y1+25, 24, 24); Wbutton.Click += (o, e) => { x_value--; if (x_value<0) { x_value = 0; } Invalidate(); }; Wbutton.Text = "W"; // Controls.Add( Ebutton = new Button4_Direction() ); Ebutton.SetBounds(x0+50, y1+25, 24, 24); Ebutton.Click += (o, e) => { x_value++; if (x_value>xmax) { x_value = xmax; } Invalidate(); }; Ebutton.Text = "E"; // Controls.Add( Nbutton = new Button4_Direction() ); Nbutton.SetBounds(x0+25, y1, 24, 24); Nbutton.Click += (o, e) => { y_value--; if (y_value<0) { y_value = 0; } Invalidate(); }; Nbutton.Text = "N"; // Controls.Add( Sbutton = new Button4_Direction() ); Sbutton.SetBounds(x0+25, y1+50, 24, 24); Sbutton.Click += (o, e) => { y_value++; if (y_value>ymax) { y_value = ymax; } Invalidate(); }; Sbutton.Text = "S"; } // ======================================================== private void countup(object sender, EventArgs e) { m_value++; Invalidate(); } // ======================================================== protected override void OnPaint(PaintEventArgs e) { Graphics g=e.Graphics; Brush solidbrush = new SolidBrush(ForeColor); Font fontgothic18 = new Font("MS ゴシック", 64); g.DrawString( m_value.ToString(), fontgothic18, solidbrush, 240, 70); int L = 10, xbase=140, ybase=y1+15; g.DrawRectangle(new Pen(Color.Blue), xbase, ybase, xmax, ymax); g.DrawLine(new Pen(Color.Black), xbase+x_value, ybase+y_value-L, xbase+x_value, ybase+y_value+L); g.DrawLine(new Pen(Color.Black), xbase+x_value-L, ybase+y_value, xbase+x_value+L, ybase+y_value); } // ======================================================== } // ######################### end of class MyForm ########################### // --------------------------- bottom of file MyForm.cs --------------------------