如何:彩色Flash TextBox背景? [英] How To: Colour Flash TextBox background?

查看:42
本文介绍了如何:彩色Flash TextBox背景?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然起初看起来似乎很简单,但它已经困扰了我一段时间...


我想做的是让背景颜色像TextBox

从(比方说)白色变为黄色变为白色变为黄色然后再变回白色

大约1秒左右。


当用户在4个单选按钮中的一个上单击

时(这会改变TextBox中的Text),这就是创建类似''flash''(或Pulse)的东西。所以在其他

的单词中,要引起用户的注意,文本已经改变了。弹出框是痛苦的,所以我不想去那里(即:他们可能会点击几个RadioButtons)。


我试过了像以下一样简单的测试这个。但你确实没有看到任何背景变化。很明显,我在这里遗漏了一些东西

基本:


私有子rbASME1_CheckedChanged(ByVal发送者As System.Object,_

ByVal e As System.EventArgs)处理rbASME1.CheckedChanged

pltPrefx =" a"

txbScrName.Text = pltPrefx& pltTitle& pltType

Dim TimCtr,TimX As Integer

TimX = 1到4

如果TimX = 1那么txbScrName.BackColor = Color.Yellow

如果TimX = 2那么txbScrName.BackColor = Color.White

如果TimX = 3那么txbScrName.BackColor = Color.Yellow

如果TimX = 4然后txbScrName.BackColor = Color.White

对于TimCtr = 0到200000

下一个''timx

下一个''timctr

txbScrName.BackColor = Color.White

End Sub


其他人做过类似的事吗?我想我尝试了一段时间的定时器控制

也没有成功...


问候,


布鲁斯

解决方案

先生。 B,


虽然这不是你想要的,但它与我所做的相似。

我只是把这个样本快速地放在一起一个表单,TextBox(TextBox1)和一个

按钮(Button1)。

很可能是更好/更安全的方式,但我相信它更好

比你想做的还要多。


''--------------------- ---------------------------------------

''威尔Flash背景黄色任何支持BackColor的控件

属性

''注意:此示例中没有实现错误检查。

Private Sub FlashBackground(ByVal控件As System.Windows.Forms.Control)

Dim origColor As System.Drawing.Color


''存储原始背景颜色控制所以我们可以恢复它

origColor = control.BackColor


带控件

''将BackColor设置为黄色

.BackColor =系统tem.Drawing.Color.Yellow

''告诉控件使用新设置重绘

。更新()

''等待很短的时间。如果我们不这样做,那么更新

''会如此之快,我们不会看到它。

''仅供参考,这将暂停整个当前的GUI线程,在这个

''的情况下就是我们想要的。

Threading.Thread.Sleep(100)

''恢复原始BackColor

.BackColor = origColor

''告诉控件使用新设置重绘

.Update()

结束


End Sub


Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As

System.EventArgs)处理Button1.Click

FlashBackground(TextBox1)

结束子


'' - -------------------------------------------------- ---------


Gerald


" Mr。 B" < US ** @ NoWhere.com>在消息中写道

news:9l ******************************** @ 4ax.com ...

虽然起初这可能看起来很简单,但它已经困扰了我一段时间......

我想要的是拥有背景色类似于TextBox的东西
从(比如)白色变成黄色变成白色变成黄色再变回白色
大约1秒钟左右。

这是创造当用户在4个单选按钮中的一个上单击
(这会更改TextBox中的文本)时,类似于''flash''(或Pulse)。所以在其他方面,要引起用户的注意,文本已经改变了。弹出框是一种痛苦,所以我不想去那里(即:他们可能会点击几个RadioButtons)。

我已经尝试过如下的简单测试这个。但你确实没有看到任何背景变化。很明显,我遗漏了一些基本的东西:

Private Sub rbASME1_CheckedChanged(ByVal sender As System.Object,_
ByVal e As System.EventArgs)处理rbASME1。 CheckedChanged
pltPrefx =" a"
txbScrName.Text = pltPrefx& pltTitle& pltType
Dim TimCtr,TimX As Integer
TimX = 1到4
如果TimX = 1那么txbScrName.BackColor = Color.Yellow
如果TimX = 2那么txbScrName.BackColor = Color.White
如果TimX = 3那么txbScrName.BackColor = Color.Yellow
如果TimX = 4那么txbScrName.BackColor = Color.White
对于TimCtr = 0到200000
下一步''timx
下一个''timctr
txbScrName.BackColor = Color.White
End Sub

其他人做过类似的事吗?我想我尝试了一段时间的定时器控制也没有成功......

问候,

布鲁斯



