Probably the Form1_Load function is not executed. Open the Designer of the form, select the form, go to Properties, to Events tab. For the Load event, select Form1_Load.
How to show the controls

Dear All,
The following code is copied from the web page https://www.geeksforgeeks.org/c-sharp-tooltip-class/. Then I created a new project "TooltipTest" and copied the code to test the code. However, when I ran the form all controls disappeared.
My question is how to show the controls?
The code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;using
namespace
public
public
{
InitializeComponent();
}
private
{
// Creating and setting the
// properties of the Label
Label l1 = new
l1.Location = new
l1.Text = "Name";
// Adding this Label
// control to the form
this.Controls.Add(l1);
// Creating and setting the
// properties of the TextBox
TextBox box1 = new
box1.Location = new
box1.BorderStyle = BorderStyle.FixedSingle;
// Adding this TextBox
// control to the form
this.Controls.Add(box1);
// Creating and setting the
// properties of Label
Label l2 = new
l2.Location = new
l2.Text = "Password";
// Adding this Label
// control to the form
this.Controls.Add(l2);
// Creating and setting the
// properties of the TextBox
TextBox box2 = new
box2.Location = new
box2.BorderStyle = BorderStyle.FixedSingle;
// Adding this TextBox
// control to the form
this.Controls.Add(box2);
// Creating and setting the
// properties of the ToolTip
ToolTip t_Tip = new
t_Tip.Active = true;
t_Tip.AutoPopDelay = 4000;
t_Tip.InitialDelay = 600;
t_Tip.IsBalloon = true;
t_Tip.ToolTipIcon = ToolTipIcon.Info;
t_Tip.SetToolTip(box1, "Name should start with Capital letter");
t_Tip.SetToolTip(box2, "Password should be greater than 8 words");
}
}
}
The Project:
When I ran the code, no controls on the form:
Developer technologies | C#
2 additional answers
Sort by: Most helpful
-
Karen Payne MVP 35,586 Reputation points Volunteer Moderator
2024-01-30T16:40:07.62+00:00 You are missing
- The project namespace name (1)
- The form name e.g. Form1 (2)
- The form name e.g. Form1() (3)
- Method name (4)
- using System.Windows.Forms;using is incorrect
-
Anonymous
2024-01-31T01:29:29.7133333+00:00 Hi @BenTam-3003 , Welcome to Microsoft Q&A,
You are missing some necessary elements. The correct code should be:
using System; using System.Drawing; using System.Windows.Forms; namespace xxx { public partial class Form1 : Form { public Form1() { InitializeComponent(); Form1_Load(null, null); } private void Form1_Load(object sender, EventArgs e) { // Creating and setting the // properties of the Label Label l1 = new Label(); l1.Location = new Point(140, 122); l1.Text = "Name"; // Adding this Label // control to the form this.Controls.Add(l1); // Creating and setting the // properties of the TextBox TextBox box1 = new TextBox(); box1.Location = new Point(248, 119); box1.BorderStyle = BorderStyle.FixedSingle; // Adding this TextBox // control to the form this.Controls.Add(box1); // Creating and setting the // properties of Label Label l2 = new Label(); l2.Location = new Point(140, 152); l2.Text = "Password"; // Adding this Label // control to the form this.Controls.Add(l2); // Creating and setting the // properties of the TextBox TextBox box2 = new TextBox(); box2.Location = new Point(248, 145); box2.BorderStyle = BorderStyle.FixedSingle; // Adding this TextBox // control to the form this.Controls.Add(box2); // Creating and setting the // properties of the ToolTip ToolTip t_Tip = new ToolTip(); t_Tip.Active = true; t_Tip.AutoPopDelay = 4000; t_Tip.InitialDelay = 600; t_Tip.IsBalloon = true; t_Tip.ToolTipIcon = ToolTipIcon.Info; t_Tip.SetToolTip(box1, "Name should start with Capital letter"); t_Tip.SetToolTip(box2, "Password should be greater than 8 words"); } } }
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.