473,394 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to pass a form to another form

Hi all,

I have a form1 ,in that i have 2 lable and 2 combo boxes. and a
button. when the user clicks the button,i need to pass form1 to form2.
how i can access the form1 controls in form2.

plz help me

Jun 26 '07 #1
3 1308
As a general rule, that isn't a great idea as it breaks encapsulation.

One solution is to mark the protection of the controls as "public"
(which you can do in the designer via the properties window, or in
code) but this is not very nice.

A better approach would depend on what you are doing; you could, for
instance, expose some public events and methods on the second form;
this would allow you to interact / respond, without needing to know
about the implementation details.

Marc
Jun 26 '07 #2
As Mark indicated, there are elegant and not-so-great ways to do this. One
easy way (not necessarily the best or most elegant) is to pass the first form
into the constructor of the second form, and have a field of type Form in the
second:
class Form Secondform
{
private Form _firstForm;

public Form( Form otherForm)
{
_firstForm = otherForm;
}

-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder(BETA): http://www.blogmetafinder.com

"bh**************@yahoo.co.in" wrote:
Hi all,

I have a form1 ,in that i have 2 lable and 2 combo boxes. and a
button. when the user clicks the button,i need to pass form1 to form2.
how i can access the form1 controls in form2.

plz help me

Jun 26 '07 #3
Hi,

<bh**************@yahoo.co.inwrote in message
news:11**********************@x35g2000prf.googlegr oups.com...
Hi all,

I have a form1 ,in that i have 2 lable and 2 combo boxes. and a
button. when the user clicks the button,i need to pass form1 to form2.
how i can access the form1 controls in form2.
Just create a constructor in form2 that receive a Form1 instance

Remember to also make the controls (or use properties ) to make the controls
available from form2
Jun 26 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Vanessa | last post by:
Hi, I would like to know whether there's any way for me to pass an object by reference to another form? Regards Vanessa
3
by: Lyn | last post by:
Hi, I have been experiencing a problem passing a LIKE statement in the WHERE argument of a DoCmd.Openform statement. I have posted that issue separately. However, in an attempt to work around...
4
by: Vaughn | last post by:
When I pass a reference to my current form, frm_x, when I create and show another form, frm_y, do I have access to all of the public methods, controls, members, etc.. of frm_x from frm_y? In my...
4
by: tom | last post by:
Hi Experts, I want to pass the selectedDate value from my calender form to another web form or a web user control. Could you please show me how to do this? Thanks in advance.
2
by: KFactor | last post by:
Is it possible to pass form variables to a page on another server using response.redirect? Or is there a secure way of passing sensitive information from one site to another such as a userID? ...
2
by: c676228 | last post by:
Hi, This is my first time to post asp.net question on this forum. I have a question for "How to pass the first form value to the next form" I have enrollinfo.aspx form which look like as follow:...
17
by: Rabbit | last post by:
Hi, On my 1st page, i have a function which gets a new ID value and need to transfer to another immediately. which I want to get in 2nd page using Request.form("txtID"), but doesn't work, the...
7
by: Boki | last post by:
Hi All, I can't pass data to another form: in form2: private void button1_Click(object sender, EventArgs e) { Form1 form_copy = new Form1();
14
by: =?Utf-8?B?Umljaw==?= | last post by:
I have seen examples of passing data from FormB to FormA (Parent To Child) but I need an example of passind data from FormA to FormB. My main form is FormA; I will enter some data in textboxes and...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
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...
0
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...

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.