Question Why are programmatically added controls not shown?

Kaskorian

New member
Joined
May 30, 2018
Messages
1
Programming Experience
3-5
Does anyone know why these controls are not displayed on the form? When I add the controls over the design and the algorithm writes the properties to the InitializeComponents method, everything works great. But if I use the same code from the designer in the form constructor with just different names, the labels will not be displayed.

C#:
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);
    }

panel_Media is a panel which has been added to the form via design, so it's already on the form.
 

Latest posts

Back
Top Bottom