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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:36:02+00:00 2026-05-26T07:36:02+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);
modelarray myArray = new modelarray(this);
model = myArray.models[0];
myArray.models[1] = (Model) model.Clone();

    private void btn13_Click(object sender, EventArgs e)
    {
        model.btn13Clicked();
    }

    private void btnGetBackClone_Click(object sender, EventArgs e)
    {
        model = myArray.models[1];
        //here I'm expecting to get the original object back (ie. with btns[7,7].Visible = True) but it doesn't work!!
    }

in model class I have:

private Button[,] btns;

public Model(Form1 form1)
{
btns = new Button[10,10];
myform = form1;
btns[8, 6] = form1.btn1;
btns[9, 5] = form1.btn2;
btns[7, 7] = form1.btn13;

}

public void btn13Clicked()
{
   btns[7, 7].Visible = False;
}

public object Clone()
{
  return this.MemberwiseClone();
}

in modelarray class I have:

public Model[] models = new Model[19];
public modelarray(Form1 form1)
{
  models[0] = new Model(form1);
}

Note my comment under the btnGetBackClone_Click method.
“//here I’m expecting to get the original object back (ie. with btns[7,7].Visible = True) but it doesn’t work!!”

I understand that this is because models[0] and models[1] are pointing to the same memory location (ie copy by ref). But I am really lost at how to implement a solution in this situation. Searches on ‘deep copy’ did not seem to help as serializing a form didn’t work. Can someone please correct my cloning error?

I know I could simply redo “btns[7, 7].Visible = True;” but I would like to know a cloning solution so it will copy all future fields I decide to put in my model.

I’ve had a search on codeproject.etc but there doesn’t seem to be any straightforward intro to winforms.

  • 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-26T07:36:03+00:00Added an answer on May 26, 2026 at 7:36 am

    .NET usually uses shallow copies during Clone operations.

    In order to implement deep copies, you typically have 2 options

    1. Serialize / deserialize (if your classes are all serializable) – e.g. Here
    2. By using reflection e.g. Here

    If you split your data (model) concerns out of your form (view), you can then more easily ‘clone’ just the data.

    • 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
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
I have a program with two modes: GUI & Just Run. GUI loads a
So, I have a list containing a custom class, MyClass MyClass has properties, which

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.