从复选框中显示的值构建数组? [英] Building an array from a values displayed in checkboxes?

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

问题描述

大家好,


我是编程的初学者,我正在构建一个简单的程序,用户可以从中订购冷冻酸奶。该程序具有容器,浇头,香料等类型,并且将产生"收据"。所选的所有内容及其价格,点击"订购"后


我目前有许多复选框列出每个配料,分组在一个集装箱框中。我想要它,以便用户选择的每一个顶部,它最终将作为收据的一部分在屏幕上列出。我应该怎么做呢?如果我错误的是
,我应该从这些复选框中构建一个数组,然后使用"for循环"以某种方式显示该数组?


有人可以给出我知道我应该从哪里开始,或者如何制作我想要的东西?



谢谢,


贾斯汀

解决方案

您好Justim13601,


您说要添加许多复选框在GroupBox中控制,并循环GroupBox并将复选框复选到数组中,对不对?如果是,您可以查看以下代码:


我在表单中添加一个GroupBox和八个复选框。

私人清单< CheckBox> list = new List< CheckBox>(); 
private void button2_Click(object sender,EventArgs e)
{
foreach(checkBox c in groupBox1.Controls)
{
if(c.Checked == true)
{
list.Add(c);
}
}

for(Int32 i = 0; i< list.Count; i ++)
{
Console.WriteLine(" {检查0},文本为{1}",list [i] .Name,list [i] .Text);
}
}

最好的问候,


Cherry



Hi all,

I'm a beginner in programming and am just building a simple program where the user can order frozen yogurt from. The program has types of containers, toppings, flavours, etc., and would generate a "receipt" of everything selected, and their price, upon clicking "order".

I currently have many checkboxes listing each toppings, grouped in a group container box. I want it so that for every topping the user selects, it will eventually list it on the screen as part of a receipt. How should I go about doing that? If I'm not mistaken, I should build an array from those checkboxes, and then display that array somehow with the use of "for loops"?

Can someone give me an idea of where I should start or how I can make what I want happen?

Thanks,

Justin

解决方案

Hi Justim13601,

You said that you want to add many checkbox controls in GroupBox, and loop GroupBox and get the checked checkbox into array, am I right? If yes, you can take a look the following code:

I add one GroupBox and eight checkbox in the Form.

  private List<CheckBox> list=new List<CheckBox>();
        private void button2_Click(object sender, EventArgs e)
        {
            foreach(CheckBox c in groupBox1.Controls)
            {
                if(c.Checked==true)
                {
                    list.Add(c);
                }
            }

            for(Int32 i=0;i<list.Count;i++)
            {
                Console.WriteLine("The {0} is checked and text is {1}",list[i].Name,list[i].Text);
            }
        }

Best Regards,

Cherry


这篇关于从复选框中显示的值构建数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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