OleDb/OleDbConnection调整窗体大小(错误?)

3
有人能帮我解决一个问题吗?我创建了一个 C# 表单,使用 VSE2012 express for desktop 和 VSE2013 express for Desktop,表单大小保持默认,并添加了一个完全默认的按钮。该按钮编码用于打开和关闭数据库连接。
当单击按钮时,表单及其内容都会缩小约 25%,我尝试了所有默认设置,但都没有成功。我甚至用文本文件替换了访问数据库文件,仍然会出现这种情况。在 Windows 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

你能提供Form1.Designer.cs文件吗? - sithereal
1
对不起,什么?请原谅我可能会问一些愚蠢的问题,但是当您点击按钮时,您的表单是在调整大小还是新的对话框放在您的表单上,其中包含错误消息? 因为这就是我所期望的。 不是改变表单大小。 - Jeroen Mostert
我的原始程序非常庞大,但在找到问题后我将其大幅缩减。所以是的,所有表单代码都已发布。重现步骤:
  1. 新建C#应用程序,
  2. 添加一个按钮
  3. 添加我的代码。
........... 运行代码时,表单加载。单击按钮,表单会缩小。
- Osprey231
1
缩小的窗体上是否有“确定”按钮? - Jeroen Mostert
1
我很难相信OleDbConnection是问题的原因。如果没有它,它能正常工作吗?您安装了任何IntelliPoint / Logitech鼠标助手吗? - CodeCaster
显示剩余12条评论
1个回答

4

这一定是 OleDb 或 .NET 的一个 bug。只有在非常高分辨率的屏幕上才能注意到,而调用 OleDb.OleDbConnection.Open 这个简单的操作会导致表单忽略任何 DPI 或字体缩放。

我尝试将打开 OleDb 的调用移动到单独的类和单独的 DLL 中,但结果始终相同。

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

我想我们只需要向微软报告这个问题。

***** 找到了解决方法

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


我没想到这会起作用,但它确实起作用了。非常感谢,你救了我! - sgtBlueBird

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接