here’s my code
private void make_Book(int x, int y, string name)
{
#region Creating Book
// this code is initializing the book(button)
Button book1 = new Button();
Image img = button1.Image;
book1.Image = img;
book1.Name = name;
book1.Height = img.Height;
book1.Width = img.Width;
book1.Location = new Point(44 + x, 19 + y);
book1.Click += new EventHandler(myClickHandler);
groupBox1.Controls.Add(book1);
#endregion
}
this code is making a button every time I click on a button,, now i want to save the created button and its property so that they could appear every time application starts..
coded in C# visual studio 2010…
One solution could be to use a
StringCollectionuser setting (EDIT: In your comment you’re saying that this will not be persisted when closing the application. That’s not true, as this is the entire point of using user settings…).In every line, you need to save the position and the name of a control as a string, for example like
When the user adds a new button, create an item in the
StringCollectionlike so:Then you’d need code that creates the buttons from every item in the
StringCollectionby reading each line, extracting the location and name and callingmake_bookagain (not my newmake_BookButtonAndStoremethod, as this would double the button).Note that you may need to create the
StringCollectionwith thenewkeyword before adding the first button.EDIT
To explain how to create such a setting: Go to your project properties to the “Settings” tab. Create a new setting named
ButtonStringCollection, select typeSystem.Collections.Specialized.StringCollectionand scopeUser.In your form’s constructor, add the following line:
Then, add the code I’ve provided above to create the buttons. Also, in the form’s
Loadevent handler, add something like the following: