1.在代码中定义textBox_MouseClick事件处理
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using WindowsFormsApplication1.util;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void textBox_MouseClick(object sender, MouseEventArgs e)
{
if (textBox1.Focused)
{
textBox1.BackColor = Color.Cyan;
}
else
{
textBox1.BackColor = Color.Teal;
}
if (textBox2.Focused)
{
textBox2.BackColor = Color.Cyan;
}
else
{
textBox2.BackColor = Color.Teal;
}
}
}
}
2.为控件添加textBox_MouseClick事件