当点击"btnLogin"时,我的表格尺寸减小. [英] When clicking "btnLogin", my forms decrease in size.

查看:71
本文介绍了当点击"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天全站免登陆