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 6691487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:45:27+00:00 2026-05-26T05:45:27+00:00

My program class has: Application.Run(new Form1()); in form1 class I have: model = new

  • 0

My program class has:

Application.Run(new Form1());

in form1 class I have:

model = new Model(this);

    private void userEnteredText()
 {
       Model clonedModel = (Model)model.Clone();
       this.myButton.Size = new System.Drawing.Size(10,5);
       MessageBox.Show("buttons made small");
       this = clonedModel;
      MessageBox.Show("clone complete and buttons restored to orig size");
}

in model class I have:

    public Model(Form1 form1)
    {
        myform = form1;
    }

public object Clone()
{
   return new Model(myform);
}

My initial form1 object has the size of buttons really large. After the user enters a value in a textbox: I clone the model object and call a method that makes the buttons really small. How can I then set the model object to point back to the original model object with large buttons?

I’m getting this error:
“Cannot assign to this because it is read-only”

I know I can just change the button size but I need to clone the entire object because there are other original variables that I want reset.

  • 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-26T05:45:28+00:00Added an answer on May 26, 2026 at 5:45 am

    One question – is it expected behaviour that whilst clone both models references the same Form? Clone() method just creates a new instance of Model but it still reference the same Form object,

    You can persist state of the initial model in an other private field like

    private Model backupModel;
    

    and before applying a user-defined values just backup and later restore current model like:

     private void userEnteredText()
     {
           this.backupModel = model;     
           Model clonedModel = (Model)model.Clone();
           this.myButton.Size = new System.Drawing.Size(10,5);
           MessageBox.Show("buttons made small");
           model = this.backupModel;     
           MessageBox.Show("clone complete and buttons restored to orig size");
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My program class has: Application.Run(new Form1()); in form1 class I have: model = new
I have an application that uses (has referenced) a class library (myLib.dll private assembly).
My program has the following class definition: public sealed class Subscriber { private subscription;
All objects in my program inherit from a Container class. The Container class has
I'm making a simple program in Objective-C. It has one class with a lot
Heyo, My class at college has us writing programs in assembly. I have never
Take the following useless program: class Program { static void Main(string[] args) { IUnityContainer
why in C#, console application, in program class , which is default, all methods
I have a question on constant objects. In the following program: class const_check{ int
class Program { static void Main(string[] args) { String value = Two; Type enumType

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.