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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Selva GanapathyPosted Dec 10, 2014, 11:02 PM
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
VulpesPosted Dec 11, 2014, 5:49 AM
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?