通过复选框更改字节值 [英] change a value of byte by check box

查看:86
本文介绍了通过复选框更改字节值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi
我有4个复选框(如复选框1复选框4),如果我选择每个复选框,则字节(驱动程序)会更改其值。例如,如果我选中复选框1,则字节值将更改为0x01。现在,如果我选择复选框2,这个字节变为0x03。(这只是一个例子)

我该怎么办?

hi i have 4 check boxes (as check box1 to check box4), if i choose each of them, a byte(driver) changes its value. for example, if i select check box1, the value of byte changes to 0x01. now if i select check box2, this byte changes to 0x03.(it's just an example)
what shall i do?

推荐答案

检查盒子是独立检查的。它们足以实现比特价值,而不是相应的价值选择。为此,您应该使用单选按钮。



其余部分取决于您使用的UI库/框架或应用程序类型。您应该在涉及UI时立即标记此信息。一旦你说CheckBox或RadioButton,问题是:哪一个?这些简单名称下有不同的类。你需要显示完整的类型名称,才能提出问题。



一个基本的想法是:你可以在控件的标签上存储你需要的值,并检索选中此标记(类型转换为字节)。



-SA
Check boxes are checked independently. They are adequate to bit value, not to consequential selection of values. For this purpose, you should use radio buttons.

The rest of it depends on the UI library/framework you are using or application type. You should tag this information as soon as UI is concerned. Once you say "CheckBox" or "RadioButton", the question is: which one? There are different classes under these simple names. You need to show full type names, to ask a question.

One basic idea is this: you can store values you need on the tag of a control, and retrieve this tag (with type cast to byte) when it is checked.

—SA


试试这个:
byte value = (byte)
(
    (checkBox1.Checked ? 1 : 0)
    + (checkBox2.Checked ? 2 : 0)
    + (checkBox3.Checked ? 4 : 0)
    + (checkBox4.Checked ? 8 : 0)
);


这篇关于通过复选框更改字节值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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