Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When clicking "btnLogin", my forms decrease in size.

On my login form, whenever clicking "btnLogin" it seems that "frmLogin" and also "frmMenu" decrease in width, and length. What is the reason for this? How can you fix it? I don't know if it's something to with the code or not, but I'll link it anyway. Thank you.

Imports System.Data.OleDb
Public Class frmLogin
    Public AdminDetails As Boolean
    Public SuccessfulLoginUsername As String
    Dim provider As String
    Dim dataFile As String
    Dim connString As String
    Dim myConnection As OleDbConnection = New OleDbConnection
    Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
        provider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source ="

        dataFile = Application.StartupPath & "\SAC1 Database.mdb"
        connString = provider & dataFile
        myConnection.ConnectionString = connString


        Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM [tblUsers] WHERE [Username] = '" & txtUsername.Text & "' AND [Password] = '" & txtPassword.Text & "'", myConnection)
        myConnection.Open()
        Dim dr As OleDbDataReader = cmd.ExecuteReader
        Dim userFound As Boolean = False
        Dim FirstName As String = ""
        Dim LastName As String = ""

        While dr.Read
            userFound = True
            FirstName = dr("FirstName").ToString
            LastName = dr("LastName").ToString
        End While

        If userFound = True Then
            If txtUsername.Text = "admin" And txtPassword.Text = "password" Then
                AdminDetails = True
                SuccessfulLoginUsername = txtUsername.Text
            Else
                AdminDetails = False
                SuccessfulLoginUsername = txtUsername.Text
            End If
            frmMenu.Show()
            frmMenu.lblTitle.Text = "Welcome " & FirstName & " " & LastName
            frmMenu.lblGreeting.Text = "Howdy! " & FirstName & " " & LastName & ". What would you like to do today?"
        Else
            MsgBox("Sorry, username or password not found", MsgBoxStyle.OkOnly, "Invalid Login")
        End If
        myConnection.Close()
    End Sub

    Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
        Close()
        End
    End Sub

    Private Sub linklblCreateAccount_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles linklblCreateAccount.LinkClicked
        frmCreateAccount.Show()
    End Sub
End Class
like image 861
Ethan Avatar asked Jan 16 '18 01:01

Ethan


1 Answers

This may be an issue with DPI awareness. Specifically, your application is not declared as being DPI aware and when your code accesses the Microsoft.ACE.OLEDB provider, its process is set to being DPI aware. This is something that I discovered by accident a while ago, but I never seen anyone else report it happening.

The simple solution is to make your application DPI aware.

  1. From the Project Menu, select "your project name"-Properties.
  2. Select the Application Tab and click on the "View Window Settings" button.
  3. Depending on your VS version, you may or may not have the following in the file.
<!--
<application xmlns="urn:schemas-microsoft-com:asm.v3">
  <windowsSettings>
    <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
  </windowsSettings>
</application>
-->

If you find this block, then remove the first and last lines ("< !--" and " -->"). If it is not present, add these lines right before the last tag in the file.

  1. Rebuild your application.
like image 85
TnTinMn Avatar answered Nov 17 '22 12:11

TnTinMn