Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Posted

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)

Posted

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,

Dream as if you'll live forever, live as if you'll die today
Posted

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"

Posted

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?

  • *Experts*
Posted (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 by DiverDan

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

Posted

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,

Dream as if you'll live forever, live as if you'll die today
  • Leaders
Posted

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.

Posted

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.

Posted

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,

Dream as if you'll live forever, live as if you'll die today
Posted

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.

Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...