473,545 Members | 2,569 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Very Basic Form Opening Question

I have a login form, which i have made by simply modifying the standard
wizard created form from Visual C# express - when I chose a windows
application.

I have two buttons on my login form.

The first is OK, The second is cancel.

For cancel i have the event set to application.exi t

I'm now looking at the OK button. How do I open my main programme form
when OK is clicked?

I have tried Application.Run (new Form1()); But get an error complaining
something about threads.

Also as well as displaying my main form when the button is pressed I
will need to parse it the validated user name, how do i do this also?

I am sure this is basic, but couldn't find a direct answer.

Thanks,

Gary.

Jan 3 '07 #1
4 1345
ga********@mywa y.com wrote:
I have a login form, which i have made by simply modifying the standard
wizard created form from Visual C# express - when I chose a windows
application.

I have two buttons on my login form.

The first is OK, The second is cancel.

For cancel i have the event set to application.exi t

I'm now looking at the OK button. How do I open my main programme form
when OK is clicked?

I have tried Application.Run (new Form1()); But get an error complaining
something about threads.

Also as well as displaying my main form when the button is pressed I
will need to parse it the validated user name, how do i do this also?

I am sure this is basic, but couldn't find a direct answer.
In the Main method for your program use something like this:

static void Main()
{
Application.Ena bleVisualStyles ();
Application.Set CompatibleTextR enderingDefault (false);

LoginForm frm = new LoginForm();

if (frm.ShowDialog () == DialogResult.OK )
{
Application.Run (new MainForm(frm.Us erName));
}
}

Add a UserName property to the LoginForm class and change the
constructor of your main form to take a string. On the LoginForm, set
the OK button's DialogResult property to OK and the Cancel button's
property to Cancel. The Main method will check the result of the
LoginForm when it is closed.

public partial class LoginForm: Form
{
public LoginForm()
{
InitializeCompo nent();
}

private string _userName;
public string UserName
{
get { return _userName; }
set { _userName = value; }
}

private void button2_Click(o bject sender, EventArgs e)
{
_userName = textBox1.Text;
}
}

public partial class MainForm : Form
{
public MainForm(string username)
{
InitializeCompo nent();
this.label1.Tex t = username;
}
}

Jan 3 '07 #2
Thankyou very much. The first bit of code for use in the main part of
the programme. is that for the program.cs file ? At the moment that
consists of the following: -

static void Main()
{
Application.Ena bleVisualStyles ();
Application.Set CompatibleTextR enderingDefault (false);
Application.Run (new Form1());
}

Do i just replace that with the code you supplied or add the code you
supplied to it?

I was wondering because if i replace it, I don't see how my first form
will load.

Thankyou very much,
Gary.
Chris Dunaway wrote:
ga********@mywa y.com wrote:
I have a login form, which i have made by simply modifying the standard
wizard created form from Visual C# express - when I chose a windows
application.

I have two buttons on my login form.

The first is OK, The second is cancel.

For cancel i have the event set to application.exi t

I'm now looking at the OK button. How do I open my main programme form
when OK is clicked?

I have tried Application.Run (new Form1()); But get an error complaining
something about threads.

Also as well as displaying my main form when the button is pressed I
will need to parse it the validated user name, how do i do this also?

I am sure this is basic, but couldn't find a direct answer.

In the Main method for your program use something like this:

static void Main()
{
Application.Ena bleVisualStyles ();
Application.Set CompatibleTextR enderingDefault (false);

LoginForm frm = new LoginForm();

if (frm.ShowDialog () == DialogResult.OK )
{
Application.Run (new MainForm(frm.Us erName));
}
}

Add a UserName property to the LoginForm class and change the
constructor of your main form to take a string. On the LoginForm, set
the OK button's DialogResult property to OK and the Cancel button's
property to Cancel. The Main method will check the result of the
LoginForm when it is closed.

public partial class LoginForm: Form
{
public LoginForm()
{
InitializeCompo nent();
}

private string _userName;
public string UserName
{
get { return _userName; }
set { _userName = value; }
}

private void button2_Click(o bject sender, EventArgs e)
{
_userName = textBox1.Text;
}
}

public partial class MainForm : Form
{
public MainForm(string username)
{
InitializeCompo nent();
this.label1.Tex t = username;
}
}
Jan 3 '07 #3
Dear Chris having re read and experimented with what you said, it now
makes perfect sense. I will certainly be using this in the future so
have made a note of it in my note application!

Many Thanks,

Gary.

ga********@mywa y.com wrote:
Thankyou very much. The first bit of code for use in the main part of
the programme. is that for the program.cs file ? At the moment that
consists of the following: -

static void Main()
{
Application.Ena bleVisualStyles ();
Application.Set CompatibleTextR enderingDefault (false);
Application.Run (new Form1());
}

Do i just replace that with the code you supplied or add the code you
supplied to it?

I was wondering because if i replace it, I don't see how my first form
will load.

Thankyou very much,
Gary.
Chris Dunaway wrote:
ga********@mywa y.com wrote:
I have a login form, which i have made by simply modifying the standard
wizard created form from Visual C# express - when I chose a windows
application.
>
I have two buttons on my login form.
>
The first is OK, The second is cancel.
>
For cancel i have the event set to application.exi t
>
I'm now looking at the OK button. How do I open my main programme form
when OK is clicked?
>
I have tried Application.Run (new Form1()); But get an error complaining
something about threads.
>
Also as well as displaying my main form when the button is pressed I
will need to parse it the validated user name, how do i do this also?
>
I am sure this is basic, but couldn't find a direct answer.
In the Main method for your program use something like this:

