473,700 Members | 3,126 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 1354
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
3265
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
3705
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
1864
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
979
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
5712
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
2360
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
1288
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
3308
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
2287
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
8638
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
9202
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
9058
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...
1
6555
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
5894
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4649
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3081
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
2
2371
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2018
bsmnconsultancy
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...

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.