Skip to main content
 首页 » 编程设计

c#之通过代码在布局控件中添加用户控件

2024年02月13日12cyq1162

我想通过代码在 LayoutControl 上添加一些 UserControl。他们应该出现在彼此之间。这就是问题所在。我只是成为一个可见的 UserControl。 我现在正在做以下事情:

    foreach (myClass tempMyClass in allObjectsFromMyClass) 
    { 
        // I create UserControl 
        ctrlProgramm programm = new ctrlProgramm(); 
 
        // I set some label values and so on for Control 
        programm.BxProgrammInitialiseren(tempMyClass); 
 
        // I Add UserControl to the LayoutControl Controls Collection 
        LayoutControl.Controls.Add(programm); 
    } 

我只能看到在 foreach 的第一个循环中创建的控件。 也许他们一个人躺着一个人?也许我需要先添加一个面板?

信息:LayoutControl 在命名空间 DevExpress.XtraLayout 中,我们使用的是 DevExpress v2010 vol.2

问候

请您参考如下方法:

在 LayoutControl 中添加控件时,您应该使用 LayoutControlItems 包裹这些控件,如下所示:

//Create a layout item and add it to the root group.     
LayoutControlItem item1 = layoutControl.Root.AddItem(); 
 
item1.Name = "item1"; 
ctrlProgramm programm = new ctrlProgramm(); 
 
// Set the item's Control and caption.     
item1.Control = programm; 
item1.Text = "Program:"; 

相关帮助文章:
How to: Create layout items via code
How to: Create layout groups and items via code

要了解有关 LayoutControl 概念的更多信息,请参阅以下文章:
Introducing the XtraLayoutControl
Tutorial: Creating a Simple Layout