拍摄......我想到的一件事就是你可能需要一个

Application.DoEvents()来重新绘制文本框....如果没有't $ / b
第一次工作,在

System.Threading.Thread.Sleep(1000)行之前加上这一行:


Application.DoEvents()

-

HTH,

- Tom Spink,überGeek


有一天VBC.EXE说,OrElse是什么?


请回复新闻组,

所以所有人都可以受益

先生。 B" < US ** @ NoWhere.com>在消息中写道

news:9l ******************************** @ 4ax.com ...

虽然起初这可能看起来很简单,但它一直困扰着我一个
而... ...
我想做的是拥有背景色类似
TextBox的东西,从(比方说)白色变为黄色变为白色变为黄色,然后在大约1秒左右回到
白色。

这是创建当用户
点击4个单选按钮中的1个(更改TextBox中的文本)时,类似于''flash''(或Pulse)。所以用
换句话说,要引起用户的注意,文本已经改变了。弹出框
是一种痛苦,所以我不想去那里(即:他们可能会点击几个
RadioButtons)。
我已经尝试过如下的简单测试这个。但你
不会''看到''任何背景变化发生。很明显,我错过了
这里的基本内容:

Private Sub rbASME1_CheckedChanged(ByVal sender As System.Object,_
ByVal e As System.EventArgs)处理rbASME1。 CheckedChanged
pltPrefx =" a"
txbScrName.Text = pltPrefx& pltTitle& pltType
Dim TimCtr,TimX As Integer
TimX = 1到4
如果TimX = 1那么txbScrName.BackColor = Color.Yellow
如果TimX = 2那么txbScrName.BackColor = Color.White
如果TimX = 3那么txbScrName.BackColor = Color.Yellow
如果TimX = 4那么txbScrName.BackColor = Color.White
对于TimCtr = 0到200000
下一步''timx
下一个''timctr
txbScrName.BackColor = Color.White
End Sub

其他人做过类似的事吗?我想我尝试了一个
的定时器控制,但也没有成功...

问候,

布鲁斯



首先,您可以使用Mod语句缩小代码,

其次,不要使用循环暂停(如果有人有186?或者怎么办? a / $
100万亿86?)

Private Sub rbASME1_CheckedChanged(ByVal sender As System.Object,_
ByVal e As System.EventArgs)处理rbASME1。 CheckedChanged
pltPrefx =" a"
txbScrName.Text = pltPrefx& pltTitle& pltType
Dim TimCtr,TimX As Integer
TimX = 1到4
如果TimX = 1那么txbScrName.BackColor = Color.Yellow
如果TimX = 2那么txbScrName.BackColor = Color.White
如果TimX = 3那么txbScrName.BackColor = Color.Yellow
如果TimX = 4那么txbScrName.BackColor = Color.White
对于TimCtr = 0到200000
下一步''timx
下一个''timctr
txbScrName.BackColor = Color.White
结束次级


''///

对于TimX = 1到4

txtScrName.BackColor = CType(IIf((TimX Mod 2)= 0,Color.White,

Color.Yellow), System.Drawing.Color)

System.Threading.Thread.Sleep(1000)

下一页


txtScrName.BackColor =颜色。白色

''///


未经测试,但试一试:)


-

HTH,

- Tom Spink,überGeek


VBC.EXE说的那天,OrElse是什么?" ;


请回复新闻组,

所以所有人都可以受益

" Mr。 B" < US ** @ NoWhere.com>在消息中写道

news:9l ******************************** @ 4ax.com ...虽然起初这可能看起来很简单,但是它一直困扰着我一个
而... ...
我想做的是让背景颜色像
TextBox从(比方说)白色变为黄色变为白色变为黄色然后再回到
白色大约1秒钟左右。

这是为了创造类似''闪光''的东西用户
点击4个单选按钮中的1个(用于更改TextBox中的文本)时(或脉冲)。所以用
换句话说,要引起用户的注意,文本已经改变了。弹出框
是一种痛苦,所以我不想去那里(即:他们可能会点击几个
RadioButtons)。
我已经尝试过如下的简单测试这个。但你
不会''看到''任何背景变化发生。很明显,我错过了
这里的基本内容:

Private Sub rbASME1_CheckedChanged(ByVal sender As System.Object,_
ByVal e As System.EventArgs)处理rbASME1。 CheckedChanged
pltPrefx =" a"
txbScrName.Text = pltPrefx& pltTitle& pltType
Dim TimCtr,TimX As Integer
TimX = 1到4
如果TimX = 1那么txbScrName.BackColor = Color.Yellow
如果TimX = 2那么txbScrName.BackColor = Color.White
如果TimX = 3那么txbScrName.BackColor = Color.Yellow
如果TimX = 4那么txbScrName.BackColor = Color.White
对于TimCtr = 0到200000
下一步''timx
下一个''timctr
txbScrName.BackColor = Color.White
End Sub

