gpt4 book ai didi

c# - OleDb/OleDbConnection 调整表单大小(错误?)

转载 作者:行者123 更新时间:2023-11-30 20:44:57 25 4
gpt4 key购买 nike

谁能帮我解决一个我似乎无法解决的问题。我在用于桌面的 VSE2012 express 和用于桌面的 VSE2013 express 中创建了一个 C# 表单,其中我将表单保留为默认大小并再次添加一个完全默认的按钮。该按钮被编码为打开和关闭数据库连接。

当单击按钮时,表单及其内容都缩小了大约 25%,我已经尝试了所有默认设置,但没有任何乐趣。我什至用文本文件替换了访问数据库文件,但它仍然发生。在窗口 7 和 8.1 上都试过了

Form1.cs(所有代码)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;

namespace WindowsFormsApplication2
{

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

OleDbConnection myConn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;"
+ @"Data Source="
+ @"..\..\..\x.accdb");



private void button1_Click(object sender, EventArgs e)
{
try
{

myConn.Open();
myConn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}

未编辑的 Form1.Designer.cs

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(106, 138);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(282, 253);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}

#endregion

最佳答案

这一定是 OleDb 或 .NET 错误。它仅在非常高分辨率的屏幕上才会引人注目,调用 OleDb.OleDbConnection.Open 的简单操作会导致表单忽略任何 DPI 或字体缩放。

我试过将打开 OleDb 的调用移动到一个单独的类和一个单独的 DLL,但结果总是一样的。

用户在 YouTube 上发布了一个示例:https://www.youtube.com/watch?v=zdby6gmbX_4

我想我们只需要将它报告给 MS

***** 找到了修复它的方法

如果卸载“Microsoft Access Database Engine 2010 Redistributable”32 位版本,然后安装 64 位版本。然后卸载 64 位版本,然后重新安装 32 位版本,它现在可以工作了

关于c# - OleDb/OleDbConnection 调整表单大小(错误?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28729854/

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