我正在使用使用MS Access数据库的Visual Studio 2010制作C#程序。每次连接打开时,整个程序都会调整大小,而不仅仅是表单,而是每个控件。以下是表单的代码,它只是更大程序的一部分,这只是使用数据库连接的登录表单:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace protowtype
{
public partial class login : Form
{
private OleDbConnection connection = new OleDbConnection();
public login()
{
InitializeComponent();
}
private void btnlogin_Click(object sender, EventArgs e)
{
connection.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
command.CommandText = "select password from accounts where username='" + txtuname.Text + "'";
OleDbDataReader reader = command.ExecuteReader();
bool found = reader.Read();
if (found == false)
{
MessageBox.Show("User does not exist!");
reader.Close();
connection.Close();
return;
}
if (reader["password"].ToString() != txtpass.Text)
{
MessageBox.Show("Password does not match!");
reader.Close();
connection.Close();
return;
}
MessageBox.Show("Login Successful!");
reader.Close();
connection.Close();
this.Hide();
Form1 medical = new Form1();
medical.Show();
}
private void login_Load(object sender, EventArgs e)
{
connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=ClinicDB.accdb";
}
}
}
表单的大小调整由按钮单击事件触发,特别是connection.Open();线。该程序的大小变得非常小,并且一直保持这样。我已经尝试锁定表单并修复sizemode但它仍然会发生。我很确定代码没有问题,可能是Visual Studio或我的显卡,但我不确定,我不知道这是怎么回事。