其他人做过类似的事吗?我想我尝试了一个
的定时器控制,但也没有成功...

问候,

布鲁斯



While at first this may seem a simple tast, it has plagued me for a while...

What I want to do is to have the background colour of something like a TextBox
to change from (say) White to Yellow to White to Yellow and then back to White
in about 1 second or so.

This is to create something like a ''flash'' (or a Pulse) for when a User clicks
on 1 of 4 Radio Buttons (which change the Text in the TextBox). So in other
words, to get the User''s attention that the Text has Changed. Popup boxes are
a pain, so I don''t want to go there (ie: they may click several RadioButtons).

I''ve tried something simple like the following to Test this out. But you do
not ''see'' any background change happening. So obvious, I''m missing something
fundamental here:

Private Sub rbASME1_CheckedChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles rbASME1.CheckedChanged
pltPrefx = "a"
txbScrName.Text = pltPrefx & pltTitle & pltType
Dim TimCtr, TimX As Integer
For TimX = 1 To 4
If TimX = 1 Then txbScrName.BackColor = Color.Yellow
If TimX = 2 Then txbScrName.BackColor = Color.White
If TimX = 3 Then txbScrName.BackColor = Color.Yellow
If TimX = 4 Then txbScrName.BackColor = Color.White
For TimCtr = 0 To 200000
Next ''timx
Next '' timctr
txbScrName.BackColor = Color.White
End Sub

Anyone else done something similar? I think I tried a Timer Control a while
back also without success...

Regards,

Bruce

解决方案

Mr. B,

While this isn''t exactly what you want, it is similar to something I have done.
I just threw this sample together quickly with a Form, TextBox (TextBox1), and a
Button (Button1).
There very well may be a better / safer way, but I am confident it is better
than what you are trying to do.

''------------------------------------------------------------
''Will Flash the background Yellow of any control that supports the BackColor
property
''Note: No error checking implemented in this sample.
Private Sub FlashBackground(ByVal control As System.Windows.Forms.Control)
Dim origColor As System.Drawing.Color

''Store the original Background color of the control so we can restore it
origColor = control.BackColor

With control
''Set the BackColor to Yellow
.BackColor = System.Drawing.Color.Yellow
''Tell the control to redraw with the new setting
.Update()
''Wait for a short time. If we don''t do this, then the update
'' would be so quick we wouldn''t see it.
''FYI, this will suspend the whole current GUI thread, which in this
'' case is what we want.
Threading.Thread.Sleep(100)
''Restore the original BackColor
.BackColor = origColor
''Tell the control to redraw with the new setting
.Update()
End With

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
FlashBackground(TextBox1)
End Sub

''------------------------------------------------------------

Gerald

"Mr. B" <Us**@NoWhere.com> wrote in message
news:9l********************************@4ax.com...

While at first this may seem a simple tast, it has plagued me for a while...

What I want to do is to have the background colour of something like a TextBox
to change from (say) White to Yellow to White to Yellow and then back to White
in about 1 second or so.

This is to create something like a ''flash'' (or a Pulse) for when a User clicks
on 1 of 4 Radio Buttons (which change the Text in the TextBox). So in other
words, to get the User''s attention that the Text has Changed. Popup boxes are
a pain, so I don''t want to go there (ie: they may click several RadioButtons).

I''ve tried something simple like the following to Test this out. But you do
not ''see'' any background change happening. So obvious, I''m missing something
fundamental here:

Private Sub rbASME1_CheckedChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles rbASME1.CheckedChanged
pltPrefx = "a"
txbScrName.Text = pltPrefx & pltTitle & pltType
Dim TimCtr, TimX As Integer
For TimX = 1 To 4
If TimX = 1 Then txbScrName.BackColor = Color.Yellow
If TimX = 2 Then txbScrName.BackColor = Color.White
If TimX = 3 Then txbScrName.BackColor = Color.Yellow
If TimX = 4 Then txbScrName.BackColor = Color.White
For TimCtr = 0 To 200000
Next ''timx
Next '' timctr
txbScrName.BackColor = Color.White
End Sub

Anyone else done something similar? I think I tried a Timer Control a while
back also without success...

Regards,

Bruce



