需要使用复选框的帮助
我对我的基本项目有几个问题,
如果我有一个复选框,当它被选中时,它将进入一个显示价格的文本框,当我取消选中它时,我的价格仍然显示在该文本框中,我怎样才能当我取消选中该框时使其消失?
Dim total As Double
If rb_s1.Checked = True Then
total += 650.0
txt_1.Text = total
这就是我的代码。
我有很多组合框,当我选中/取消选中它们时,如何使它们全部加起来。
i have a couple of questions about my basic project
if i have a check box and when its checked, it is going to a text box which is displaying the price, when i uncheck it my price still says in that text box, how can i make it dissapear as i uncheck the box?
Dim total As Double
If rb_s1.Checked = True Then
total += 650.0
txt_1.Text = total
thats my code.
and i have many combo boxes, how can i make them all add up as i check/uncheck them.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我会将此功能添加到
CheckBox_Changed
事件处理程序中。这样您就可以判断它是未选中
还是已选中
,并从价格中添加或减去该值。I would add this functionality into the
CheckBox_Changed
event handler. This way you can tell if it isunchecked
orchecked
and add or subtract the value from price.您必须使用复选框的 Checked_Changed 事件。
You have to use Checked_Changed event of checkbox.
要在复选框状态更改时更改显示的文本,您需要处理 CheckedChanged 事件。在 Visual Studio 中,当窗体/控件处于 Desginer 模式时,您可以选择复选框控件,然后在“属性”窗口中选择“事件”选项卡(带有小闪电图标的选项卡),然后双击要存根的 CheckChanged 事件在事件处理程序方法中并将事件附加到处理程序。
ETA:我重读了这篇文章,我不确定我是否清楚。当我提到在事件处理程序中存根并将事件附加到处理程序时,我的意思是在设计器中双击事件的路线将为您完成此操作。
顺便说一句,听起来您希望文本仅是已检查项目的总和,因此从体系结构的角度来看,我建议创建一个方法来确定总和,并让所有复选框检查事件调用该方法而不是试图让事件处理程序方法本身直接做太多事情(也许您已经很清楚了)。
所以你可能会这样做:
To get your displayed text to change when the state of your checkbox changes, you'll need to handle the CheckedChanged event. In Visual Studio while in Desginer mode for your form/control, you can select the check box control, and then in the Properties window, select the Events tab (the one with the little lightingbolt icon), and double click the CheckChanged event to stub in an event handler method AND attach the event to the handler.
ETA: I re-reading this, I'm not sure how clear I was. When I mentioned stubbing in the event handler and attaching the event to the handler, I meant that going the route of double-clicking the event in the designer will do this for you.
As an aside, it sounds like you want the text to be a sum of only the checked items, so from an architechtueral sense, I would recommend creating a single method to determine the sum, and have all check-box check events invoke that method rather than trying to make the event handler method itself do too much directly (maybe that was already clear to you).
So you might do something like this: