设置文本框数组的背景色 [英] Setting the background colour for a textbox array

查看:62
本文介绍了设置文本框数组的背景色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为数组中的文本框设置背景色.所有其他属性均正常运行,但背景颜色正常.我在Windows XP SP3上使用VB.Net 2008.要使此属性正常工作,我还要做些其他事情吗?

以下是我正在使用的代码的片段.

提前谢谢.


I am trying to set the background colour for a textbox in an array. All other properties are working properly, but the background colour. I am using VB.Net 2008 on Windows XP SP3. Is there something more I have to do get this property to work?

Below is a snippet of the code I am using.

Thanks in advance.


ReDim txtBoxNo(20)
       txtBoxNo(0) = Me.txtNum0
       txtBoxNo(1) = Me.txtNum1
           ...
       ...
       txtBoxNo(18) = Me.txtNum18
       txtBoxNo(19) = Me.txtNum19
       '
       Try
           For iCount = 0 To 19
               With txtBoxNo(iCount)
                   .Enabled = True
                   .BackColor = Color.LightBlue
                   .ForeColor = Red
                   .Enabled = False
                   .Text = CStr(iCount + 1)
               End With
           Next
       Catch ex As Exception
           MsgBox(ex.Message)
           End
       End Try

推荐答案

这将不起作用,因为您没有定义数组的类型.如果您使用这样的Generic集合,这将更容易工作:
That''s not going to work because you don''t define the type of the array. This would work MUCH easier if you used a Generic collection like this:
Dim myTextBoxes As New List(Of TextBox)
myTextBoxes.Add(txtNum0)
myTextBoxes.Add(txtNum1)
myTextBoxes.Add(txtNum2)
...
'' BTW: You don''t have to put "Me" in front of everything...
...
'' and you don''t need the exception handling code
...
For i As Integer = 0 To myTextBoxes.Count - 1
    With myTextBoxes(i)
        '' I don''t know why you''re setting Enabled True and False.
        '' That doesn''t do anything in this code.
        .BackColor = Color.LightBlue
        .ForeColor = Red
        .Text = (i + 1).ToString
    End With
Next


这篇关于设置文本框数组的背景色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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