Windows 窗体文本框 - 淡入/淡出背景颜色

发布于 2024-07-27 14:54:01 字数 1437 浏览 6 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遗弃M 2024-08-03 14:54:01

假设这是 C#/.NET,创建您自己的用户控件是解决此问题的适当方法。 您的控件不应从 UserControl 继承,而应从 TextBox 继承 - 这将使您的控件的外观和行为就像普通的 TextBox 一样,并且您可以添加代码来处理淡入淡出效果:

public partial class MyCustomTextbox : Textbox
{

}

要实现淡入淡出,您必须创建某种计时器来使用如下函数逐步更改 BackColor

function FadeBackground(float progress)
{
    Color color = Color.FromArgb(255, (int)((1 - progress) * 255),
        (int)((1 - progress) * 255));
    base.BackColor = color;
}

当参数 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 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文