473,804 Members | 2,136 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Copying a Form

48 New Member
Hi there,

Is there any method or a way to copy a form object to a variable?

Let me explain this - We have a method called "Copy" for the Dataset class & you all must be knowing that there is a difference between the below two lines of code:
Expand|Select|Wrap|Line Numbers
  1.                  DsTemp = Ds 
  2.                  DsTemp = Ds.Copy()
  3.  
In the first line of code, any changes made to Ds will reflect in DsTemp. However, in the second line of code, any changes made to Ds will not reflect in DsTemp because we are only "copying" the contents & schema of Ds. Likewise is there a method or a work around to "copy" a Form object?

Thanks in advance,
Aads




- please see the below code:

Expand|Select|Wrap|Line Numbers
  1.  Dim Ds as Dataset
  2.                  Ds.ReadXml("C:\MyXml.xml")
  3.                  Dim DsTemp as Dataset = Ds.Copy()
Jan 8 '09 #1
11 1867
r035198x
13,262 MVP
Controls don't seem to be Cloneable by default in .NET.
Perhaps this article may help?
Jan 8 '09 #2
Aads
48 New Member
Thanks for your help - that article did help me to explore about controls but the same doesn't apply for windows forms.
Jan 10 '09 #3
Xennex
7 New Member
When I first used VB.NET the only way you could get a form was to define it first. For example if I had designed a form with the name "frmMenu" I would have had to create an instance of it first by DIMming it first. "dim myForm as New frmMenu" Then I would have to use myForm in all my further code. Now it seems you can use the classes like you could back in VB6 by just referencing them and letting the compiler create a new object automatically.. I believe if you dim a variable of type <your form class> with the New keyword like above, you should be able to create any number of objects of your form class, each with it's own set of properties that can be changed independent of any other object of that form class.
Jan 21 '09 #4
vekipeki
229 Recognized Expert New Member
Why would you like to deep copy a Form object? You can create as many instances of a Form and display them simultaneously, but the actual data those forms are displaying doesn't have to be the same.

For example:
Expand|Select|Wrap|Line Numbers
  1. MyForm f1 = new MyForm()
  2. f1.SomeData = myData.Clone(); // this will create a new copy
  3. f1.Show();
  4.  
  5. MyForm f2 = new MyForm()
  6. f2.SomeData = myData.Clone(); // this will create a new copy
  7. f2.Show();
  8.  
  9. // etc.
  10.  

What exactly are you trying to achieve, is there some data in your Form's properties that you would like to copy?
Jan 22 '09 #5
Aads
48 New Member
Thanks for your reply - yes you are right; I've some data in my form which I want to preserve for subsequent uses. Let me explain you this with the help of below code snippet - please see the below code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim _listOfForms As New List(Of Form) 'List to hold data of type Form.
  3. Dim _theFormChild As FormChild 'An instance of a child form
  4.  
  5. Private Sub OpenChildForm()
  6.    _theFormChild = New FormChild '--------> (1), See below NOTE after this code snippet
  7.    _theFormChild.MdiParent = Me
  8.    _theFormChild.Show()
  9.  
  10.    _listOfForms.Add(_theFormChild) 'Add it to the generic list.
  11. End Sub
  12.  
  13. Private Sub OpenStoredChildForm()
  14.    _listOfForms(0).Show() ' This doesn't open up a form. (quite obvious!)
  15. End Sub
  16.  
  17.  
NOTE: As Soon as the control reaches the constructor of the child Form, lots of statements are executed. For ex:
(a.) I instantiate around 8 classes which reads xml files of around 10 MB each. After it has read, it stores the data in the SortedList.
(b.) Next I instantiate 5 modal forms which in turn again instantiates some other classes.
(c.) Once the above tasks are done, I store (a.) & (b.) as properties of child Form i.e. as long as I've access to my child Form, I can happily access these properties as well.

Now this process takes around 7 seconds to complete which happens everytime whenever the user hits a button in the form. All I want to do is whenever the user hits the button for the first time let this process go on (as it needs to if I want to store somewhere or even otherwise) but when he hits the button for the second time instead of initiating this process again from scratch I want to access this data where I would've stored (which is what is required).

Is there a way where in I can store my child Form once it completes instantiation so that I can reuse the same Form whenever the user requires it thereby saving lot of time.

Cheers,
Aads
Jan 22 '09 #6
Xennex
7 New Member
So you just need to have the child form available to use but not visible? If so you could simply hide the child form using its "Hide" method. All parts of the child form are still accessible until you unload the child form.
Jan 23 '09 #7
Aads
48 New Member
Thanks for you quick reply. No I do not want the child form available just to use its properties. While this child Form is opened, if the user opens another copy of this form (without closing the one which is already opened), a new form opens going through all the process which I mentioned in the previous post thereby taking lot of time & this is what I do not want which is time consuming. All I want is that when the user opens the form subsequent times, it should open instantaneously with all the properties set (some how).


Cheers,
Aads
Jan 23 '09 #8
vekipeki
229 Recognized Expert New Member
Instead of cloning the Form, consider cloning the Form's data. For example, you already have a ChildForm constructor like this:

