views:

977

answers:

1

I want to validate the user's input and I want to inform him/her about validation error with changing background color of a standard Windows Forms TextBox control.

But instead of changing color immediately I would like to use a color fading effect, like here (click on input to see fade in effect, click again to fade out).

Is there any simple way to do it ?

Edit: I also have access to Infragistics controls, I'm not sure if it makes any difference.

+1  A: 

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.

MusiGenesis
Yes, I have custom control ;) I thought about solution that is similar to yours, but not sure if it will be good for application performance, because sometimes I have ~20 entries on screen that are validated :/I'll check it though. Thx for help.
Jarek
If you run the timer only when you need it, pegged at 60 FPS, you shouldn’t notice any performance degradation at all.
Ben Stiglitz
20 controls like this shouldn't be any problem for a WinForms app on anything resembling a modern computer. There is no .Net for Windows 3.1. :)
MusiGenesis
Ok ;) Thanks again for your time.
Jarek