文本框数组 [英] textbox array

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

问题描述



新手程序员在这里.我有一个试图开发的小型发票应用程序,但我遇到了麻烦.
根据工作中有多少技术人员,需要通过复选框在组中启用/禁用多个文本框.

例如,每项技术将有单独的费用(机票,酒店,汽车,汽油等)以及不同的工作时间(分为正常,加班,旅行,周末等).

这个想法是默认情况下启用第一列(tech1),并在加载时禁用其他所有内容.然后,基于复选框为每个其他技术启用该列.

每个技术都有大约20个要启用/禁用的字段,这意味着很多代码,如果我需要编写一行代码来启用/禁用每个框的话.我敢肯定,必须有一种简便"的方法来用更少的代码来做到这一点.但是正如开头所说,我是新手.

这是我发现的方法示例.

Hi,

Newbie programmer here. I have a small invoicing application I''m trying to build, but I''m stuck.
There are multiple textboxes that need to be enabled/ disabled in groups through checkboxes, based on how many techs are on the job.

For example, each tech will have separate expenses (airfare, hotel, car, gas, etc.) as well as different working hours (separated into regular, overtime, travel, weekend, etc.).

The idea is to have the first column (tech1) enabled by default, and everything else disabled on load. Then based on checkboxes enable the column for each additional tech.

Each tech has about 20 fields to be enabled/disabled, which means a LOT of code if I need to write a line of code to enable/disable each box. I''m sure there has to be an "easy" way to do this with much less code. But as my opening says, I''m a newbie.

Here is an example of the way I found to do this.

Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' first set enabled rest disabled on load
        TextBox3.Enabled = False
        TextBox4.Enabled = False
        TextBox5.Enabled = False
        TextBox6.Enabled = False
        CheckBox2.Enabled = False
    End Sub
    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged

        'enable second set with checkbox1
        If CheckBox1.Checked = True Then
            TextBox3.Enabled = True
            TextBox4.Enabled = True
            CheckBox2.Enabled = True
        Else
            TextBox3.Enabled = False
            TextBox4.Enabled = False
            CheckBox2.Enabled = False
            TextBox5.Enabled = False
            TextBox6.Enabled = False
        End If
        'in case checkbox 1 is unintentionally unchecked, then rechecked
        If CheckBox1.Checked And CheckBox2.Checked = True Then
            TextBox5.Enabled = True
            TextBox6.Enabled = True
        End If
    End Sub

    Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
        'enable third set with checkbox2
        If CheckBox2.Checked = True Then
            TextBox5.Enabled = True
            TextBox6.Enabled = True
        Else
            TextBox5.Enabled = False
            TextBox6.Enabled = False
        End If

    End Sub
End Class

推荐答案

尝试将每组文本框放入其自己的组框中,然后启用/禁用该组框.

如果这不起作用,请将文本框放入组框,然后在需要启用/禁用给定groupbiox中的文本框时,只需遍历该组框的子控件即可.
Try putting each group of textboxes into their own groupbox, and enable/disable the groupbox.

If that doesn''t work, put the textboxes into a groupbox, and then when you need to enable/disable the textboxes in a given groupbiox, just iterate through the child controls of the groupbox.


作为John答案的一种可能替代方法,您可以考虑使用 VB中的DataRepeater控件PowerPacks 3.0 [ ^ ] .这样一来,您就可以拥有较为整洁的表格,因为仅当需要其他技术时,这些输入控件才会出现.
As a possible alternative to John''s answer, you might consider using the DataRepeater control from VB PowerPacks 3.0[^]. This would allow you to have a less cluttered form as the input controls for additional techs would only appear when they are needed.


我使用了分组框.它运作良好,而且消除了每列的标签.

那很完美!!谢谢:-D
I used the group box. It worked well, plus it eliminates a label for each column.

That''s perfect!! thanks :-D


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

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