111,120
社区成员
发帖
与我相关
我的任务
分享

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.SqlClient;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public string 引用数据库连接 = System.Configuration.ConfigurationManager.ConnectionStrings["数据库连接"].ToString();
private void comboBox1_TextUpdate(object sender, EventArgs e)
{
if (comboBox1.Text == "")
{
}
else
{
string sqltext = "SELECT * FROM 地名 WHERE 地名拼音首字母 like '" + comboBox1.Text + "%'";
SqlConnection conn = new SqlConnection(引用数据库连接);
conn.Open();
SqlDataAdapter adr = new SqlDataAdapter(sqltext, conn);
DataSet das = new DataSet();
adr.Fill(das, "adr");
comboBox1.DataSource = das.Tables[0].DefaultView;
comboBox1.DisplayMember = "地名";
comboBox1.ValueMember = "";
conn.Close();
}
}
}
}
private void textBox1_Enter(object sender, EventArgs e)
{
}
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if ((e.KeyCode == Keys.Up) || (e.KeyCode == Keys.Down))
{
this.listBox1.Focus();
}
if ((e.KeyCode== Keys.Enter))
{
this.HideLs();
}
base.OnKeyDown(e);
}
private void textBox1_Leave(object sender, EventArgs e)
{
if (!this.listBox1.Focused)
{
this.HideLs();
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
this.txt = this.textBox1.Text;
if (!this.listBox1.Items.Contains(this.textBox1.Text))
{
this.OnTxTChanged(new TxtEvenargs(this.textBox1.Text));
}
}
private void UserControl1_Load(object sender, EventArgs e)
{
this.textBox1.Top = 0;
this.textBox1.Left = 0;
this.textBox1.Width = base.Width;
this.listBox1.Top = this.textBox1.Bottom;
this.textBox1.ForeColor = this.txtcolor;
this.listBox1.Font = this.dropfont;
this.listBox1.ForeColor = this.textBox1.ForeColor;
this.listBox1.HorizontalScrollbar = this.hscrollbar;
this.HideLs();
base.Height = this.textBox1.Height;
}
private void UserControl1_SizeChanged(object sender, EventArgs e)
{
this.textBox1.Top = 0;
this.textBox1.Left = 0;
this.textBox1.Width = base.Width;
this.listBox1.Top = this.textBox1.Bottom;
this.listBox1.Left = 0;
this.listBox1.Width = this.textBox1.Width;
if (base.Height < this.textBox1.Height)
{
base.Height = this.textBox1.Height;
}
this.listBox1.Height = base.Height - this.textBox1.Height;
}
// Properties
[Description("下拉框字体"), Category("自定义")]
public Font DropFont
{
get
{
return this.dropfont;
}
set
{
this.dropfont = value;
}
}
[Category("自定义"), Description("下拉框高度")]
public int DropHeight
{
get
{
return this.dropheight;
}
set
{
this.dropheight = value;
}
}
[Description("下拉框高度固定"), Category("自定义")]
public bool DropHeightFix
{
get
{
return this.dropheightfix;
}
set
{
this.dropheightfix = value;
}
}
[Category("自定义"), Description("下拉框显示的字符串数组")]
public string[] DropItems
{
get
{
return this.items;
}
set
{
this.items = value;
if (this.items.Length > 0)
{
this.ShowLs();
}
else
{
this.HideLs();
}
}
}
[Description("下拉框横向溢出显示滚动条"), Category("自定义")]
public bool HScrollbar
{
get
{
return this.hscrollbar;
}
set
{
this.hscrollbar = value;
}
}
[Description("下拉框显示最多选项数目"), Category("自定义")]
public int MaxItems
{
get
{
return this.maxitems;
}
set
{
this.maxitems = value;
}
}
[Description("文本框最小字符长度,不包括空格"), Category("自定义")]
public int Minletters
{
get
{
return this.minletters;
}
set
{
this.minletters = value;
}
}
public int SelectionLength
{
get
{
return this.selectionlength;
}
set
{
this.selectionlength = value;
if (this.selectionlength < 0)
{
this.selectionlength = 0;
}
this.textBox1.Select(this.selectionstart, this.selectionlength);
}
}
public int SelectionStart
{
get
{
return this.selectionstart;
}
set
{
this.selectionstart = value;
if (this.selectionstart < 0)
{
this.selectionstart = 0;
}
this.textBox1.Select(this.selectionstart, 0);
}
}
[Browsable(true), Category("自定义"), Description("文本框字符")]
public override string Text
{
get
{
return this.txt;
}
set
{
this.txt = value;
this.textBox1.Text = this.txt;
}
}
[Category("自定义"), Description("文本颜色")]
public Color TxtColor
{
get
{
return this.txtcolor;
}
set
{
this.txtcolor = value;
}
}
// Nested Types
public delegate void TxtChangedHandle(object sender, TxtEvenargs e);
}
public class TxtEvenargs : EventArgs
{
// Fields
public string txt = "";
// Methods
public TxtEvenargs(string txt)
{
this.txt = txt;
}
}