单击“btnLogin"时,我的表单会缩小. [英] When clicking "btnLogin", my forms decrease in size.

查看:28
本文介绍了单击“btnLogin"时,我的表单会缩小.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的登录表单上,每当单击btnLogin"时,frmLogin"和frmMenu"的宽度和长度似乎都会减小.这是什么原因?你怎么能修好呢?我不知道它是否与代码有关,但无论如何我都会链接它.谢谢.

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

推荐答案

这可能是 DPI 意识的问题.具体而言,您的应用程序未声明为可识别 DPI,并且当您的代码访问 Microsoft.ACE.OLEDB 提供程序时,其进程将设置为可识别 DPI.这是我前段时间偶然发现的事情,但我从未见过其他人报告它发生过.

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.

简单的解决方案是让您的应用程序了解 DPI.

The simple solution is to make your application DPI aware.

  1. 从项目"菜单中,选择您的项目名称"-属性.
  2. 选择应用程序"选项卡,然后单击查看窗口设置"按钮.
  3. 根据您的 VS 版本,文件中可能包含或不包含以下内容.

<!--
<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. 重新构建您的应用程序.

这篇关于单击“btnLogin"时,我的表单会缩小.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