private void LoadControls() { ControlsPanel.SuspendLayout(); foreach (var control in customControls) { if (control is ComboBox) { var combo = (ComboBox)control; var panel = ControlPanel(); combo.Size = combo.PreferredSize; combo.Padding = new Padding(5, 5, 5, 10); panel.Controls.Add(NewControlLabel(combo.Tag.ToString())); panel.Controls.Add(combo); ControlsPanel.Controls.Add(panel); } else if (control is TextBox) { var textBox = (TextBox)control; var panel = ControlPanel(); if (textBox.Name.Contains("pass")) { textBox.UseSystemPasswordChar = true; } panel.Controls.Add(NewControlLabel(textBox.Tag.ToString())); textBox.Width = 150; textBox.KeyDown += TextBox_KeyDown; panel.Controls.Add(textBox); ControlsPanel.Controls.Add(panel); } else if (control is CheckBox) { var checkBox = (CheckBox)control; checkBox.AutoSize = true; checkBox.Text = checkBox.Tag.ToString(); ControlsPanel.Controls.Add(checkBox); } else if (control is Label) { var label = (Label)control; label.AutoSize = true; label.Padding = new Padding(5, 5, 5, 10); ControlsPanel.Controls.Add(label); } else if (control is RichTextBox) { var rtb = (RichTextBox)control; if (isMessageBox) { ControlsPanel.Visible = false; rtb.ReadOnly = true; rtb.Margin = new Padding(5, 10, 5, 0); rtb.BackColor = ControlsMainPanel.BackColor; rtb.TabStop = false; rtb.LinkClicked += ClickedLink; ControlsMainPanel.Controls.Add(rtb); // Set the local field for later loading/resizing changes. messageBox = rtb; } else { var panel = ControlPanel(); rtb.Width = 150; rtb.Height = 80; if (rtb.Tag != null) { panel.Controls.Add(NewControlLabel(rtb.Tag.ToString())); } panel.Controls.Add(rtb); ControlsPanel.Controls.Add(panel); } } else if (control is Button) { var button = (Button)control; button.AutoSize = true; button.Click += ButtonClick; ControlsPanel.Controls.Add(button); } else { var panel = ControlPanel(); panel.Controls.Add(NewControlLabel(control.Tag.ToString())); panel.Controls.Add(control); ControlsPanel.Controls.Add(panel); } } ControlsPanel.ResumeLayout(); ControlsMainPanel.PerformLayout(); }