实现效果
参考代码:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TextBoxColor
{
public class TextBoxColor: TextBox
{
public Color XuanColor { get; set; } = Color.Red;
public Color FeiXuanClolor { get; set; } = Color.Green;
public TextBoxColor()
{
this.BackColor = this.FeiXuanClolor;
}
protected override void OnEnter(EventArgs e)
{
this.BackColor = this.XuanColor;
base.OnEnter(e);
//this.BackColor = this.XuanColor;
}
protected override void OnLeave(EventArgs e)
{
this.BackColor = this.FeiXuanClolor;
base.OnEnter(e);
//this.BackColor = this.FeiXuanClolor;
}
}
}
参考链接
winform 重写TextBox的OnTextChanged方法(事件)-CSDN博客https://blog.csdn.net/weixin_30920853/article/details/97443196文本框获取焦点后变色-CSDN博客
https://blog.csdn.net/anlog/article/details/136227357?spm=1001.2014.3001.5502
特此记录
anlog
2024年2月22日