dcsimg
Results 1 to 8 of 8

Thread: [RESOLVED] Userform Scaling

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2018
    Posts
    10

    Resolved [RESOLVED] Userform Scaling

    So, I had this issue where the userform was changing its size when connecting to a database; and I thought I had fixed the issue, but it appears not. The forms are scaling to a really small version of themselves when connecting to the database, and it affects all the other forms as well. I can't figure it out; it only seems to do it on my Surface Pro 4, running Windows 10. My Windows 7 machine does not seem affected by the issue

    Code:
    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
    Name:  Before_Login.jpg
Views: 243
Size:  33.2 KB

    Name:  After_Login.jpg
Views: 238
Size:  33.2 KB

  2. #2

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2018
    Posts
    10

    Re: Userform Scaling

    That fixed it! I did have to mess about with another setting to get it to stop giving me null exception errors, but all in all it now works!!

    Thank you man!!
    Last edited by ste_wilko; Jan 12th, 2019 at 06:15 PM.

  4. #4

    Thread Starter
    New Member
    Join Date
    Dec 2018
    Posts
    10

    Re: Userform Scaling

    So yeah, I've just tried that. But whenever I set the manifest file to be DPi aware my application doesn't start, I just get a null exception thrown

    Code:
    An unhandled exception of type 'System.ArgumentNullException' occurred in mscorlib.dll
    
    Additional information: Value cannot be null.
    It gives me no other information

  5. #5
    Lively Member
    Join Date
    Jun 2018
    Posts
    85

    Re: Userform Scaling

    Quote Originally Posted by ste_wilko View Post
    So yeah, I've just tried that. But whenever I set the manifest file to be DPi aware my application doesn't start, I just get a null exception thrown

    Code:
    An unhandled exception of type 'System.ArgumentNullException' occurred in mscorlib.dll
    
    Additional information: Value cannot be null.
    It gives me no other information
    Wilko,

    Where or what line does the error occur on?

    Typo? In your app.manifest.

    Make a one form sample project that reproduces the problem. Then work in that?

    The key is to understand why you are doing it. Do you understand the surface is twice the resolution (or whatever) ie 3200 pixels vs 1600 pixels. Your form appears to be scaled to 3200 pixels (or whatever) in the designer but it gets shown at real res of 1600 pixels when running. Or whatever it is.

    There are other things to look at but this dpi aware seems to be what you need? You should try to get it to work.

    Do you understand? Are you familiar with the text/dpi scaling settings in the control panel and etc? The surface may be set on a scale factor of x200 percent etc.

    I dont have your equipment or your setup to try so its hard for to help other than tell you I have seen others say it works. Depends on the exact situation you have.

    Maybe others have tried it and or know more I am sure.
    Last edited by tommytwotrain; Jan 12th, 2019 at 06:40 PM.

  6. #6

    Thread Starter
    New Member
    Join Date
    Dec 2018
    Posts
    10

    Re: Userform Scaling

    Sorry, I edited my original reply to you tommytwotrain to say your suggestion worked, but for some reason the forum has kept my original reply and my edited reply.

  7. #7
    Lively Member
    Join Date
    Jun 2018
    Posts
    85

    Re: Userform Scaling

    Quote Originally Posted by ste_wilko View Post
    Sorry, I edited my original reply to you tommytwotrain to say your suggestion worked, but for some reason the forum has kept my original reply and my edited reply.
    wilko,

    Oh. Ok. Wonderful! LOL even.

    So you are done? If so mark the post resolved?

    Perhaps make a quick summary of exactly what you did and a code sample for future generations if you want to.

  8. #8

    Thread Starter
    New Member
    Join Date
    Dec 2018
    Posts
    10

    Re: Userform Scaling

    Quote Originally Posted by tommytwotrain View Post
    wilko,

    Oh. Ok. Wonderful! LOL even.

    So you are done? If so mark the post resolved?

    Perhaps make a quick summary of exactly what you did and a code sample for future generations if you want to.
    Yeah, that's all for this problem, thanks. I will mark it as resolved in a moment.

    There is no code sample to do. Trying the DPI aware originally threw an exception, and it gave no code where the exception was. I had to turn the "Enable the Visual Studio hosting process" off, run my application; close it and then re-enable the hosting process (I presume that is a bug in VS 2015 Community)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width