6 Replies - 579 Views - Last Post: 12 January 2019 - 06:07 PM Rate Topic: -----

#1 Norman_Bates   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 21
  • Joined: 26-February 13

Userforms automatically resizing

Posted 12 January 2019 - 03:17 PM

I have this problem where I have created several forms that connect to a database; so far they are a login, registration, and forgot user/pass forms.

For some reason, whenever the user clicks on any button that results in a connection to the database the form completely resizes itself to a much smaller version of itself.

I've attached the code for the first form (it affects all forms); and attached screenshots of before and after.

I've tried everything to resolve it, and nothing is working. I've set form properties to make sure it doesn't autoscale, and all the other autoscale options, nothing works. It always changes size when a database connection is established.

This only seems to occur when I run the programme on my Surface Pro 4, running Windows 10. It behaves as I expect it to on my Windows 7 machine

Imports System.Data.OleDb
Imports System.Text
Imports System.Security.Cryptography

Public Class frmWelcome
    Dim User As String
    Dim Pass As String
    Dim con As New OleDbConnection
    Dim da As New OleDbDataAdapter
    Dim dr As OleDbDataReader
    Dim ds As New DataSet
    Dim sql As String
    Dim strHash As String = ""

    Private Sub frmWelcome_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        con.ConnectionString = "Provider = Microsoft.ACE.OLEDB.12.0; Data source = " & Application.StartupPath & "\CopsnRobbers.accdb"
    End Sub

    Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
        If Len(Trim(txtUser.Text)) = 0 Then
            MessageBox.Show("Please enter a Username", "Login Failed!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            txtUser.Focus()
            Exit Sub
        Else
            User = txtUser.Text
        End If

        If Len(Trim(txtPass.Text)) = 0 Then
            MessageBox.Show("Please enter a valid password", "Login Failed!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        Else
            Dim Source As String = txtPass.Text
            Dim md5String As New MD5CryptoServiceProvider
            Dim inputByte As Byte() = Encoding.ASCII.GetBytes(Source)

            inputByte = md5String.ComputeHash(inputByte)

            For Each b As Byte In inputByte
                strHash += b.ToString("x2")
            Next
        End If

        Dim dl As New OleDbCommand("SELECT Username from Users WHERE Username = '" & txtUser.Text & "'", con)
        con.Open()

        dr = dl.ExecuteReader

        If dr.Read = True Then
            Dim login_Query As String = "SELECT Password from Users WHERE Username= '" & User & "';"
            Dim cmd As New OleDbCommand(login_Query, con)



            Try
                Pass = cmd.ExecuteScalar().ToString
            Catch ex As Exception
                MessageBox.Show("Username/Password invalid. Please try again", "Login failed!", MessageBoxButtons.OK, MessageBoxIcon.Error)
                con.Close()
            End Try

            If (Pass = strHash) Then
                Dim Login_Attempts As String = "SELECT Failed_Attempts from Users WHERE Username = '" & User & "';"
                Dim newCmd As New OleDbCommand(Login_Attempts, con)

                Dim isFailed As Integer = Convert.ToInt32(newCmd.ExecuteScalar().ToString)

                If isFailed >= 10 Then
                    MessageBox.Show("Your account has been locked due to too many failed login attempts. Please contact system administrator")
                    con.Close()
                    Exit Sub
                Else
                    isFailed = 0
                    Dim exCmd As New OleDbCommand("UPDATE Users SET Failed_Attempts = '" & isFailed & "' WHERE Username = '" & txtUser.Text & "'", con)
                    Try
                        exCmd.ExecuteNonQuery()
                        con.Close()
                    Catch ex As Exception

                    End Try
                    MessageBox.Show("Login success!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information)
                End If
                frmMain.Show()
                Me.Hide()
            Else
                MessageBox.Show("Username/Password invalid. Please try again", "Login failed!", MessageBoxButtons.OK, MessageBoxIcon.Error)
                con.Close()
                Failed_Login()
            End If
        Else
            MessageBox.Show("User not found, please check and try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            If con.State = ConnectionState.Open Then con.Close()
            Exit Sub
        End If

        con.Close()

    End Sub

    Private Sub btnRegister_Click(sender As Object, e As EventArgs) Handles btnRegister.Click
        frmReg.Show()
        Me.Hide()
    End Sub

    Private Sub Failed_Login()

        con.Open()

        Dim Login_Fail As String = "SELECT Failed_Attempts from Users WHERE Username = '" & User & "';"
        Dim cmd As New OleDbCommand(Login_Fail, con)

        Dim numFailed As Integer = Convert.ToInt32(cmd.ExecuteScalar().ToString)

        If numFailed >= 10 Then
            MessageBox.Show("Your account has been locked due to too many failed login attempts. Please contact system administrator")
            con.Close()
            Exit Sub
        Else
            numFailed += 1

            Dim newCmd As New OleDbCommand("UPDATE Users SET Failed_Attempts = '" & numFailed & "' WHERE Username = '" & txtUser.Text & "'", con)
            Try
                newCmd.ExecuteNonQuery()
                con.Close()
            Catch ex As Exception

            End Try

        End If




    End Sub

    Private Sub lnkForgot_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles lnkForgot.LinkClicked
        frmForgot.Show()
        Me.Hide()
    End Sub

    Private Sub frmWelcome_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed
        End
    End Sub
End Class

Attached image(s)

  • Attached Image
  • Attached Image

This post has been edited by Norman_Bates: 12 January 2019 - 03:19 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Userforms automatically resizing

#2 IronRazer   User is offline

  • Custom Control Freak
  • member icon

Reputation: 1532
  • View blog
  • Posts: 3,859
  • Joined: 01-February 13

Re: Userforms automatically resizing

Posted 12 January 2019 - 05:07 PM

This seems to be a bug that has been asked about but, without a lot of answers. However, the two links below both suggest that they found it was something to do with installing/re-installing the 32bit version of the "Microsoft Access Database Engine 2010 Redistributable". Read the last posts in each post though, as they both did it a little differently.

EDIT: Not sure but, you might need a newer version than 2010, since those threads are from 2015/2016.

Why does my winform resize when i open an access database (.accdb), and how do i fix it?

OleDb / OleDbConnection resizing form (bug?)

A quick google search provided more results (below) that I did not read through too.
Google Search -> "form resizes when connect to access database vb.net"
Was This Post Helpful? 1
  • +
  • -

#3 Norman_Bates   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 21
  • Joined: 26-February 13

Re: Userforms automatically resizing

Posted 12 January 2019 - 05:14 PM

View PostIronRazer, on 12 January 2019 - 05:07 PM, said:

This seems to be a bug that has been asked about but, without a lot of answers. However, the two links below both suggest that they found it was something to do with installing/re-installing the 32bit version of the "Microsoft Access Database Engine 2010 Redistributable". Read the last posts in each post though, as they both did it a little differently.

Why does my winform resize when i open an access database (.accdb), and how do i fix it?

OleDb / OleDbConnection resizing form (bug?)

A quick google search provided more results (below) that I did not read through too.
Google Search -> "form resizes when connect to access database vb.net"


Thanks for your reply. I posted the same question on vbforums.com and someone on there suggested making my application DPI aware; I did that and it has resolved the issue
Was This Post Helpful? 1
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14761
  • View blog
  • Posts: 59,004
  • Joined: 12-June 08

Re: Userforms automatically resizing

Posted 12 January 2019 - 05:25 PM

Also - use parameters. Stop creating SQL statements on the fly with mashing in the data. Waaaay more secure.
Was This Post Helpful? 3
  • +
  • -

#5 IronRazer   User is offline

  • Custom Control Freak
  • member icon

Reputation: 1532
  • View blog
  • Posts: 3,859
  • Joined: 01-February 13

Re: Userforms automatically resizing

Posted 12 January 2019 - 05:27 PM

Glad you found a solution and that you shared your solution here too. I actually thought about setting the app to be DpiAware route but figured you might have tried that already, and I was not sure if it would work after seeing the solutions that others had found on the net. 8)
Was This Post Helpful? 1
  • +
  • -

#6 Norman_Bates   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 21
  • Joined: 26-February 13

Re: Userforms automatically resizing

Posted 12 January 2019 - 05:41 PM

View Postmodi123_1, on 12 January 2019 - 05:25 PM, said:

Also - use parameters. Stop creating SQL statements on the fly with mashing in the data. Waaaay more secure.


Hi, I'm really new to DB programming with VB.NET so just learning. I don't fully understand what you mean, in terms of parameters instead of on the fly data.

Every type of tutorial I've seen on the net on creating, inserting, and editing information into a DB has been done the way my code is set up.

With regards to security, I don't really need it for this exercise per se.

I would be very grateful, however, if you could point me in the right direction of your suggestion; to aid in my learning.

Thanks!
Was This Post Helpful? 0
  • +
  • -

#7 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14761
  • View blog
  • Posts: 59,004
  • Joined: 12-June 08

Re: Userforms automatically resizing

Posted 12 January 2019 - 06:07 PM

Plenty of examples..

https://docs.microso...framework-4.7.2
https://blogs.msdn.m...-sequence-rule/
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1