static void Main()
{
Application.Ena bleVisualStyles ();
Application.Set CompatibleTextR enderingDefault (false);

LoginForm frm = new LoginForm();

if (frm.ShowDialog () == DialogResult.OK )
{
Application.Run (new MainForm(frm.Us erName));
}
}

Add a UserName property to the LoginForm class and change the
constructor of your main form to take a string. On the LoginForm, set
the OK button's DialogResult property to OK and the Cancel button's
property to Cancel. The Main method will check the result of the
LoginForm when it is closed.

public partial class LoginForm: Form
{
public LoginForm()
{
InitializeCompo nent();
}

private string _userName;
public string UserName
{
get { return _userName; }
set { _userName = value; }
}

private void button2_Click(o bject sender, EventArgs e)
{
_userName = textBox1.Text;
}
}

public partial class MainForm : Form
{
public MainForm(string username)
{
InitializeCompo nent();
this.label1.Tex t = username;
}
}
Jan 3 '07 #4
As well as Chris's answer you could just do the following in the click
handler for the OK button:

<aircode>

private void OK_Click(Object sender, EventArgs e)
{
if (UsernameIsVali d(userNameTextB ox.Text))
{
this.Close();
MainForm f = new MainForm();
f.Show(); //Or use f.ShowDialog() if you need it to be modal
}
else
{
//Handle the incorrect username or password
MessageBox.Show ("Wrong UserName or Password!");
}
}

private Boolean UserNameIsValid (String userName)
{
//Do your validation test here and return the necessary Boolean
value.
if (UserNamePassed TheValidationTe st)
return true;
else
return false;
}

</aircode>
Also as well as displaying my main form when the button is pressed I
will need to parse it the validated user name, how do i do this also?
How are you storing the usernames now? It's a bit hard to tell you how
to validate them without knowing how they are stored. Let us know and
we'll be glad to help you out!

Thanks,

Seth Rowe
ga********@mywa y.com wrote:
I have a login form, which i have made by simply modifying the standard
wizard created form from Visual C# express - when I chose a windows
application.

I have two buttons on my login form.

The first is OK, The second is cancel.

For cancel i have the event set to application.exi t

I'm now looking at the OK button. How do I open my main programme form
when OK is clicked?

I have tried Application.Run (new Form1()); But get an error complaining
something about threads.

Also as well as displaying my main form when the button is pressed I
will need to parse it the validated user name, how do i do this also?

I am sure this is basic, but couldn't find a direct answer.

Thanks,

Gary.
Jan 3 '07 #5

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

Similar topics

6
3243
by: John | last post by:
Just a general question... I'm currently using a combobox that when updated, opens a form with its recordset based on a query using the combo box value as the criteria. I'm I correct in thinking that using: docmd.openfrm "frmName",,,where "=" & cboSelectID will open all records and then just navigate to that filtered record, which is...
4
3700
by: MS | last post by:
Just a general question here re VBA. Can anyone explain the differences between "!" and "." when refering to a control? eg Me!TxtBox and Me.TxtBox. What is difference between "+" and "&" when working with strings. eg MyStr = "I have " & MyNumber & " apples." and MyStr = "I have " + MyNumber + " apples."
10
1849
by: Jason Curl | last post by:
Greetings, I have an array of 32 values. This makes it extremely fast to access elements in this array based on an index provided by a separate enum. This array is defined of type "unsigned long int". I have a typedef for this: typedef unsigned long int Uint32; typedef float Float32; Uint32 myArray;
5
975
by: Sarah | last post by:
Hi all, Just doing my first VB.NET windows app. It has half a dozen forms and not alot else. When I do a release and run the exe that has been built (which works fine), I go to close it by clicking on the X it closes (or appears to). Infact it is still running in the processes. What am I doing wrong? Should there be an...
50
5666
by: diffuser78 | last post by:
I have just started to learn python. Some said that its slow. Can somebody pin point the issue. Thans
12
2347
by: Tom | last post by:
Hello, I have a database of employee data in access and I am trying to create a form with combo boxes for criteria (ex. gender, office, position, etc.) that let the user select criteria from drop down menus (ex. they may select Male, New York, Manager) and those criteria will be used to run a query (ie Query by Form). I can do this with...
7
1284
by: Bruno43 | last post by:
Hi I am trying to learn Visual Basic and I am getting everything for the most part, mainly because of my ability to read code like a book, but my question is what is the best way to Navigate through a Visual Basic program. For example lets say I have a big Visual Basic Form1.vb and on Form1.vb there are buttons and I click on this button, now...
5
3300
by: Neil | last post by:
"lyle" <lyle.fairfield@gmail.comwrote in message news:48c3dde7-07bd-48b8-91c3-e157b703f92b@f3g2000hsg.googlegroups.com... Question for you. I'm doing something similar, only, instead of opening the forms all at once, I'm opening them as needed. I have a main form with multiple records; and then I have a pop-up form that the user opens with...
1
2274
by: pitjpz | last post by:
We have moved our Database to another server. The server it was on used SQL 4 and the new one its on now uses SQL5 the only problem we can find is that when you attempt to delete a record from the DB the following happens: When Deleting a record: Fatal Error: Can't call method "fetchrow_arrayref" on an undefined value at...
0
7490
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7682
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. ...
1
7449
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...
0
7780
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...
0
6009
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...
0
5069
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...
0
3465
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1911
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
1
1037
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.