I need guidance in creating a login form.
I have the main form, where the main GUI is.
I tried creating a new form and calling it from the main form but with a condition.
When the password and username are true, then the main form gets initialized, simple.
The problem is about getting the login form textbox data to main form.
How do you do it? Or should I do the login some other way? Call both forms from somwhere else?
I have the main form, where the main GUI is.
I tried creating a new form and calling it from the main form but with a condition.
When the password and username are true, then the main form gets initialized, simple.
The problem is about getting the login form textbox data to main form.
How do you do it? Or should I do the login some other way? Call both forms from somwhere else?
I've read that C# doesn't have popup with textbox. I found that I could use VB for that, but I couldn't get it to work.
Thank you
Thank you
theLizardPosted Oct 20, 2010, 12:40 AM
Don't worry to much about the main form at login, let it initialize, it's not a problem. What yo need to do is make the login form a modal form when it is in a modal state, access to other forms in the application is not possible until the modal form is closed.
To access data from your text box to the main form, create a static class that has pubic properties and methods, then if the user enters the correct information in the text box, set the variables of the class and have the main form access the variables of the class when it needs to.
You can set a try limit on the login form so that if the limit is exceeded then the whole application is terminated.
And I am with you Moose, books only tell you that you can't do things the way you want and offer no solution to problems. There is no such thing as Can't do in programming, difficult solutions take a little more time to discover and can only be discovered if you think out side the square.
I hope this helps you, Unfortunately, Sam answers questions when he does not understand the question and is always cryptic in his attempt to provide solutions.
Sam HobbsPosted Oct 19, 2010, 7:17 PM
Let me say it again. It would really help if you could specify what data you intend to put into the login form from the main form or wherever, and get from the login form. Look through this thread; did you state that explicitly? I think not.
As best as I understand your question, it can be easily solved using member variables and/or properties. If I am wrong then instead of complaining that I am not helpinig, it would help if you could explain what you need to do that cannot be easily soplved using member variables and/or properties.
Moose PickardPosted Oct 19, 2010, 6:49 PM
It didn't help me anymore because I've got it working. But I learned that there is a controls array which I can use in the future.
Sam, if you really want to help me then you could say to me where I'm lacking.
So I could understand about what are you talking. You know the basics is a big word.
If you refer to this thread's question about private and public classes.
I know very well about the access modifiers with methods and instances, well enough.
I wanted to know what happens with a class when it gets public. Could it surpass namespaces?
And I searched the web, but all I could find was acess modifiers about methods.
I use the "Head First C#" as a guidebook if you want to know and plan to read more about forms e.g. "C# - Windows Forms programming with C#", "Beginning C# 2008 Objects - From Concept to Code".
But at this point I do not have such time to take them on.
I really think I have provided all the info anyone would need, about the last question (relict window).
I personally think it is about the InitializeComponent which I put into aN if statement.
I think it InitializeComponent initializes all what is inside the form, so the window would still be there.
But this is a hunch and I haven't confirmed it.
Sam HobbsPosted Oct 19, 2010, 5:59 PM
I certainly tried to help, but you still need to learn more about the basics. You will likely get less assistance in other forums. There are abundant resources available that teach the basics so most people that help others are reluctant to spend the time to explain things that are already explained quite well in other resources.
Suthish NairPosted Oct 19, 2010, 5:44 PM
Might this looking for, try and lemme know..
Moose PickardPosted Oct 19, 2010, 5:06 PM
Why do you still think your posts are useful?
Books are the lousiest teachers, I know by great experience.
By doing my project I have learned much more then any book could have ever taught me.
And I know the basics, no matter what you believe.
I am not what you think, considering your ability to comprehend what I write.
I am far beyond these abilities and at some far below.
You think of me in light of your previous misconceptions.
You should stop doing that.
I'll say it to you directly, I don't want answers as "There are relevant articles...", riddles.
There are stars in the sky, but why would they matter to me if I can't reach them. (hint: links, links, links)
I'll repeat myself, if you don't have anything worthy to add to the thread then don't.
Reread the thread if you think you provided any answers.
If you still do then leave without agreeing.
Sam HobbsPosted Oct 19, 2010, 3:22 PM
I hope you also understand that you need a good book about C# to explain the basics to you.
Moose PickardPosted Oct 19, 2010, 2:14 PM
Hey I've got it working.
I don't show the main form until program.loginCarRental doesn't equal null.
Anyway there seems to be a relict form when I close the login window(Form2).
What could it be? I guess InitializeComponent() isn't really about the form in whole but the contents.
Am I right? How would you do this?
public Form1() {
program = new CarRentalProgram();
Form2 Name = new Form2(program);
Name.ShowDialog();
if(program.loginCarRental != null){
InitializeComponent();
}
}
Moose PickardPosted Oct 19, 2010, 5:27 AM
I did it this way.
This is the Form1 constructor (There doesn't seem to be code formatting button when I reply, only when I make a thread):
CarRental login;
public Form1() {
Form2 Name = new Form2(this);
Name.ShowDialog();
}
This is the Form2 constructor:
private Form1 theParent;
public Form2(Form1 Parent) {
InitializeComponent();
this.theParent = Parent;
}
I did it like this because I couldn't find a way to pass parameters to Form2's button_Click EventHandler,
which needs to know about the usernames. And those are in Form2 as objects.
And I don't want to start messing with the Events right now.
But the only way I could acess the CarRental object(out of the Form1 Constructor) was when I made CarRental object public.
This is where the inconsistent accessibility errors come in.
Which I can fix by changing the default "Class 'Class Name Here'" to "public Class 'Class Name Here'".
What happens when I make them public?
Thank You
Sam HobbsPosted Oct 18, 2010, 8:20 PM
Correct? Then you can use "lf" to access any public member of formLogin. You can put data into the formLogin, show the form, then get data from it.
Moose PickardPosted Oct 18, 2010, 7:14 PM
But I have found a way to do this.
I created the Form2 in the Main form and passed the main form as an argument to Form2.
So I could get the data the main form knows e.g. login name.
But the problem is now with the reference in form2 to main form.
It doesn't see the objects unless I make them public but then the incosistency errors emerge.
I haven't really thought about making the classes public.
I know about privacy it in the smaller scale, methods and types.
What changes when I make the classes public?
Thank You
Sam HobbsPosted Oct 18, 2010, 6:14 PM
It is totally possible to use C# to create a popup with whatever controls you need in it. Perhaps what you read is that VB has a general-purpose popup already created that you can use, but it is extremely easy to create your own popup, customized for your application.