C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » .NET »

C# application.


Posted Date: 04 Nov 2009      Posted By: sajith      Member Level: Bronze     Points: 1   Responses: 2



Hi experts,
I have a c# application.I want to create a button dynamically when I click on a button.Also When I click on another button,I want to delete or disable the dynamically created button. Can I acces this dynamically created button anywheere in the application.?????





Responses

Author: Danasegarane.A    04 Nov 2009Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

Hope this helps


private void button1_Click(object sender, EventArgs e)
{


Button btn = new Button();
btn.Visible = true;
btn.Text = "Dyanamically Created Button";
btn.Click += new System.EventHandler(btnClick);
//Add it to Form
this.Controls.Add(btn);

}
private void btnClick(object sender, EventArgs e)
{
MessageBox.Show("I am diabling");
((Button)sender).Enabled = false;
}



Thanks and Regards,
Danasegarane Arunachalam



Author: ABitSmart    04 Nov 2009Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

Danasegrane has demonstrated the adding of button correctly. To remove or disable, you can do a find control.

private void button1_Click(object sender, EventArgs e)
{

Button btn = new Button();
btn.Visible = true;
btn.Text = "Dyanamically Created Button";
btn.Name = "btnName";
btn.Click += new System.EventHandler(btnClick);
//Add it to Form
this.Controls.Add(btn);
}
private void btnClick(object sender, EventArgs e)
{
MessageBox.Show("I am diabling");
Button bt = this.Controls.Find("btnName");
bt.Enabled = false;
//or this.Controls.Remove(bt); to remove it
}


Kind regards,
ABitSmart
DNS Web-master, DNS MVM
My blog
Thoughts.exe



Post Reply
You must Sign In to post a response.
Next : How to dispose/disable dynamically created button
Previous : Clearing/Editing Internet explorer DNS cache
Return to Discussion Forum
Post New Message
Category: .NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use