Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8672023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:05:57+00:00 2026-06-12T19:05:57+00:00

I’m building a form to get a username and password from a user and

  • 0

I’m building a form to get a username and password from a user and I can’t get it to work. Basically when I enter in the username and password, if I hit “Cancel” or close the window it pulls the data, but when I press “Ok” it crashes. I’m sure this is a simple fix but I can’t seem to find something similar on Google (which suggests there is a better way to do it… but I’m new to vb.net, haha).

Here is the form (wrapped in a public function returning the username/password in a dictionary):

Public Function displayLoginForm() As Dictionary(Of String, String)

    Dim loginForm As New Form()
    Dim usernameLabel As New Label()
    Dim username As New TextBox()
    Dim passwordLabel As New Label()
    Dim password As New TextBox()
    Dim okButton As New Button()
    Dim cancelButton As New Button()

    usernameLabel.Text = "Username:"
    usernameLabel.Location = New Point(10, 10)
    usernameLabel.Width = 70
    username.Height = 20
    username.Width = 300
    username.Location = New Point(80, 10)

    passwordLabel.Text = "Password:"
    passwordLabel.Location = New Point(10, 40)
    passwordLabel.Width = 70
    password.Height = 20
    password.Width = 300
    password.Location = New Point(80, 40)

    okButton.Text = "Ok"
    okButton.Location = New Point(220, 70)

    cancelButton.Text = "Cancel"
    cancelButton.Location = New Point(okButton.Left + okButton.Width + 10, okButton.Top)

    loginForm.Text = "Login Form"
    loginForm.Height = 130
    loginForm.Width = 400
    loginForm.FormBorderStyle = FormBorderStyle.FixedDialog
    loginForm.MaximizeBox = False
    loginForm.MinimizeBox = False
    loginForm.AcceptButton = okButton
    loginForm.CancelButton = cancelButton
    loginForm.StartPosition = FormStartPosition.CenterScreen

    loginForm.Controls.Add(usernameLabel)
    loginForm.Controls.Add(username)
    loginForm.Controls.Add(passwordLabel)
    loginForm.Controls.Add(password)
    loginForm.Controls.Add(okButton)
    loginForm.Controls.Add(cancelButton)

    loginForm.ShowDialog()

    Dim Result As New Dictionary(Of String, String)
    Result.Add("username", username.Text)
    Result.Add("password", password.Text)

    Return Result

End Function
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T19:05:57+00:00Added an answer on June 12, 2026 at 7:05 pm

    I’m missing this line

    okButton.DialogResult = Windows.Forms.DialogResult.OK
    

    if you add it to your code, the form will close without problems.
    To be honest I don’t understand why the Cancel button works.
    It should have a similar line

    cancelButton.DialogResult = Windows.Forms.DialogResult.Cancel
    

    EDIT: The cancel button has its default DialogResult property set to Cancel, I presume that leaving out the DialogResult.OK on the okButton (so it defaults to Cancel) confuses the winform manager that see an AcceptButton=okButton set with DialogResult=Cancel.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.