日期:2014-05-20  浏览次数:20906 次

控件上添加控件无效
public   void   AddMyControls1(int   pos_width,   int   pos_height,   string   text,   string   name)
                {
                        Label   UserControl   =   new   Label();
                        UserControl.Name   =   "lbl "   +   name;
                        UserControl.Text   =   text;
                        UserControl.ForeColor   =   SystemColors.ControlLightLight;
                        UserControl.Location   =   new   Point(6,   30   +   pos_height);
                        UserControl.Size   =   new   Size(53,   12);
                        //UserControl.TopLevelControl   =   this.groupBox5;
                        //this.groupBox5.Controls.Add(UserControl);
                        this.groupBox5.Controls.Add(UserControl);
                        LabArray[TxtNum   -   2]   =   UserControl;
       
                }

我   用这段代码在groupBox5添加LABEL控件没有效果,
但把这句
this.groupBox5.Controls.Add(this.label1);
写到主函数里却是有效果的

我问下是那里出了问题啊

------解决方案--------------------
个人感觉是线程造成的。Ui线程和工作线程的问题
------解决方案--------------------
你添加到Controls的UserControl应该设置Visible属性为True才行:
UserControl.Visible=true;
------解决方案--------------------
是不是你生成控件的Location已经超出了你这个groupBox5的范围了