比方說,我們有下面的類Cell
,它是由一個Label
控制:更改動態創建的自定義控件的位置
class Cell : UserControl
{
Label base;
public Cell(Form form)
{
base = new Label();
base.Parent = form;
base.Height = 30;
base.Width = 30;
}
}
public partial class Form1 : Form
{
Label label = new Label();
public Form1()
{
InitializeComponent();
Cell cell = new Cell(this);
cell.Location = new Point(150, 150); //this doesnt work
label.Location = new Point(150,150); //but this does
}
}
單Cell
將在Form
顯示,而是固定在top left (0,0)
位置。
將位置屬性設置爲一個新的Point
與任何其他座標什麼也不做,因爲Cell
將保留在左上角。
但是,如果一個人創建一個新Label
,然後嘗試將其位置,標籤會被感動。
有沒有辦法做到這一點我Cell
對象?
你控件添加到控件集合?你用對接嗎? –