📄 form1.cs
字号:
this.txtID.Location = new System.Drawing.Point(112, 80);
this.txtID.Name = "txtID";
this.txtID.Size = new System.Drawing.Size(88, 21);
this.txtID.TabIndex = 5;
this.txtID.Text = "";
//
// txtlname
//
this.txtlname.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dsAuthors1, "authors.au_lname"));
this.txtlname.Location = new System.Drawing.Point(112, 120);
this.txtlname.Name = "txtlname";
this.txtlname.Size = new System.Drawing.Size(88, 21);
this.txtlname.TabIndex = 6;
this.txtlname.Text = "";
//
// txtfname
//
this.txtfname.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dsAuthors1, "authors.au_fname"));
this.txtfname.Location = new System.Drawing.Point(112, 160);
this.txtfname.Name = "txtfname";
this.txtfname.Size = new System.Drawing.Size(88, 21);
this.txtfname.TabIndex = 7;
this.txtfname.Text = "";
//
// comboBox1
//
this.comboBox1.Items.AddRange(new object[] {
"Menlo Park",
"Oakland",
"Berkeley",
"San Jose",
"San Francisco",
"Lawrence",
"Palo Alto",
"Covelo",
"Corvallis",
"Nashville",
"Walnut Creek",
"Ann Arbor",
"Gary",
"Rockville",
"Vacaville",
"Salt Lake City"});
this.comboBox1.Location = new System.Drawing.Point(104, 24);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(104, 20);
this.comboBox1.TabIndex = 8;
//
// btnshow
//
this.btnshow.Location = new System.Drawing.Point(168, 48);
this.btnshow.Name = "btnshow";
this.btnshow.Size = new System.Drawing.Size(40, 24);
this.btnshow.TabIndex = 9;
this.btnshow.Text = "查询";
this.btnshow.Click += new System.EventHandler(this.btnshow_Click);
//
// btnNext
//
this.btnNext.Location = new System.Drawing.Point(176, 200);
this.btnNext.Name = "btnNext";
this.btnNext.Size = new System.Drawing.Size(24, 23);
this.btnNext.TabIndex = 10;
this.btnNext.Text = ">";
this.btnNext.Click += new System.EventHandler(this.btnNext_Click);
//
// btnLast
//
this.btnLast.Location = new System.Drawing.Point(200, 200);
this.btnLast.Name = "btnLast";
this.btnLast.Size = new System.Drawing.Size(32, 23);
this.btnLast.TabIndex = 11;
this.btnLast.Text = ">|";
this.btnLast.Click += new System.EventHandler(this.btnLast_Click);
//
// btnPre
//
this.btnPre.Location = new System.Drawing.Point(64, 200);
this.btnPre.Name = "btnPre";
this.btnPre.Size = new System.Drawing.Size(24, 23);
this.btnPre.TabIndex = 12;
this.btnPre.Text = "<";
this.btnPre.Click += new System.EventHandler(this.btnPre_Click);
//
// btnFirst
//
this.btnFirst.Location = new System.Drawing.Point(32, 200);
this.btnFirst.Name = "btnFirst";
this.btnFirst.Size = new System.Drawing.Size(32, 23);
this.btnFirst.TabIndex = 13;
this.btnFirst.Text = "|<";
this.btnFirst.Click += new System.EventHandler(this.btnFirst_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(264, 253);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.btnFirst,
this.btnPre,
this.btnLast,
this.btnNext,
this.btnshow,
this.comboBox1,
this.txtfname,
this.txtlname,
this.txtID,
this.label5,
this.label4,
this.label3,
this.label2,
this.label1});
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.dsAuthors1)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
int iCnt;
void ShowPosition()
{
int iPos;
if(iCnt == 0)
{
//如果数据集中没有记录则显示“无记录”
label5.Text ="无记录";
}
else
{
iPos = this.BindingContext[dsAuthors1, "authors"].Position + 1;
label5.Text = iPos.ToString() + "of" + iCnt.ToString();
//如果有则以类似于“1 of 10”表示记录位置
}
}
private void Form1_Load(object sender, System.EventArgs e)
{
}
private void btnshow_Click(object sender, System.EventArgs e)
{
oleDbDataAdapter1.SelectCommand.Parameters[0].Value=comboBox1.Text;
dsAuthors1.Clear();
oleDbDataAdapter1.Fill(dsAuthors1);
iCnt=this.BindingContext[dsAuthors1,"authors"].Count;
this.BindingContext[dsAuthors1, "authors"].Position=0;
ShowPosition();
}
private void btnFirst_Click(object sender, System.EventArgs e)
{
this.BindingContext[dsAuthors1, "authors"].Position= 0;
ShowPosition();
}
private void btnPre_Click(object sender, System.EventArgs e)
{
if (this.BindingContext[dsAuthors1, "authors"].Position >= 1)
{
//导航到上一条记录
this.BindingContext[dsAuthors1, "authors"].Position -= 1;
//显示当前记录在数据集中的位置
ShowPosition();
}
}
private void btnNext_Click(object sender, System.EventArgs e)
{
if (this.BindingContext[dsAuthors1, "authors"].Position< iCnt - 1)
{
//导航到下一条记录
this.BindingContext[dsAuthors1, "authors"].Position+= 1;
//显示当前记录在数据集中的位置
ShowPosition();
}
}
private void btnLast_Click(object sender, System.EventArgs e)
{
this.BindingContext[dsAuthors1, "authors"].Position=iCnt-1;
ShowPosition();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -