using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
namespace WindowsApplication8
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
private System.Data.OleDb.OleDbConnection conn;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.Button button6;
private System.Windows.Forms.ComboBox comboBox1;
DataSet ds=new DataSet();
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.conn = new System.Data.OleDb.OleDbConnection();
this.button2 = new System.Windows.Forms.Button();
this.textBox3 = new System.Windows.Forms.TextBox();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.button5 = new System.Windows.Forms.Button();
this.button6 = new System.Windows.Forms.Button();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(16, 8);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
//
// button1
//
this.button1.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(128)), ((System.Byte)(128)), ((System.Byte)(255)));
this.button1.Location = new System.Drawing.Point(128, 8);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "数据绑定";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// conn
//
this.conn.ConnectionString = @"Auto Translate=True;User ID=sa;Tag with column collation when possible=False;Data Source=WNHOO;Password=111;Initial Catalog=WaterID;Use Procedure for Prepare=1;Provider=""SQLOLEDB.1"";Persist Security Info=True;Workstation ID=WNHOO;Use Encryption for Data=False;Packet Size=4096";
//
// button2
//
this.button2.Location = new System.Drawing.Point(216, 8);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(96, 24);
this.button2.TabIndex = 2;
this.button2.Text = "绑定前按钮颜色";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(16, 32);
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(96, 21);
this.textBox3.TabIndex = 4;
this.textBox3.Text = "textBox3";
//
// button3
//
this.button3.Location = new System.Drawing.Point(56, 144);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(56, 32);
this.button3.TabIndex = 5;
this.button3.Text = "第一笔";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button4
//
this.button4.Location = new System.Drawing.Point(128, 144);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(56, 32);
this.button4.TabIndex = 6;
this.button4.Text = "上一笔";
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// button5
//
this.button5.Location = new System.Drawing.Point(200, 144);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(56, 32);
this.button5.TabIndex = 7;
this.button5.Text = "下一笔";
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// button6
//
this.button6.Location = new System.Drawing.Point(280, 144);
this.button6.Name = "button6";
this.button6.Size = new System.Drawing.Size(72, 32);
this.button6.TabIndex = 8;
this.button6.Text = "最后一笔";
this.button6.Click += new System.EventHandler(this.button6_Click);
//
// comboBox1
//
this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox1.Location = new System.Drawing.Point(56, 208);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(176, 20);
this.comboBox1.TabIndex = 9;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(454, 373);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.button6);
this.Controls.Add(this.button5);
this.Controls.Add(this.button4);
this.Controls.Add(this.button3);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "Form1";
this.Closing += new System.ComponentModel.CancelEventHandler(this.Form1_Closing);
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
OleDbDataAdapter oda=new OleDbDataAdapter("select * from userinfo",conn);
oda.Fill(ds,"userinfo");
textBox1.DataBindings.Add("Text",ds,"userinfo.username");
textBox3.DataBindings.Add("Text",ds,"userinfo.UserCardNo");
this.BindingContext[ds,"userinfo"].PositionChanged += new EventHandler(Position_Changed);
this.BindingContext[ds,"userinfo"].Position=0;
comboBox1.DataSource=ds.Tables["userinfo"];
comboBox1.DisplayMember="UserName";
comboBox1.ValueMember="UserCardNo";
oda.Dispose();
}
private void Position_Changed(object sender, EventArgs e)
{
this.Text="当前指针:"+(((BindingManagerBase)sender).Position+1).ToString();
}
private void button2_Click(object sender, System.EventArgs e)
{
(sender as Button).DataBindings.Add("BackColor",button1,"ForeColor");
}
private void Form1_Load(object sender, System.EventArgs e)
{
conn.Open();
}
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
conn.Close();
}
private void button3_Click(object sender, System.EventArgs e)
{
this.BindingContext[ds,"userinfo"].Position=0;
}
private void button6_Click(object sender, System.EventArgs e)
{
this.BindingContext[ds,"userinfo"].Position=this.BindingContext[ds,"userinfo"].Count-1;
}
private void button4_Click(object sender, System.EventArgs e)
{
this.BindingContext[ds,"userinfo"].Position-=1;
}
private void button5_Click(object sender, System.EventArgs e)
{
this.BindingContext[ds,"userinfo"].Position+=1;
}
}
}
浙公网安备 33010602011771号