Expand|Select|Wrap|Line Numbers
  1. public ChildForm()
  2. {
  3.     InitializeComponent();
  4.     // do lots of xml work
  5. }
  6.  
and then you have a ChildForm property with large quantities of data:

Expand|Select|Wrap|Line Numbers
  1. private MyDataClass LargeData
  2. {
  3.     get { return this.largeData; }
  4.     set { this.largeData = value; }
  5.  
So, all that you need to do is add a parameterized constructor which accepts MyDataClass, or event ChildForm as input:

Expand|Select|Wrap|Line Numbers
  1. public ChildForm(ChildForm otherCopy)
  2. {
  3.     InitializeComponent();
  4.     // instead of doing xml work, just copy the data
  5.     // (note that we can access private properties in
  6.     // otherCopy instance)
  7.     this.LargeData = otherCopy.LargeData;
  8.  
  9.     // or this.largeData = otherCopy.LargeData.Copy(); if you want a deep copy
  10. }
  11.  
Then you can create a form by calling this constructor:
Expand|Select|Wrap|Line Numbers
  1. ChildForm c = new ChildForm(someOtherForm);
  2. c.MdiParent = this;
  3. c.Show();
  4.  
I just realized you're using VB.NET -- sorry. You should probably get the general idea.

Also, it is up to you to decide whether you want to Clone the data (make a separate deep memory copy), or just pass the reference to the same instance.
Jan 23 '09 #9
Aads
48 New Member
Hey thanks for your reply. I tried the technique suggested by you (storing xml data in properties & accessing it when required) - it worked absolutely fine. But could you please tell me what exactly "deep copy" means?

Cheers,
Aads
Feb 1 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
3795
by: winshent | last post by:
I have copied approx 20 controls from a form to a tab control for reasons of space. i now cannot run code triggered by the events of these controls. for example, the following will not trigger the message box when changed: Private Sub cboA_Change() MsgBox "combo A changed"
1
2181
by: Andromeda | last post by:
Ok... form with a subform.. form has contact information (company name, address, etc.) subform selects the area covered by each contact form is linked to subform on contactID (a primary key/autonumber for tbl form is based on, FK for table subform is based on) for some reason, the contactID is not copying over from the form to the subform, so after I enter information in the subform I have to go to the table and fill in the...
9
1535
by: Raposa Velha | last post by:
Any of you ever catch this bug: I made a form and decided to copy it. Then I modified the cloned form. Then I run it and access start saying "Error accessing file. Network connection may have been lost." Then I tryed to modify an event procedure and I realized that the correspondig code wasn't copyed along with the form! Deleting the form didn't solve the problem and a Compact and Repair Database did everything but reparing it! Actually I'm...
8
18361
by: Randy | last post by:
Hi, is it possible to show the progress of a big file being copied e.g. in a "progressbar"? I tried to use file.copy - but this seems to make no sense :-( Thanks in advance, Randy
2
2261
by: Venkat Venkataramanan | last post by:
Hello: I have an object Users that implements the ICloneable interface. I am trying to pass an instance of this object, foUser from one form into a second form ByRef. Dim formLogin As New frmLogin(foUser)
10
7841
by: Martin Ho | last post by:
I am running into one really big problem. I wrote a script in vb.net to make a copy of folders and subfolder to another destination: - in 'from.txt' I specify which folders to copy - in 'to.txt' I specify where to copy it - After I read content of 'to.txt' I create one more subfolder named by current date and thats where everything gets to be copied
3
1646
by: Son KwonNam | last post by:
Hello, When there a two forms like the follosings, <form name="source"> <input name="a..." value=".." ..> <input name="a..." value=".." ..> <input name="a..." value=".." ..> <input name="a..." value=".." ..> </form>
4
1542
by: antheana | last post by:
Hi there, I have a specific problem, but also wanted to guage everyone's thoughts on copying codes. For less knowledgeable people like myself, I sometimes find i difficult to write code from scratch, but now that I've been developing a database (with your help!) I'm starting to see how the code is working. However, I recently copied some code to create an appointment in MS Outlook and adapted it to use existing data on my job form, as...
1
3164
by: =?Utf-8?B?Y3JhbmtlX2JveQ==?= | last post by:
Hi Folks, I'm not sure where this post belongs since I'm using managed vc.net, but the issue is around GDI BitBlt. Here is a summary of the problem: - I am trying to copy a bitmap of my main form into a picture box. - To do this, I bitblt using the device contexts of the form and a bitmap object. - After blitting, the bitmap image is always blank. I don't understand what
2
2820
by: raylopez99 | last post by:
Beware newbies: I spent a day before I figured this out: copying a bitmap (image) file to file is not quite like copying a text file--you have to do some tricks (see below), like using a "Graphics" object to wrap around the image (!). It's not so simple as shown in most examples (where they have a simple image file and hard copy it into a harddrive along the lines of : image.Save(@"C:\\temp\\myimage.pgn"); That will work, but it's a...
0
9595
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10604
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10354
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10359
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10101
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9177
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7643
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6870
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4314
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.