不会出现动态生成的控件

时间:2018-04-21 16:28:02

标签: c# winforms

有一个名为OnUserJoined的事件,它会触发一个将控件添加到flowLayoutPanel的进程。问题是控件没有出现,并且没有错误消息。为什么不工作?

代码

public void Adduser(object sender, QMEventArgs e)
{
    Console.WriteLine("Updating user list.");
    MetroPanel up = new MetroPanel()
    {
        BackColor = Color.DodgerBlue,
        CustomBackground = true,
        Size = new System.Drawing.Size(1177, 76),
        Style = MetroFramework.MetroColorStyle.Blue
    };

    MetroLabel uname = new MetroLabel()
    {
        Text = e.UserName,
        AutoSize = true,
        CustomBackground = true,
        Dock = DockStyle.Top,
        FontSize = MetroFramework.MetroLabelSize.Tall,
        FontWeight = MetroFramework.MetroLabelWeight.Bold,
        Location = new Point(0, 0),
        Style = MetroFramework.MetroColorStyle.White,
        UseStyleColors = true,
    };
    MetroLabel uip = new MetroLabel()
    {
        Text = e.UserIP,
        AutoSize = true,
        CustomBackground = true,
        Dock = DockStyle.Top,
        FontSize = MetroFramework.MetroLabelSize.Small,
        FontWeight = MetroFramework.MetroLabelWeight.Regular,
        Location = new Point(0, 25),
        Style = MetroFramework.MetroColorStyle.White,
        UseStyleColors = true,
    };                

    up.Controls.Add(uip);
    up.Controls.Add(uname);
    flowLayoutPanel1.Controls.Add(up);
}

0 个答案:

没有答案