vb.net动态创建复选框 [英] vb.net dynamicly create checkboxes

查看:155
本文介绍了vb.net动态创建复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想知道如何在表单上创建动态复选框,当我不知道我需要多少箱子。问题是,我不知道如何DIM多个对象。这是我创建一个复选框的代码

  Dim checkBox As New CheckBox()

Form1.Controls .Add(checkBox)
checkBox.Location = New Point(10,10)
checkBox.Text =testing
checkBox.Checked = True
checkBox.Size = (100,20)

它工作正常,但我无法添加多个复选框,这样做:

  Dim checkBox作为新的CheckBox()
Dim checkBox2作为新的CheckBox()

Form1.Controls.Add(checkBox)
checkBox.Location = New Point(10,10)
checkBox.Text =testing
checkBox.Checked = True
checkBox.Size = New Size(100,20)

Form1.Controls.Add(checkBox2)
checkBox2.Location = New Point(40,10)
checkBox2.Text =testing2
checkBox2.Checked = True
checkBox2.Size = New Size(100,20)

等...



有没有办法变暗多个复选框,而不是为每个checkBoxe写多个dim语句? p>


对不起也许我应该说这个..



像这样:

  dim checkBox()作为复选框

do until i = 50
Form1.Controls.Add(checkBox(i))
checkBox(i).Location = New Point(10,10)
checkBox(i).Text =testing& i
checkBox(i).Checked = True
checkBox(i).Size = New Size(100,20)
i + = 1
loop





David

解决方案

似乎只有在 CheckBox 实例之间不同且不计算的项目是文本。如果是这样,那么你可以使用下面的代码添加一组 CheckBox 实例基于 String 的。

  Dim data as String()= New String(){testing,testing2} 
Dim offset = 10
对于每个cur数据
Dim checkBox = new CheckBox()
Form1.Controls.Add(checkBox)
checkBox.Location = New Point(offset,10)
checkBox.Text = cur
checkBox.Checked = True
checkBox.Size = New Size(100,20)
offset = offset + 30
Next


Hey all, i am trying to figure out how to go about creating dynamic checkboxes on my form when i do not know axacctly how many boxes i will need.

The problem is that i do not know how to DIM more than one object. This is my code for creating one checkbox

Dim checkBox As New CheckBox()

Form1.Controls.Add(checkBox)
checkBox.Location = New Point(10, 10)
checkBox.Text = "testing"
checkBox.Checked = True
checkBox.Size = New Size(100, 20)

It works just fine but i am unable to add more than one checkBox without having to do this:

Dim checkBox As New CheckBox()
Dim checkBox2 As New CheckBox()

Form1.Controls.Add(checkBox)
checkBox.Location = New Point(10, 10)
checkBox.Text = "testing"
checkBox.Checked = True
checkBox.Size = New Size(100, 20)

Form1.Controls.Add(checkBox2)
checkBox2.Location = New Point(40, 10)
checkBox2.Text = "testing2"
checkBox2.Checked = True
checkBox2.Size = New Size(100, 20)

etc...

Is there a way to dim more than 1 checkbox instead of having to write multiple dim statements for each checkBoxe?

Sorry maybe i should say this..

I'm looking to do something like this:

 dim checkBox() as CheckBox

 do until i = 50
    Form1.Controls.Add(checkBox(i))
    checkBox(i).Location = New Point(10, 10)
    checkBox(i).Text = "testing " & i
    checkBox(i).Checked = True
    checkBox(i).Size = New Size(100, 20)
    i += 1
 loop

David

解决方案

It seems like the only items that are different and not calculated between the CheckBox instances is the text. If so then you could just use the following code to add a set of CheckBox instances based off of a list of String's.

Dim data as String() = New String() { "testing", "testing2" }
Dim offset = 10
For Each cur in data 
  Dim checkBox = new CheckBox()
  Form1.Controls.Add(checkBox)
  checkBox.Location = New Point(offset, 10)
  checkBox.Text = cur
  checkBox.Checked = True
  checkBox.Size = New Size(100, 20)
  offset = offset + 30
Next

这篇关于vb.net动态创建复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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