为什么以编程方式添加控件未显示?

时间:2018-05-29 01:48:33

标签: winforms controls

有谁知道为什么这些控件没有显示在表单上?如果我通过设计添加具有相同属性的控件一切正常,但如果我在表单构造函数中使用设计器中的相同代码而只有其他名称,则无效。

private void CreatePlayingTab()
    {
        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));

        // 
        // bunifuCustomLabel_Titel
        // 
        BunifuCustomLabel bunifuCustomLabel_Titel = new BunifuCustomLabel();
        bunifuCustomLabel_Titel.AutoSize = true;
        bunifuCustomLabel_Titel.Font = new Font("Century Gothic", 11.25F, FontStyle.Bold, GraphicsUnit.Point, 0);
        bunifuCustomLabel_Titel.ForeColor = Color.FromArgb(224, 224, 224);
        bunifuCustomLabel_Titel.Location = new Point(19, 30);
        bunifuCustomLabel_Titel.Name = "bunifuCustomLabel_Titel";
        bunifuCustomLabel_Titel.Size = new Size(153, 18);
        bunifuCustomLabel_Titel.Text = "#001 Wer ist Naruto?";

        // 
        // bunifuCustomLabel_Interpret
        // 
        BunifuCustomLabel bunifuCustomLabel_Interpret = new BunifuCustomLabel();
        bunifuCustomLabel_Interpret.AutoSize = true;
        bunifuCustomLabel_Interpret.Font = new Font("Century Gothic", 11.25F, FontStyle.Regular, GraphicsUnit.Point, 0);
        bunifuCustomLabel_Interpret.ForeColor = Color.FromArgb(224, 224, 224);
        bunifuCustomLabel_Interpret.Location = new Point(20, 52);
        bunifuCustomLabel_Interpret.Name = "bunifuCustomLabel_Interpret";
        bunifuCustomLabel_Interpret.Size = new Size(98, 20);
        bunifuCustomLabel_Interpret.Text = "Studio Tokyo";

        // 
        // windowsMediaPlayer
        // 
        AxWindowsMediaPlayer windowsMediaPlayer = new AxWindowsMediaPlayer();
        windowsMediaPlayer.Dock = DockStyle.Bottom;
        windowsMediaPlayer.Enabled = true;
        windowsMediaPlayer.Location = new Point(0, 117);
        windowsMediaPlayer.Name = "windowsMediaPlayer";
        windowsMediaPlayer.OcxState = ((AxHost.State)(resources.GetObject("mediaPlayer.OcxState")));
        windowsMediaPlayer.Size = new Size(912, 513);
        windowsMediaPlayer.uiMode = "None";

        // 
        // panel_currentlyPlaying
        //
        Panel panel_currentlyPlaying = new Panel();
        panel_currentlyPlaying.Controls.Add(windowsMediaPlayer);
        panel_currentlyPlaying.Controls.Add(bunifuCustomLabel_Titel);
        panel_currentlyPlaying.Controls.Add(bunifuCustomLabel_Interpret);
        panel_currentlyPlaying.Dock = DockStyle.Fill;
        panel_currentlyPlaying.Location = new Point(0, 100);
        panel_currentlyPlaying.Name = "panel_Playing";
        panel_currentlyPlaying.Size = new Size(912, 630);

        panel_Media.Controls.Add(panel_currentlyPlaying);
    }

1 个答案:

答案 0 :(得分:0)

我想您可能忘记将控件添加到表单中。

使用this.Controls.Add(Control Item);