Assuming this is C#/.NET, creating your own user control is an appropriate solution to this problem. Instead of inheriting from UserControl, your control should instead inherit from TextBox - this will make your control look and act just like an ordinary TextBox, and you can add code to handle the fading effect:
public partial class MyCustomTextbox : Textbox
{
}
To do the fading, you'd have to create some sort of timer to progressively change BackColor with a function like this:
function FadeBackground(float progress)
{
Color color = Color.FromArgb(255, (int)((1 - progress) * 255),
(int)((1 - progress) * 255));
base.BackColor = color;
}
When parameter progress = 0, this will produce a white background, and when progress = 1 this will be full red.
发布评论
评论(1)
假设这是 C#/.NET,创建您自己的用户控件是解决此问题的适当方法。 您的控件不应从
UserControl
继承,而应从TextBox
继承 - 这将使您的控件的外观和行为就像普通的TextBox
一样,并且您可以添加代码来处理淡入淡出效果:要实现淡入淡出,您必须创建某种计时器来使用如下函数逐步更改
BackColor
:当参数
progress = 0,这将产生白色背景,当
progress
= 1 时,这将产生全红色。Assuming this is C#/.NET, creating your own user control is an appropriate solution to this problem. Instead of inheriting from
UserControl
, your control should instead inherit fromTextBox
- this will make your control look and act just like an ordinaryTextBox
, and you can add code to handle the fading effect:To do the fading, you'd have to create some sort of timer to progressively change
BackColor
with a function like this:When parameter
progress
= 0, this will produce a white background, and whenprogress
= 1 this will be full red.