问题描述
新手程序员在这里.我有一个试图开发的小型发票应用程序,但我遇到了麻烦.
根据工作中有多少技术人员,需要通过复选框在组中启用/禁用多个文本框.
例如,每项技术将有单独的费用(机票,酒店,汽车,汽油等)以及不同的工作时间(分为正常,加班,旅行,周末等).
这个想法是默认情况下启用第一列(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
推荐答案
这篇关于文本框数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!