Lanc1988 Posted December 9, 2003 Posted December 9, 2003 I have a Login form which has a textbox for users to enter their username, when they enter it and click login, how can I have it displayed in the Title bar of the main window Example: My Program: USERNAME It would really help me if I had this code, I think its done with variables, but im not sure how. Quote
*Experts* DiverDan Posted December 10, 2003 *Experts* Posted December 10, 2003 Try Me.Text = "My Program" & USERNAME Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
Lanc1988 Posted December 10, 2003 Author Posted December 10, 2003 works good, except it does it for wrong form. I have a form where you enter your username and click Login then on the main form, I want it to display the Username. So i have this so far: Me.Text = ": " & TextBox1.Text Close() but it displays it on that Login form instead of my main form (Form1.vb) Quote
Lanc1988 Posted December 10, 2003 Author Posted December 10, 2003 Also i want it to know what the Name of the form is, is there a variable for that? like FormName? Quote
Mehyar Posted December 10, 2003 Posted December 10, 2003 There are plenty of ways to do what you want, one of them is One of them: Create another constructor for your main form which takes a string as an argument. Public Sub New(Byval Username as String) InitializeComponent() Me.Text = Username End Sub And when you want to log in you should replace your Dim f as New Form1() by Dim f as new Form1(TextBox1.Text) Hope this helps, Quote Dream as if you'll live forever, live as if you'll die today
Lanc1988 Posted December 11, 2003 Author Posted December 11, 2003 Hmm.. i must be doing something wrong. I copied exactly what you have in the first part and just pasted it into the Form1 code. Then I guess I didnt put the second part in right. I tried putting it in the button "Login" Quote
Administrators PlausiblyDamp Posted December 11, 2003 Administrators Posted December 11, 2003 What does your code look like at the moment, and what problem are you having? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Lanc1988 Posted December 11, 2003 Author Posted December 11, 2003 problem is that it wont change the title of the Form1 (main form). On my frmUser form, I have a text box and a login button. When I click login, it just closes the login window and doesn't change the Form1 title bar. Could someone post where to put each code and what to change in them? Quote
*Experts* DiverDan Posted December 12, 2003 *Experts* Posted December 12, 2003 (edited) Why not set a global variable like myName in form1. Then open form2 with dialogshow method: this part is in form1's declaration section Public Shared myName as String this part is in form1's event that loads form2 Dim frmUserName as New form2 frmUserName.ShowDialog() If form2.response = DialogResult.Ok then me.Text = "My Program : " & myName End If in form2 Set another global variable in form2's declaration section as: Public Shared response as DialogResult Then in form2's okay or enter button event set : Form1.myTitle = txtUserName.Text response = DialogResultOk Me.Close This will get the user's name onto form1's title bar from form2. If you're going to be passing alot of information between forms, you might also consider a global string array. It works fantastic with the ShowDialog method and a Public Shared response variable. and wouldn't it be nice if the threads had spell check? Edited December 12, 2003 by DiverDan Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
Mehyar Posted December 12, 2003 Posted December 12, 2003 Then I guess I didnt put the second part in right. I tried putting it in the button "Login" [/Quote] You should place it in the Login button as you said. Dim f As New Form1(TextBox1.Text) f.ShowDialog() Hope this helps, Quote Dream as if you'll live forever, live as if you'll die today
Leaders dynamic_sysop Posted December 12, 2003 Leaders Posted December 12, 2003 on your login form's button ( when showing the Main Form ) ... Dim frmMain As New Form1() '/// where your Main Form's name would be inplace of Form1. frmMain.Text = TextBox1.Text '/// set it's caption to the user's name ( in TextBox1 ). frmMain.Show()'/// then show the form. Quote
Mehyar Posted December 12, 2003 Posted December 12, 2003 Hell ya dynamic_sysop, Thats even better ...... Quote Dream as if you'll live forever, live as if you'll die today
Lanc1988 Posted December 12, 2003 Author Posted December 12, 2003 Ok.. one problem still. I need it to display what the current title of the main form is, example "My Program" then add on a colon then a space then the user name they choose. Finished product: My Program: USERNAME I know you could just enter in the title into it, but i was wondering if there is something you can use instead so it will automatically know. Like Title.Text or something, if you get what i mean. I need this because i have the version number in the title bar of the main form, therefore i have to update the title bar to a new version and then i would also have to go and edit the code to change the version number, which i would prefer not to do. Quote
Leaders dynamic_sysop Posted December 13, 2003 Leaders Posted December 13, 2003 well all you would do is... frmMain.Text = Me.Name & ": " & TextBox1.Text '/// or MyBase.Name inplace of Me. Quote
Lanc1988 Posted December 16, 2003 Author Posted December 16, 2003 ok.. so then just that then? Im a little confused with all the parts of code posted. Could someone please copy and paste what i need to do it? Quote
Mehyar Posted December 17, 2003 Posted December 17, 2003 In your button click event handler put this code 'I am quoting dynamic_sysop here Dim frmMain As New Form1() '/// where your Main Form's name would be inplace of Form1. frmMain.Text = Me.Name & ": " & TextBox1.Text '/// or MyBase.Name inplace of Me. '/// set it's caption to the user's name ( in TextBox1 ). frmMain.Show()'/// then show the form. Hope this helps, Quote Dream as if you'll live forever, live as if you'll die today
Lanc1988 Posted December 17, 2003 Author Posted December 17, 2003 Something is wrong, it works but it keeps opening new windows. I click to Login and it changes the title, but it opens a new form to change it, so im ending up with many forms of the same thing with different title bar titles. Quote
Leaders dynamic_sysop Posted December 17, 2003 Leaders Posted December 17, 2003 it's very straight forwards , but to make it a little easier , i've made a sample project for you ...login to main.zip Quote
Grimfort Posted December 19, 2003 Posted December 19, 2003 Please dont think I am putting you down, but I think your are lacking the major concept of coding workflow. I would suggest reading up on things like: Properties, Variables, Classes. Basic functions like , If, For and Concatenations (joining together data). Lookup tutorials, there are many good ones for beginners. Also, if your doing this to learn (rather then just making a program), have a really good crack at working it out for yourself and using examples. You will not learn by copying and pasting someone elses code. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.