Hi,
I am using following code in winform but it throws error while dynamically add the control.
Button button = new Button();
button.Name = "h Enter";
button.Text = "Enter";
this.Controls.Add(button);
Hi,
I am using following code in winform but it throws error while dynamically add the control.
Button button = new Button();
button.Name = "h Enter";
button.Text = "Enter";
this.Controls.Add(button);
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Selva GanapathyRank #560 · 4.3K reputationPosted Dec 10, 2014, 6:02 PM EST
Hi Jegan Priya,
What error you have face? Also I think it may due to the Name you have declared for the button.
Space is not allowed in Name SO please use "hEnter" instead of "h Enter"
Regards,
Selva Ganapathy K
VulpesRank #55 · 29.2K reputationPosted Dec 11, 2014, 12:49 AM EST
You can call a control what you like and, although it's not recommended, even give it the same name as an existing control.
To show that this is so, I created a new WF project, placed a button (button1) in the middle of it and put this code in the click handler:
When I clicked the button, the output of the MessageBox was:
button1
h Enter
and when I clicked it again, the output was:
button1
h Enter
h Enter
as there were now two 'h Enter' buttons superimposed over each other.
Can you tell us what the actual error is here?