Hi,
Thanks for help in advance!
In Form1, I "New" a Form2 and ShowDialog the Form2, it's OK.
My intention is passing a value from Form2 to Form1.
However, in Form2, I shouldn't "New" a Form1, 'cuz it will open a new Form1,
the new Form1 will get the value. And the original Form1 get nothing!
What do I need to do to let the ORIGINAL Form1 get the target value?
Any help will be highly appreciated.
Jason 4 1991
hello,
You can create a public static property and set it to any value and you can
access it in form1.
eg
public static string myvalue
{
set {value = "what ever"};
get {return value;}
}
"Jason Huang" <Ja************ @hotmail.com> wrote in message
news:%2******** *******@TK2MSFT NGP15.phx.gbl.. . Hi,
Thanks for help in advance! In Form1, I "New" a Form2 and ShowDialog the Form2, it's OK. My intention is passing a value from Form2 to Form1. However, in Form2, I shouldn't "New" a Form1, 'cuz it will open a new Form1, the new Form1 will get the value. And the original Form1 get nothing! What do I need to do to let the ORIGINAL Form1 get the target value? Any help will be highly appreciated.
Jason
Hi,
You have several ways to do so, like:
1- Pass a reference from form1 to form2, then when needed you can update
form1 , note that form1 should have a public member to receive the value
back
// in form 1
form2 = new Form2( this);
form2.ShowDialo g();
//in form 2:
//constructor
public Form2( Form1 parent) { this.parentForm = parent;}
// in a method
parentForm.Publ icProperty = "what ever value";
2- make tha value accesible to form1 as a public property:
// in form 1
form2 = new Form2( this);
form2.ShowDialo g();
form1.receivedv alue = form2.PublicPro perty;
3- Make a static public property in form1 , this is the last resort,
//form1
public static string A_Property { get.. set }
//form2
//inside a method:
//note I use the Form1 type, not any instnace
Form1.A_Propert y = "a value" ;
cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Jason Huang" <Ja************ @hotmail.com> wrote in message
news:%2******** *******@TK2MSFT NGP15.phx.gbl.. . Hi,
Thanks for help in advance! In Form1, I "New" a Form2 and ShowDialog the Form2, it's OK. My intention is passing a value from Form2 to Form1. However, in Form2, I shouldn't "New" a Form1, 'cuz it will open a new Form1, the new Form1 will get the value. And the original Form1 get nothing! What do I need to do to let the ORIGINAL Form1 get the target value? Any help will be highly appreciated.
Jason
Thank you for help me!
But I got another question for this.
Saying that Form3 and Form4 will be also using the Form2, then how do we
build up the Form2 constructor,
so that Form3 and Form4 can get the value passed from Form2? Given that
Form1, Form2, Form3 and Form4
have no mdi relationship.
Thanks in advance again.
Jason
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us > ¼¶¼g©ó¶l¥ó·s»D: %2************* **@tk2msftngp13 .phx.gbl... Hi,
You have several ways to do so, like:
1- Pass a reference from form1 to form2, then when needed you can update form1 , note that form1 should have a public member to receive the value back // in form 1 form2 = new Form2( this); form2.ShowDialo g();
//in form 2: //constructor public Form2( Form1 parent) { this.parentForm = parent;}
// in a method parentForm.Publ icProperty = "what ever value";
2- make tha value accesible to form1 as a public property: // in form 1 form2 = new Form2( this); form2.ShowDialo g(); form1.receivedv alue = form2.PublicPro perty;
3- Make a static public property in form1 , this is the last resort,
//form1 public static string A_Property { get.. set }
//form2 //inside a method: //note I use the Form1 type, not any instnace Form1.A_Propert y = "a value" ;
cheers,
-- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation
"Jason Huang" <Ja************ @hotmail.com> wrote in message news:%2******** *******@TK2MSFT NGP15.phx.gbl.. . Hi,
Thanks for help in advance! In Form1, I "New" a Form2 and ShowDialog the Form2, it's OK. My intention is passing a value from Form2 to Form1. However, in Form2, I shouldn't "New" a Form1, 'cuz it will open a new Form1, the new Form1 will get the value. And the original Form1 get nothing! What do I need to do to let the ORIGINAL Form1 get the target value? Any help will be highly appreciated.
Jason
Hi Jason,
You kind of lost me, too many forms for so early in the morning :)
If your app is not MDI, and you know you will only have one instance of each
form created at the most, you can use a static property in each individual
form to hold a reference.
cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Jason Huang" <Ja************ @hotmail.com> wrote in message
news:eK******** *****@tk2msftng p13.phx.gbl... Thank you for help me! But I got another question for this. Saying that Form3 and Form4 will be also using the Form2, then how do we build up the Form2 constructor, so that Form3 and Form4 can get the value passed from Form2? Given that Form1, Form2, Form3 and Form4 have no mdi relationship. Thanks in advance again.
Jason
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us > ¼¶¼g©ó¶l¥ó·s»D: %2************* **@tk2msftngp13 .phx.gbl... Hi,
You have several ways to do so, like:
1- Pass a reference from form1 to form2, then when needed you can update form1 , note that form1 should have a public member to receive the value back // in form 1 form2 = new Form2( this); form2.ShowDialo g();
//in form 2: //constructor public Form2( Form1 parent) { this.parentForm = parent;}
// in a method parentForm.Publ icProperty = "what ever value";
2- make tha value accesible to form1 as a public property: // in form 1 form2 = new Form2( this); form2.ShowDialo g(); form1.receivedv alue = form2.PublicPro perty;
3- Make a static public property in form1 , this is the last resort,
//form1 public static string A_Property { get.. set }
//form2 //inside a method: //note I use the Form1 type, not any instnace Form1.A_Propert y = "a value" ;
cheers,
-- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation
"Jason Huang" <Ja************ @hotmail.com> wrote in message news:%2******** *******@TK2MSFT NGP15.phx.gbl.. . Hi,
Thanks for help in advance! In Form1, I "New" a Form2 and ShowDialog the Form2, it's OK. My intention is passing a value from Form2 to Form1. However, in Form2, I shouldn't "New" a Form1, 'cuz it will open a new Form1, the new Form1 will get the value. And the original Form1 get nothing! What do I need to do to let the ORIGINAL Form1 get the target value? Any help will be highly appreciated.
Jason
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Randell D. |
last post by:
Folks,
I'm sure this can be done legally, and not thru tricks of the trade - I
hope someone can help.
I'm writing a 'tool' (a function) which can be used generically in any
of my projects. When it completes, it can call a success, or a failure
function. The names of these success, or failure functions will differ,
and I'd like to know how I can pass the name of a function to my tool,
and how my tool can call the function, using that...
|
by: Harmony407 |
last post by:
Hello:
Our organization uses MS Access to store all of our members
information.
Our primary database computer is running on Windows 98. This is where
the main database exists. The MS Access version we are running is MS
Access 95, V7. I know it is very old, but the organization is afraid
to update to a newer version for fear of losing data. So, I must work
with what I have.
|
by: David N |
last post by:
Hi All,
I just wonder if in C#, I can develop a user defined control that can call
its parent function which is not yet developed. For example, how do I make
my user control call a to-be-developed-function cmdOkay_Click() function as
described below.
1. Create an user control that contains an OK button as below
Public Class MyButton:System.Windows.Form.UserControl
|
by: Anand Ganesh |
last post by:
Hi All,
I need some help. I am sort of not sure how to approach this problem.
I have a MAINPROGRAM. This is the core application.
I have asked two of my staff to developed two different Windows Controls.
Say ControlA.dll and ControlB.dll.
As usual I know how to add these .dlls as the reference and then start using
|
by: PawelR |
last post by:
Hello Group,
In my application I have few class, and I want call function with "master
class". This is as master form (startClass) and option window (ClassA). My
question is how call function from startClass in classA?
public startClass : System.Windows.Forms.Form
{
static void Main()
{...}
| |
by: Paul |
last post by:
Hi,
I've been struggling with this today, I'm developing a DotNet2.0 website in C# that needs to call a long running data query. Obviously this is a good candidate for an Asynchronous call, so the page can carry on rendering whilst the call is taking place and also returning the ASP.NET worker thread to service another page request (for scalability). I have developed a very basic asynchronous object (for testing, that reproduces the same...
|
by: forest demon |
last post by:
for example, let's say I do something like,
System.Diagnostics.Process.Start("notepad.exe","sample.txt");
if the user does a SaveAs (in notepad), how can i capture the path that
the user selects?
thanks...
|
by: garyusenet |
last post by:
Dear Professionals,
I have recently been using the wonderful krypton toolkit and am trying
to use them in my small hobby application. I include this bit of info
as an aside really because i'm sure my question can be extrapolated to
the more general case, so here goes!
I have a box standard windows forms project. (File, New Project,
Windows Application, OK)
|
by: Rahul |
last post by:
Hi Everyone,
I have the following code and i'm able to invoke the destructor
explicitly but not the constructor. and i get a compile time error
when i invoke the constructor, why is this so?
class Trial
{
public: Trial()
{
|
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,...
|
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...
| |
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,...
|
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...
|
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...
|
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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |