473,625 Members | 2,687 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 1349
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
3253
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 not as fast/efficient as using a query where the criteria is
4
3703
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
1859
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
978
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 application.onclose procedure, unfortunately I can't find anything on the net and I don't
50
5694
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
2358
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 text boxes but when I tried to use combo boxes no records were returned in the query. Any idea what...
7
1285
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 the only thing I want to change would be a "content" area, I want the navigation to be the same. ...
5
3305
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 button. The pop-up form contains one record relating to the current record in the main form (but...
1
2278
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 GT::SQL::File::delete_records line 275. Stack Trace: GT::Base (2704): main::fatal called at...
0
8182
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
8688
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
8635
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...
0
7178
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
6115
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
4085
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...
0
4188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2614
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
1800
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.