Created
December 30, 2014 10:23
-
-
Save kazuooooo/38d23d04f9067499e33e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Windows.Forms; | |
public class Sample1:Form | |
{ | |
private Label lb; | |
private TextBox tb; | |
public static void Main(){ | |
Application.Run (new Sample1 ()); | |
} | |
public Sample1(){ | |
this.Text ="Sample"; | |
this.Width = 200; | |
this.Height = 200; | |
lb = new Label (); | |
lb.Text = "Welcome"; | |
lb.Dock = DockStyle.Top; | |
tb = new TextBox (); | |
tb.Dock = DockStyle.Bottom; | |
lb.Parent = this; | |
tb.Parent = this; | |
tb.KeyDown += new KeyEventHandler (tb_KeyDown); | |
} | |
public void tb_KeyDown(Object sender, KeyEventArgs e){ | |
//senderにはObjectとして色々情報が入っている。 | |
//その中からTextBoxの情報をCastで取り出しているよ | |
TextBox tmp = (TextBox)sender; | |
if (e.KeyCode == Keys.Enter) { | |
lb.Text = tmp.Text+" is selected"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment