using System;
using System.Drawing;
using System.Windows.Forms;
namespace textboxact
{
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
public class Form1 : Form
{
TextBox Atex = new TextBox(), Btex=new TextBox();
public Form1()
{
Atex.Location = new Point(15, 15);
Atex.Multiline = true;
Atex.Size = new Size(270, 110);
Atex.WordWrap = false;
//Atex.KeyDown += Atex_KeyDown;
Atex.KeyPress += _KeyPress;
Btex.Location = new System.Drawing.Point(15, 140);
Btex.Multiline = true;
Btex.Size = new Size(270, 110);
Btex.WordWrap = false;
this.AutoScaleDimensions = new SizeF(6F, 12F);
this.ClientSize = new Size(300, 300);
this.Controls.Add(Btex); this.Controls.Add(Atex);
Atex.GotFocus += text_gotfocus;
Atex.LostFocus += text_lostfocus;
Btex.GotFocus += text_gotfocus;
Btex.LostFocus += text_lostfocus;
}
private void text_gotfocus(object sender, EventArgs e)
{
TextBox tb = sender as TextBox;
if (null == tb) return;
tb.BackColor = SystemColors.Window;
}
private void text_lostfocus(object sender, EventArgs e)
{
TextBox tb = sender as TextBox;
if (null == tb) return;
tb.BackColor = Color.Red;
}
//private void Atex_KeyDown(object sender, KeyEventArgs e)
//{ e.SuppressKeyPress = true; Btex.Select(); }
private void _KeyPress(object sender, KeyPressEventArgs e)
{ e.Handled = true; Btex.Select(); }
}
}