Shoot... something that just crossed my mind is that you may need an
Application.DoEvents() in there to repaint the textbox.... If it doesn''t
work first time, add this line before the
System.Threading.Thread.Sleep(1000) line:

Application.DoEvents()

--
HTH,
-- Tom Spink, über Geek

Woe be the day VBC.EXE says, "OrElse what?"

Please respond to the newsgroup,
so all can benefit
"Mr. B" <Us**@NoWhere.com> wrote in message
news:9l********************************@4ax.com...

While at first this may seem a simple tast, it has plagued me for a while...
What I want to do is to have the background colour of something like a TextBox to change from (say) White to Yellow to White to Yellow and then back to White in about 1 second or so.

This is to create something like a ''flash'' (or a Pulse) for when a User clicks on 1 of 4 Radio Buttons (which change the Text in the TextBox). So in other words, to get the User''s attention that the Text has Changed. Popup boxes are a pain, so I don''t want to go there (ie: they may click several RadioButtons).
I''ve tried something simple like the following to Test this out. But you do not ''see'' any background change happening. So obvious, I''m missing something fundamental here:

Private Sub rbASME1_CheckedChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles rbASME1.CheckedChanged
pltPrefx = "a"
txbScrName.Text = pltPrefx & pltTitle & pltType
Dim TimCtr, TimX As Integer
For TimX = 1 To 4
If TimX = 1 Then txbScrName.BackColor = Color.Yellow
If TimX = 2 Then txbScrName.BackColor = Color.White
If TimX = 3 Then txbScrName.BackColor = Color.Yellow
If TimX = 4 Then txbScrName.BackColor = Color.White
For TimCtr = 0 To 200000
Next ''timx
Next '' timctr
txbScrName.BackColor = Color.White
End Sub

Anyone else done something similar? I think I tried a Timer Control a while back also without success...

Regards,

Bruce



First off, you can make the code smaller by using the Mod statement,
Secondly, don''t use loops for pauses (what if someone has a 186? or a
1millionzillion86?)

Private Sub rbASME1_CheckedChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles rbASME1.CheckedChanged
pltPrefx = "a"
txbScrName.Text = pltPrefx & pltTitle & pltType
Dim TimCtr, TimX As Integer
For TimX = 1 To 4
If TimX = 1 Then txbScrName.BackColor = Color.Yellow
If TimX = 2 Then txbScrName.BackColor = Color.White
If TimX = 3 Then txbScrName.BackColor = Color.Yellow
If TimX = 4 Then txbScrName.BackColor = Color.White
For TimCtr = 0 To 200000
Next ''timx
Next '' timctr
txbScrName.BackColor = Color.White
End Sub
'' ///
For TimX = 1 To 4
txtScrName.BackColor = CType(IIf((TimX Mod 2) = 0, Color.White,
Color.Yellow), System.Drawing.Color)
System.Threading.Thread.Sleep(1000)
Next

txtScrName.BackColor = Color.White
'' ///

Untested, but give that a try :)

--
HTH,
-- Tom Spink, über Geek

Woe be the day VBC.EXE says, "OrElse what?"

Please respond to the newsgroup,
so all can benefit
"Mr. B" <Us**@NoWhere.com> wrote in message
news:9l********************************@4ax.com... While at first this may seem a simple tast, it has plagued me for a while...
What I want to do is to have the background colour of something like a TextBox to change from (say) White to Yellow to White to Yellow and then back to White in about 1 second or so.

This is to create something like a ''flash'' (or a Pulse) for when a User clicks on 1 of 4 Radio Buttons (which change the Text in the TextBox). So in other words, to get the User''s attention that the Text has Changed. Popup boxes are a pain, so I don''t want to go there (ie: they may click several RadioButtons).
I''ve tried something simple like the following to Test this out. But you do not ''see'' any background change happening. So obvious, I''m missing something fundamental here:

Private Sub rbASME1_CheckedChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles rbASME1.CheckedChanged
pltPrefx = "a"
txbScrName.Text = pltPrefx & pltTitle & pltType
Dim TimCtr, TimX As Integer
For TimX = 1 To 4
If TimX = 1 Then txbScrName.BackColor = Color.Yellow
If TimX = 2 Then txbScrName.BackColor = Color.White
If TimX = 3 Then txbScrName.BackColor = Color.Yellow
If TimX = 4 Then txbScrName.BackColor = Color.White
For TimCtr = 0 To 200000
Next ''timx
Next '' timctr
txbScrName.BackColor = Color.White
End Sub

Anyone else done something similar? I think I tried a Timer Control a while back also without success...

Regards,

Bruce



这篇关于如何:彩色Flash TextBox背景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