文本框控制背面颜色 [英] Text box control back color
问题描述
早上好我有问题可以帮助我。我在Vb.net的vs2013中创建了一个表单。表格的目的是一个工作人员轮换一个月,在3班制的8小时制.Person创建rota使用每个员工的文本框背面颜色显示工作人员所在的班次。 IE ..红色背面颜色是早上6点到下午2点,绿色是下午2点到晚上10点等。颜色是通过点击事件改变每次点击白天变为下一个颜色。下面的代码适用于将文本框更改为所需的输出。我的问题是.....有没有办法,而不是将下面的代码复制并粘贴到每个文本框单击事件,并编辑到文本名称到所需的文本框是否可以在类或过程中编写代码onece这将涵盖所有文本框,从而节省了为所有50个文本框编写代码的时间????
感谢您提前输入/建议
我的尝试:
Dim Count As Integer = 5
**代码下面是一个文本框点击事件
私有子txtM16_Click(发件人为对象,e为EventArgs)处理txtM11。点击
计数=计数 - 1
如果Count = 4那么
txtM16.BackColor = Color.Red
ElseIf Count = 3然后
txtM16.BackColor = Color.Green
ElseIf Count = 2然后
txtM16.BackColor = Color.MediumPurple
ElseIf Count = 1然后
txtM16.BackColor = Color.Blue
ElseIf Count = 0然后
txtM16.BackColor = Color.White
Count = 5
结束如果
结束Sub
Good morning i have a problem can anyone help me.I have created a form in vs2013 in Vb.net. The purpose of the form is a staff rota for a month, on a 3 shift system of 8 Hours.Person creating rota uses the textbox back color of each employee to display the shift the staff member is on. IE .. Red back color is 6am-2pm, green is 2pm-10pm etc. The color is change via the click event each click on day shift is changed to the next color. The code below works well for changing the text boxes to the required output. My question is ..... Is there a way of instead of copy and paste the code below to each text box click event and editing to the text name to the required text box is it possible to write code onece in a class or procedure that will cover all text boxes thus saving time writing code for all 50 plus text boxes????
Thank you for anyone input/advice in advance
What I have tried:
Dim Count As Integer = 5
**Code Below is of one text box click event
Private Sub txtM16_Click(sender As Object, e As EventArgs) Handles txtM11.Click
Count = Count - 1
If Count = 4 Then
txtM16.BackColor = Color.Red
ElseIf Count = 3 Then
txtM16.BackColor = Color.Green
ElseIf Count = 2 Then
txtM16.BackColor = Color.MediumPurple
ElseIf Count = 1 Then
txtM16.BackColor = Color.Blue
ElseIf Count = 0 Then
txtM16.BackColor = Color.White
Count = 5
End If
End Sub
推荐答案
是:s ender
参数包含引发事件的源控件。
所以你需要做的就是设置所有Textboxes使用相同的处理程序并使用参数来控制哪个框:
Yes: thesender
parameter contains the source control that raised the event.
So all you need to do is set all the Textboxes to use the same handler and use the parameter to control which box:
Private Sub AllTextBoxes_Click(sender As Object, e As EventArgs) Handles txtM11.Click
...
Count = Count - 1
Dim tb As TextBox = TryCast(sender, TextBox)
If tb IsNot Nothing Then
If Count = 4 Then
tb.BackColor = Color.Red
ElseIf Count = 3 Then
tb.BackColor = Color.Green
ElseIf Count = 2 Then
tb.BackColor = Color.MediumPurple
ElseIf Count = 1 Then
tb.BackColor = Color.Blue
ElseIf Count = 0 Then
tb.BackColor = Color.White
Count = 5
End If
End If
这篇关于文本框控制背面颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!