Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1049781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:40:13+00:00 2026-05-16T16:40:13+00:00

Is it possible to save a WinForms user control(ex: button) to the database? Or

  • 0

Is it possible to save a WinForms user control(ex: button) to the database?
Or the only thing that can be saved is the settings property.

EDIT:
Like what triggerX said. I tested the serializable idea.

btnAttrib.cs

[Serializable()]
class btnAttrib
{
    public Point LocationBTN { get; set; }
    public Size SizeBTN { get; set; }
    public string NameBTN { get; set; }

    public btnAttrib(Point l, Size s, string n) 
    {
        this.LocationBTN = l;
        this.SizeBTN = s;
        this.NameBTN = n;
    }
}

MainForm.cs

 private void button2_Click(object sender, EventArgs e)
    {
        var btnAttr = new List<btnAttrib>();

        btnAttr.Add(new btnAttrib(new Point(50, 100), new Size(50, 50), "Button 1"));
        btnAttr.Add(new btnAttrib(new Point(100, 100), new Size(50, 50), "Button 2"));
        btnAttr.Add(new btnAttrib(new Point(150, 100), new Size(50, 50), "Button 3"));
        btnAttr.Add(new btnAttrib(new Point(200, 100), new Size(50, 50), "Button 4"));

        try
        {
            using(Stream st = File.Open("btnSettings.bin", FileMode.Create)) {
                BinaryFormatter bf = new BinaryFormatter();
                bf.Serialize(st, btnAttr);
            }
        }
        catch (Exception ex) {
            MessageBox.Show(ex.Message, "Exception");
        }
    }

    private void button1_Click(object sender, EventArgs e)
    {
        try {
            using (Stream st = File.Open("btnSettings.bin", FileMode.Open)) {
                BinaryFormatter bf = new BinaryFormatter();

                var btnAttr2 = (List< btnAttrib>)bf.Deserialize(st);
                foreach(btnAttrib btAtt in btnAttr2) {

                    Button nBTN = new Button();
                    nBTN.Location = btAtt.LocationBTN;
                    nBTN.Size = btAtt.SizeBTN;
                    nBTN.Name = btAtt.NameBTN;

                    this.Controls.Add(nBTN);
                }
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "Exception");
        }
    }

Is this the best Idea for saving user controls?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T16:40:14+00:00Added an answer on May 16, 2026 at 4:40 pm

    the answer is a vague “yes”, by serializing its properties/settings you can have the illusion that you are saving the control to the database.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

is it possible to save the user details (the Signed request that facebook sends
Is it possible to save some Perl code in a database, retrieve it using
How is it possible to save text from a text field when the user
Possible Duplicate: What is the best way to store user settings for a .NET
Is it possible to save the session data for database purposes before being destroyed?
Possible Duplicate: Save my cookie data to MySQL database? I want save data into
Possible Duplicate: Save my cookie data to MySQL database? I am new in programming
Is it possible to save a DataTable into SQL database in one cell of
Would it be possible to save certain locations that I've used recently/commonly (like /folder/folder/folder/)
Is it possible to save some kind of settings for an app create in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.