473,396 Members | 2,111 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,396 software developers and data experts.

Passing Value back to the Main Form

Hello, everyone I'm new to C# and I was wondering if someone can tell me how
do I pass a value from 1 form back to the calling routine. What I mean is in
my Parent form I have this code:

private void frmParent_Load(object sender, EventArgs e)
{
//When the form loads show the login prompt for the user to login.
Form loginForm = new frmLogin();
loginForm.ShowDialog();

}

Now in the loginform I have the following:

private bool blnFormFlag;

public bool GetFormFlag
{ get { return blnFormFlag; }
}

private void btnlogin_Click(object sender, EventArgs e)
{
bool blnLoginFlag = false;

//Check for blank username or password.
if (String.IsNullOrEmpty(txtlogin.Text)== true ||
String.IsNullOrEmpty(txtpassword.Text) == true)
{
MessageBox.Show("Blank username/password is not permitted!",
"Invalid Login", MessageBoxButtons.OK,
MessageBoxIcon.Stop);
}
else
{
sqlClass sClass = new sqlClass(); //Create sqlclass object.

//Grab flag variable.
blnLoginFlag = sClass.RequestLogin(this.txtlogin.Text,
this.txtpassword.Text);
if (blnLoginFlag == false)
MessageBox.Show("Username or password is incorrect!",
"Invalid User", MessageBoxButtons.OK,
MessageBoxIcon.Stop);
else
this.Close(); //close the form.
blnFormFlag = true;

}

}

In the calling procedure in the Parent form the method GetFormFlag isn't
made public to the object loginForm. Meaning I tried doing the following and
get an error message after I initiate the object loginForm:

private bool temp;

temp = loginForm.GetFormFlag; //not valid

How can I get the flag back to the Parent form? Thanks.
--
TC
Jul 20 '06 #1
6 4514
Terrance wrote:
public bool GetFormFlag
{ get { return blnFormFlag; }
}
In the calling procedure in the Parent form the method GetFormFlag isn't
made public to the object loginForm. Meaning I tried doing the following and
get an error message after I initiate the object loginForm:
Since the GetFormFlag is a public propertyof the loginForm class, it
should be available right after the call to ShowDialog. What error are
you getting?

Chris

Jul 21 '06 #2
Chris:

That's what I thougtht, but I get an error stating
"System.Windows.Forms.Form" does not contain a definition for 'GetFormFlag'

What am I doing wrong?
--
TC
"Chris Dunaway" wrote:
Terrance wrote:
public bool GetFormFlag
{ get { return blnFormFlag; }
}
In the calling procedure in the Parent form the method GetFormFlag isn't
made public to the object loginForm. Meaning I tried doing the following and
get an error message after I initiate the object loginForm:

Since the GetFormFlag is a public propertyof the loginForm class, it
should be available right after the call to ShowDialog. What error are
you getting?

Chris

Jul 21 '06 #3
hey ,
try this.........
get { return blnFormFlag; }
it will work..........

Jul 22 '06 #4
I tried that in my login form and it doesn't like it. The version I'm using
is C# Express; I don't think this will make a difference but who knows.

Thanks
--
TC
"gu*************@gmail.com" wrote:
hey ,
try this.........
get { return blnFormFlag; }
it will work..........

Jul 22 '06 #5
Terrance wrote:
>
What am I doing wrong?
--
>private void frmParent_Load(object sender, EventArgs e)
{
//When the form loads show the login prompt for the user to login.
Form loginForm = new frmLogin();
loginForm.ShowDialog();

}
I think your problem lies in the way you are calling the loginForm.

Instead of

Form loginForm = new frmLogin();

Try using

frmLogin loginForm = new frmLogin();
You were declaring your form as a generic Form object. A Form does not
have the property you added to it. Only the type frmLogin has that
property.

Chris

Jul 24 '06 #6
Thanks, a bunch Chris; that worked.
--
TC
"Chris Dunaway" wrote:
Terrance wrote:

What am I doing wrong?
--
private void frmParent_Load(object sender, EventArgs e)
{
//When the form loads show the login prompt for the user to login.
Form loginForm = new frmLogin();
loginForm.ShowDialog();

}

I think your problem lies in the way you are calling the loginForm.

Instead of

Form loginForm = new frmLogin();

Try using

frmLogin loginForm = new frmLogin();
You were declaring your form as a generic Form object. A Form does not
have the property you added to it. Only the type frmLogin has that
property.

Chris

Jul 24 '06 #7

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

Similar topics

1
by: Paul | last post by:
Hmmm, didn't seem to work. I have set session.use_cookies = 1 and session.use_trans_sid = 1 in my php.ini file. Index.php contains:...
11
by: Dthmtlgod | last post by:
I am having a little difficulty in passing a value from a page to another page. I am going to provide excerpts from the code. I think I am close. This is from Page1.ASP <% Set Conn =...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
10
by: Noozer | last post by:
Below is some ASP, HTML and javascript. It is part of a page used to maintain a small database. This code did work at one time, but has since stopped. For some reason the data on my form is not...
8
by: Johnny | last post by:
I'm a rookie at C# and OO so please don't laugh! I have a form (fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip code. The user can enter a zip code in the text box and...
1
by: billy | last post by:
Ok, here's the situation... I have a user control that contains two textboxes (one for a from date/time and one for a to date/time) and two image buttons. The user control itself is supposed to...
11
by: John Pass | last post by:
Hi, In the attached example, I do understand that the references are not changed if an array is passed by Val. What I do not understand is the result of line 99 (If one can find this by line...
5
by: Ronald S. Cook | last post by:
It's been longer that I remember since writing windows (not web) apps. 1) I want to load a main form 2) User clicks login button which brings up login form (on top of main form) 3) Upon...
1
by: Shawn | last post by:
As if it won't be clear enough from my code, I'm pretty new to C programming. This code is being compiled with an ANSI-C compatible compiler for a microcontroller. That part, I believe, will be...
9
by: itarizin | last post by:
Today I found as ignorance owe me.. Let me explain what I'm tring to do and fail (fail: in my needs) For example, I've my stupid class: public class Hello { private int x = 0; public...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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
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...
0
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,...

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.