gpt4 book ai didi

c# - 事件发生后,表格会自行缩小

转载 作者:行者123 更新时间:2023-11-30 21:37:48 24 4
gpt4 key购买 nike

我得到了“LogInform”表格。其中有一些标签,两个文本框(用户名和密码)。和一个按钮“登录”。表单大小为 (1149, 847)。

当用户点击按钮时,我有一个 SQL 函数来检查用户是否存在于数据库中。

//log in to user
private void bunifuThinButton21_Click(object sender, EventArgs e)
{
if(ConsoleApp2.UsersDB.userExists(this.userName.Text,this.passWord.Text))
{
this.Hide();
}
else
{
bunifuThinButton22.Visible = false;
wrongUser.Visible = true;
timer2.Enabled = true;
}
}

和 SQL 函数 (userExists):

public static bool userExists(string userName,string passWord)
{
DataTable d1;
string com = "SELECT * FROM users where user_name='" + userName + "'AND user_password='"+passWord+"'";
d1 = oledbhelper.GetTable(com);

if (d1.Rows.Count == 0)
{
return false;
}

return true;
}

单击后一切正常,除了一件事 - 窗口自行变小,没有代码使窗口在单击后变小。我不明白为什么要这样做。对于那些不明白我的意思的人,我制作了 20 秒的视频(我开始填写表格并输入一些不正确的名称和密码,然后按下按钮):youtube vid

我试图用常规尺寸数字设置“MinumumSize”,我试图将“AutoSize”设置为false,我试图在窗口变小后设置窗口的大小(logInForm.size = new size(x, y)),我尝试了所有可能的方法!我不明白为什么要这样做);感谢您的帮助,希望我解释得足够好..

最佳答案

当您使用高 DPI 显示器并在 Windows 显示设置中启用布局缩放时,表单大小会发生变化。当您的应用程序将任何以 WPF 为目标的 DLL 加载到内存中时,Winforms DPI 自动缩放会重置(在发生时检查 Visual Studio 输出控制台)。例如,当加载 PresentationCore.dll 或 PresentationFramework.dll 时,缩放会重置。

您可以创建 app.manifest 文件覆盖 dpiAwareness设置:

<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">false</dpiAware>
</windowsSettings>
</application>

... but this won't play together with ClickOnce manifest :

Installing ClickOnce published applications is not possible if there is a tag in the manifest file about the dpi-awareness. This is not something that ClickOnce explicitly supports. So you may need to exclude the DPI-aware part for ClickOnce deployment.

解决方案是添加DisableDpiAwareness属性到您的 Properties/AssemblyInfo.cs 文件:

// Disable Dpi awareness in the application assembly.
// Add reference to WindowsBase.dll
[assembly: System.Windows.Media.DisableDpiAwareness]

关于c# - 事件发生后,表格会自行缩小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46847591/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com