本文介绍了如何重绘动态添加的控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

这里我从checkedListBox中选择项目并通过检查将它们保存在ListBox中,之后有一个按钮为>>它存储列表框中的已检查项目,我根据列表框的项目计数生成文本框。所有操作都在>>上进行按钮的点击事件。





以下是代码:



  foreach 对象项目  checkedListBox1.CheckedItems)
{
listBox1.Items.Add(items);

}



  int  camCount = listBox1 .Items.Count; 
arrCam = new TextBox [camCount];
int dist = 0 ;
for int i = 0 ; i < camCount; i ++)
{
TextBox tx = new TextBox();
arrCam [i] = tx;
}



  foreach (TextBox fortx1   arrCam)
{
fortx1.Location = new Point( 448 13 + dist);
groupBox8.Controls.Add(fortx1);
dist + = 25 ;

}





这里问题是当我检查checkedlistbox中的所有项目时,项目转到列表框和然后根据列表框的项目计数生成文本框。到这里它工作正常,现在当我取消选中checkedlistbox中的任何项目总数。文本框也应该改变,但是那些文本框没有重新绘制,只有以前绘制的文本框保留在窗体中。



有人可以帮我解决我出错的地方或者在哪里缺少一段代码?

解决方案


Hello,
Here i am selecting the items from checkedListBox and saving them in ListBox by checking and after that there is a button as ">>" which stores checked items in listbox and I am generating the textboxes according to the item count of list box. all operations are carried on ">>" button's click event.


Below is code:

foreach (Object items in checkedListBox1.CheckedItems)
            {
                listBox1.Items.Add(items);

            }


int camCount = listBox1.Items.Count;
            arrCam = new TextBox[camCount];
            int dist = 0;
            for (int i = 0; i < camCount; i++)
            {
                TextBox tx = new TextBox();
                arrCam[i] = tx;
            }


foreach (TextBox fortx1 in arrCam)
           {
               fortx1.Location = new Point(448, 13 + dist);
               groupBox8.Controls.Add(fortx1);
               dist += 25;

           }



here the problem is when i check all the items in checkedlistbox,items go to listbox and then generate the textboxes according to the listbox's item count.Till here it working fine,now when i uncheck any item from checkedlistbox the total no. of textboxes should also change but those textboxes are not getting redrawn only previously drawn textboxes remain in form.

Can someone help me out where I am going wrong or where is the piece of code missing?

解决方案


这篇关于如何重绘动态添加的控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 08:09
查看更多